作业5.18

使用友元函数,让老师输入学生的数据,学生只能查看自己的数据;老师能录入自己的信息!

#include<iostream>
#include<string>
using namespace std;
class preson{
public:
	//preson(){};
	void input()
	{
		cout<<"请输入姓名:";
	    cin>>name;
	    cout<<"请输入编号:";
	    cin>>number;
	}
	void show()
	{
		cout<<"姓名:"<<name<<endl;
		cout<<"编号:"<<number<<endl;
	}
protected:
	string name;
	string number;
};
class teacher;
class student:public preson{
public:
	student()
	{
	};
	void show()
	{
		cout<<"--------------------------"<<endl;
		preson::show();
		cout<<"班别:"<<Class<<endl;
		cout<<"成绩:"<<score<<endl;
	}
	friend teacher;
private:
	string Class;
	float score;
};
class teacher:public preson{
public:
	teacher()
	{};
	void input_teacher()
	{
		preson::input();
		cout<<"请输入老师的职称:";
		cin>>title;
		cout<<"请输入老师的部门:";
		cin>>dept;
		system("cls");
	}
	void input_student(student &s)
	{
		cout<<"--------------------------"<<endl;
		cout<<"     请输入学生的信息     "<<endl;
		cout<<"请输入学生的姓名:";
		cin>>s.name;
		cout<<"请输入学生的学号:";
		cin>>s.number;
		cout<<"请输入学生的班别:";
		cin>>s.Class;
		cout<<"请输入学生的成绩:";
		cin>>s.score;
		system("cls");
	}
	void show()
	{
		preson::show();
		cout<<"职称:"<<title<<endl;
		cout<<"部门:"<<dept<<endl;
	}
private:
	string title;
	string dept;
};
int main()
{
	teacher tea1;
	student stu1;
	tea1.input_teacher();
	tea1.show();
	tea1.input_student(stu1);
	tea1.show();
	stu1.show();
	system("pause");
	return 0;
}






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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值