第五章5.18

5.18编写一个学生和教师数据输入和显示程序,学生数据有编号、姓名、班号和成绩,教师数据有编号、姓名、职称、部门。要求将编号、姓名和显示设计成一个类person,并作为学生数据操作类student和teacher的基类。
#include<iostream>
#include<string>
using namespace std;
class person{
public:
    person(string i,string n)
	{
		id=i;
		name=n;
	}
	void person_show()
	{
		cout<<"number="<<id<<endl;
		cout<<"name="<<name<<endl;
	}
private:
	string id;
	string name;
};
class teacher:public person{
public:
	teacher(string i,string n):person(i,n)
	{  
		cout<<"teacher:"<<endl;
		person::person_show();
		cout<<"title:";
		  cin>>title;
		   cout<<"department:";
		   cin>>department;
	                                                                     
	}
	void teacher_show()
	{
		person::person_show();
		cout<<"title:"<<title<<endl;
		cout<<"department:"<<department<<endl;
	}
private:
	string title;
	string department;
};
class student:public person{
public:
	student(string i,string n):person(i,n)
	{
	    cout<<"student:"<<endl;
		person::person_show();
		cout<<"class_no:";
		cin>>class_no;
        cout<<"score:";
		cin>>score;
	}
		
	
	void student_show()
	{
		person::person_show();
		cout<<"class_no:"<<class_no<<endl;
		cout<<"score:"<<score<<endl;
	}
private:
	string class_no;
	float score;
};
int main()
{
	teacher stu("001","mingge");
	student stu1("002","liyi");
	cout<<"*****************************"<<endl;
	stu.teacher_show();
	stu1.student_show();
	return 0;
}

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值