Current location: Hot Scripts Forums » Programming Languages » C/C++ » How come Account_Type and Organization cannot accept user input?


How come Account_Type and Organization cannot accept user input?

Reply
  #1 (permalink)  
Old 06-23-04, 07:49 PM
toezaurus81 toezaurus81 is offline
Newbie Coder
 
Join Date: Mar 2004
Location: Malaysia
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy How come Account_Type and Organization cannot accept user input?

/*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();
}
Reply With Quote
  #2 (permalink)  
Old 07-30-04, 01:59 PM
Rob_Darkins Rob_Darkins is offline
Newbie Coder
 
Join Date: Jun 2004
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
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.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -5. The time now is 04:29 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.