PDA

View Full Version : How come Account_Type and Organization cannot accept user input?


toezaurus81
06-23-04, 08:49 PM
/*Define a class Citizen with three attributes: Name (type sting), Id (type string),
and race (type string). Provide two member functions to input and output the three data.

Implement a class Customer with the following attributes: Account Number (type int),
Account type (type string) and Balance (type double). Provide member functions to accept
and display the data. Your Customer class should inherit the Citizen class.

Implement a class Employee with the following attributes: Organization (type string),
Basic Salary (type double), allowance percent (type double), deduction percent (type double).
Provide member functions to accept and display the data.
*/


#include<iostream>
#include<string>
using namespace std;

class Citizen
{
protected:
char Name[50];
char Id[20];
char Race[30];

public:
void input()
{
cout<<"\nEnter Citizen's information"<<endl;
cout<<"***************************"<<endl;
cout<<"Enter Name: ";
cin.getline(Name,50);
cout<<"Enter Id: ";
cin.getline(Id,20);
cout<<"Enter Race: ";
cin.getline(Race,30);
}

void output()
{ cout<<"\nCitizen's information"<<endl;
cout<<"*********************"<<endl;
cout<<"Name: "<<Name<<endl;
cout<<"Id: "<<Id<<endl;
cout<<"Race: "<<Race<<endl;
}



};

class Customer:Citizen
{
private:
int Account_Number;
char Account_Type[30];
double Balance;

public:
void accept()
{
cout<<"\nEnter Customer's information"<<endl;
cout<<"****************************"<<endl;
cout<<"Enter Account Number: ";
cin>>Account_Number;
cout<<"Enter Account Type: ";
cin.getline(Account_Type,30); //can't accept user input
cout<<"Enter Balance: ";
cin>>Balance;
}

void display()
{ cout<<"\nCustomer's information"<<endl;
cout<<"*********************"<<endl;
cout<<"Account Number: "<<Account_Number<<endl;
cout<<"Account Type: "<<Account_Type<<endl;
cout<<"Balance: "<<Balance<<endl;
}
};

class Employee
{
private:
char Organization[30];
double Basic_Salary;
double Allowance_percent;
double Deduction_percent;

public:
void accept()
{
cout<<"\nEnter Employee's information"<<endl;
cout<<"****************************"<<endl;
cout<<"Enter Organization: ";
cin.getline(Organization,30); //can't accept user input
cout<<"Enter Basic Salary: ";
cin>>Basic_Salary;
cout<<"Enter Allowance Percent: ";
cin>>Allowance_percent;
cout<<"Enter Deduction Percent: ";
cin>>Deduction_percent;
}

void display()
{
cout<<"\nEmployee's information"<<endl;
cout<<"*********************"<<endl;
cout<<"Organization: "<<Organization<<endl;
cout<<"Basic Salary: "<<Basic_Salary<<endl;
cout<<"Allowance Percent: "<<Allowance_percent<<endl;
cout<<"Deduction Percent: "<<Deduction_percent<<endl;
}

};



void main()
{
Citizen cit;
Customer cust;
Employee emp;
cit.input();
cit.output();
cout<<endl;
cust.accept();
cust.display();
emp.accept();
emp.display();
}

Rob_Darkins
07-30-04, 02:59 PM
Hi,
you haven't been explained your problem. However, I'm guessing from your Qs title what the problem is. I looked at your code, and although I can't spot an immediate problem, perhaps try replacing:

cin.getline(Name,50);

with:

cin.sync(); cin.clear(); // Just new input.
cin >> setw(50) >> Name;

Also, you seem to have created your variables to store the input as character arrays.. Perhaps replace them with Strings? or String arrays?
Don't forget to specify the element of the array to write input to aswell.

Good luck,
Rob D.