类的公有继承题目

初写博客,有什么更好的要求,多多指教

编写一个学生和教师数据输入和显示程序

编写一个学生和教师数据输入和显示程序,学生数据有编号、姓名、班号和成绩,教师数据有编号、姓名、职称和部门。‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬

要求将编号、姓名输入和显示设计成一个类person,并作为学生数据操作类student和教师数据操作类teacher的基类。‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬

‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬

描述

在此处编写题目描述信息‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬

点击编辑器菜单栏按钮 {;} 添加示例代码‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬

 

 ‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬

输入输出示例

在此处提供一个符合格式描述的例子, 对于自动评阅题, 您也可以选择直接在测试用例中提供‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬

输入输出
示例 1
100
王大力
90101
95
99822
孙国强
副教授
信息系
输入一个学生数据:
输入一个教师数据:
显示一个学生数据:
编号:100
姓名:王大力
班号:90101
成绩:95
显示一个教师数据:
编号:99822
姓名:孙国强
职称:副教授
部门:信息系

#include <iostream>
#include<string>
using namespace std;
class person{
    string number;
    string name;
    public:
    person(string num,string na){
        number=num;
        name=na;
    }
    void inputperson(){
        cin >>number>>name ;
    }
    void showperson(){
        cout<<"编号:"<<number<<endl<<"姓名:"<<name<<endl;
    }
};
class student:public person{
    string classnumber;
    double score;
    public:
    student(string cla,double sco,string num1,string na1):person(num1,na1){
        classnumber=cla;
        score=sco;
    }
    void showstudent(){
        showperson();
        cout<<"班号:"<<classnumber<<endl<<"成绩:"<<score<<endl;
    }
};
class teacher:public person{
    string title;
    string department;
    public:
    teacher(string ti,string dep,string num2,string na2):person(num2,na2){
        title=ti;
        department=dep;
    }
    void showteacher(){
        showperson();
        cout<<"职称:"<<title<<endl<<"部门:"<<department<<endl;
    }
};
int main(){
    string nu1,nu2,na1,na2,c1,t,d;
    double s;
    cout<<"输入一个学生数据:"<<endl<<"输入一个教师数据:"<<endl;
    cin>>nu1>>na1>>c1>>s>>nu2>>na2>>t>>d;
    student a(c1,s,nu1,na1);
    cout<<"显示一个学生数据:"<<endl;
    a.showstudent();
    teacher b(t,d,nu2,na2);
    cout<<"显示一个教师数据:"<<endl;
    b.showteacher();
    return 0;
}

继承点类定义圆类

描述

定义基类——平面点类POINT,x,y坐标为其私有数据成员,double;成员函数有:默认构造设置坐标为(0,0);两参数构造函数设置x,y;set()函数设置x,y坐标;show()显示x,y坐标。成员函数均为公有。‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬

定义派生类——圆类Circle,继承上面的POINT点类,增加数据成员radius表示半径,double,私有。成员函数有:默认构造函数,设置圆心半径均为0;三参数构造函数初始化圆心和半径;set()设置圆心和半径;show()显示圆心和半径。‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬

编写主程序,(1)使用默认构造函数定义圆类对象1,使用三参数构造函数定义圆类对象2,圆心半径为(1,2),3;显示对象1、对象2的信息;输入圆心半径,设置对象1的圆心半径,再次显示对象1的信息。主函数如下:‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬

int main() {
	Circle a;
	Circle b(1.0, 2.0, 3.0);
	a.show();
	b.show();
	double x, y, r;
	cin >> x >> y >> r;
	a.set(x, y, r);
	a.show();
	return 0;
}

 输入

三个实数,用空格隔开,表示圆的圆心和半径。‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬

输出

三行,三个圆的圆心和半径,格式见样例,数据间用空格隔开。‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬

输入输出示例

输入输出
示例 1
3 4 5
x=0 y=0 r=0
x=1 y=2 r=3
x=3 y=4 r=5

#include<iostream>
using namespace std;
class POINT {
    double x, y;
public:
   /* POINT() {
        x = 0;
        y = 0;
    }
     POINT(double a, double b) {
        x = a;
        y = b;
    }*/

    POINT(double a=0, double b=0) {//相当于上面两个构造函数的结合体
        x = a;
        y = b;
    }
    void set1(double a, double b) {
        x = a;
        y = b;
    }
    void show() {
        cout << "x=" << x << " y=" << y;
    }
};
class Circle :public POINT {
    double radius;
public:
    Circle() {
        radius = 0;
    }
    Circle(double e, double f, double r) :POINT(e, f) {
        radius = r;
    }
    void set(double e, double f, double r) {
        set1(e, f);
        radius = r;
    }
    void showC() {
        show();
        cout << " r=" << radius << endl;
    }
};
int main() {
    Circle a;
    Circle b(1.0, 2.0, 3.0);
    a.showC();
    b.showC();
    double x, y, r;
    cin >> x >> y >> r;
    a.set(x, y, r);
    a.showC();
    return 0;
}

住宅楼类

‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬

建立基类Building,作为楼房类,这个基类中包含楼房层数、房间数、楼房总面积数。‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬

再建立派生类Home_Arch作为住宅楼类。在类Home_Arch中包含的内容有卧室数、客厅数、卫生间数和厨房数等。‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬

在main()中定义一个派生类的对象,并输出信息到屏幕上。‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬

描述

在此处编写题目描述信息‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬

点击编辑器菜单栏按钮 {;} 添加示例代码‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬

 

 ‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬

输入输出示例

在此处提供一个符合格式描述的例子, 对于自动评阅题, 您也可以选择直接在测试用例中提供‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬

输入输出
示例 1
7
100
12000
3
1
1
1
住宅楼:
楼层层数:7层
房间数:100间
楼房总面积:12000平方米
其中:
卧室数:3间
客厅数:1间
卫生间数:1间
厨房数:1间

#include<iostream>
using namespace std;
class Building{
    int layer,room,area;
    public:
    Building(int l,int r,int a){
        layer=l;
        room=r;
        area=a;
    }
    void showBuilding(){
        cout<<"住宅楼:"<<endl<<"楼层层数:"<<layer<<"层"<<endl<<"房间数:"<<room<<"间"<<endl<<"楼房总面积:"<<area<<"平方米"<<endl;
    }
};
class Home_Arch:public Building{
    int bedroom,livingroom,toilet,kitchen;
    public:
    Home_Arch(int x,int y,int z,int b,int li,int t,int k):Building(x,y,z){
        bedroom=b;
        livingroom=li;
        toilet=t;
        kitchen=k;
    }
    void showHome_Arch(){
        showBuilding();
        cout<<"其中:"<<endl<<"卧室数:"<<bedroom<<"间"<<endl<<"客厅数:"<<livingroom<<"间"<<endl<<"卫生间数:"<<toilet<<"间"<<endl<<"厨房数:"<<kitchen<<"间"<<endl;
    }
};
int main(){
    int a,b,c,d,e,f,g;
    cin>>a>>b>>c>>d>>e>>f>>g;
    Home_Arch A(a,b,c,d,e,f,g);
    A.showHome_Arch();
    return 0;
}

  • 12
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值