*1. 编写一个学生和教师数据输入和显示程序,学生数据有编号、姓名、班级和成绩,教师数据有编号、姓名、职称和部门。要求将编号、姓名输入和显示设计成一个类person,并作为学生数据操作类student和教师类数据操作类teacher的基类。
请大家尽快!我马上要用哦!
*1. 编写一个学生和教师数据输入和显示程序,学生数据有编号、姓名、班级和成绩,教
答案:2 悬赏:0 手机版
解决时间 2021-02-06 20:12
- 提问者网友:雾里闻花香
- 2021-02-05 21:13
最佳答案
- 五星知识达人网友:怀裏藏嬌
- 2021-02-05 21:22
标准答案哦:)
#include
#include
class Student; //学生类
class Teacher; //教师类
class Person //人类
{
private:
int id;
char name[20];
public:
Person(int x,char *p)
{
id=x;
strcpy(name,p);
}
void show(Student s)
{
cout << "编号:" << id << endl;
cout << "姓名:" << name << endl;
cout << "班号:" << s.getclassid() << endl;
cout << "成绩:" << s.getscore() << endl;
}
void show(Teacher t) //show函数的重载
{
cout << "编号:" << id << endl;
cout << "姓名:" << name << endl;
cout << "职称:" << t.getzhicheng() << endl;
cout << "部门:" << t.getbumen() << endl;
}
};
class Student:public Person
{
private:
int classid;
double score;
public:
void setclassid(int x) //设置私有属性班级号
{
classid=x;
}
void setscore(double y) //设置私有属性成绩
{
score=y;
}
int getclassid()
{
return classid;
}
double getscore()
{
return score;
}
};
class Teacher:public Person
{
private:
char zhicheng[10]; //职称
char bumen[10]; //部门
public:
void setzhicheng(char *p) //设置私有属性职称
{
strcpy(zhicheng,p);
}
void setbumen(char *p) //设置私有属性部门
{
strcpy(bumen,p);
}
char getzhicheng()
{
return zhicheng;
}
char getbumen()
{
return bumen;
}
};
void main()
{
Person s1(1,"小强");
Student p1;
p1.setclassid(15);
p1.setscore(90.8);
s1.show(p1);
}
#include
#include
class Student; //学生类
class Teacher; //教师类
class Person //人类
{
private:
int id;
char name[20];
public:
Person(int x,char *p)
{
id=x;
strcpy(name,p);
}
void show(Student s)
{
cout << "编号:" << id << endl;
cout << "姓名:" << name << endl;
cout << "班号:" << s.getclassid() << endl;
cout << "成绩:" << s.getscore() << endl;
}
void show(Teacher t) //show函数的重载
{
cout << "编号:" << id << endl;
cout << "姓名:" << name << endl;
cout << "职称:" << t.getzhicheng() << endl;
cout << "部门:" << t.getbumen() << endl;
}
};
class Student:public Person
{
private:
int classid;
double score;
public:
void setclassid(int x) //设置私有属性班级号
{
classid=x;
}
void setscore(double y) //设置私有属性成绩
{
score=y;
}
int getclassid()
{
return classid;
}
double getscore()
{
return score;
}
};
class Teacher:public Person
{
private:
char zhicheng[10]; //职称
char bumen[10]; //部门
public:
void setzhicheng(char *p) //设置私有属性职称
{
strcpy(zhicheng,p);
}
void setbumen(char *p) //设置私有属性部门
{
strcpy(bumen,p);
}
char getzhicheng()
{
return zhicheng;
}
char getbumen()
{
return bumen;
}
};
void main()
{
Person s1(1,"小强");
Student p1;
p1.setclassid(15);
p1.setscore(90.8);
s1.show(p1);
}
全部回答
- 1楼网友:未来江山和你
- 2021-02-05 21:33
#include#includeusingnamespacestd;classperson{intnum;stringname;friendistream&operator>>(istream&in,person&p);friendostream&operator>(istream&in,person&p){returnin>>p.num>>p.name;}ostream&operatort>>s;cout#includeusingnamespacestd;classperson{intnum;stringname;friendistream&operator>>(istream&in,person&p);friendostream&operator>(istream&in,student&p);friendostream&operator>(istream&in,teacher&p);friendostream&operator>(istream&in,person&p){cout>p.num>>p.name;}ostream&operator(istream&in,student&p){in>>(person&)p;cout>p.cls>>p.score;}ostream&operator(istream&in,teacher&p){in>>(person&)p;cout>p.lev>>p.dep;}ostream&operatort>>s;cout<
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯