Output of the program程序是正确的但在执行完所有语句后,编译器没有从memid中获取输入,而是跳转到下一个语句。
#include<iostream>
#include<conio.h>
using namespace std;
class member{
protected:
string memid,memname;
public:
void get_info(){
cout<<"\nEnter Member Id:\t";getline(cin,memid);
cout<<"\nEnter Member Name:\t";getline(cin,memname);
}
void show_info(){
cout<<"\nMember Id :\t "<<memid;
cout<<"\nMember Name:\t"<<memname;
}
};
class employee:public member{
protected:
string jobtitle,location;
public:
void get_info(){
member::get_info();
cout<<"\nEnter job title: \t";getline(cin,jobtitle);
cout<<"\nEnter Location: \t";getline(cin,location);
}
void show_info(){
member::show_info();
cout<<"\nJob Title:\t"<<jobtitle;
cout<<"\nLocation:\t"<<location;
}
};
class student:public member{
protected:
string institution;
public:
void get_info(){
member::get_info();
cout<<"\nEnter institution name:\t";getline(cin,institution);
}
void show_info(){
member::show_info();
cout<<"\nInstitution Name is:\t"<<institution;
}
};
class undergraduate:public student{
protected:
int age;
public:
void get_info(){
student::get_info();
cout<<"\nEnter age:\t";cin>>age;
}
void show_info(){
student::show_info();
cout<<"\nAge:\t"<<age;
}
};
class graduate:public student{
protected:
string department;
public:
void get_info(){
student::get_info();
cout<<"\nEnter Department Name:\t";getline(cin,department);
}
void show_info(){
student::show_info();
cout<<"\nDepartment is:\t"<<department;
}
};
int main(){
employee e1;
undergraduate u1;
graduate g1;
cout<<"Enter Information of Employees:";
e1.get_info();
cout<<"\nHere is the Information of Employees:";
e1.show_info();
cout<<"\nEnter Information of Undergraduate Student:";
u1.get_info();
cout<<"\nHere is the Information of Undergraduate Student:";
u1.show_info();
cout<<"\nEnter Information of Post graduate students:";
g1.get_info();
cout<<"\nHere is the Information of Post graduate Student:";
g1.show_info();
getch();
}