#include<iostream.h>
class person
{
private:
int id;
char name[20];
char sex;
public:
void input();
void output();
};
class student:protected person
{
private:
char course[20];
float score;
public:
void input();
void output();
};
void person::input()
{
cout<<"input id: ";
cin>>id;
cout<<"input name: ";
cin.seekg(0);
cin.get(name,20);
cout<<"input sex: ";
cin>>sex;
}
void person::output()
{
cout<<"id\tName\tSex\tCourse\tScore\n";
cout<<id<<"\t"<<name<<"\t"<<sex;
}
void student::input()
{
person::input();
cout<<"input course: ";
cin>>course;
cout<<"input score: ";
cin>>score;
}
void student::output()
{
person::output();
cout<<"course\tscore\n";
cout<<course<<"\t"<<score;
}
void main()
{
student st;
st.input();
st.output();
}
Blogger Comment
Facebook Comment