信管14:前四章节课堂小测-编程示例代码

        前四章节学习完成了。昨天下午,在第六周四课堂前20分钟,进行第三次课堂小测,主要是编程,重点考类的定义,对象的定义使用等重要内容。程序没有标准答案,这里也给一个参考程序。
题目:
    定义一个学生类和一个老师类。学生类有学号、姓名、两门或多门成绩数据,老师有职工号和姓名数据。学生对象能查看自己成绩信息,教师能对学生成绩进行录入。编程实现初始化一个或多个学生信息,初始化一个老师信息。实现学生成绩的输入和相关学生的成绩查看功能。
#include<iostream>
#include<string>
using namespace std;

class  Student
{	friend  class teacher;           
	string  name;
	int id;
	int english;
	int database;
public:
	Student(string n,int i)
	{	name=n;
		id=i;
		english=0;
		database=0;
	}
	void show_score()
	{cout<<name<<"::"<<"english= "<<english<<"   database=  "<<database<<endl;
	}
};

class  teacher
{        string  name;
	 string num;
public:
	teacher(string n1,string n2)
	{
	 name=n1;
	 num=n2;
	}
	void score_keying(Student &s)
	{ int e,d;
	  cout<<"please input score of  "<<s.name<<endl;
	  cout<<"englsih:";
	  cin>>e;
          cout<<"database:";
	  cin>>d;
	  s.english=e;
	  s.database=d;
	}
	
};



int main()
{
	Student st1("ChenHaiYan",201401),st2("LiYiFan   ",201411);

	teacher  mingge("mingge","000000");

	mingge.score_keying(st1);
	mingge.score_keying(st2);

	st1.show_score();
	st2.show_score();

        system("pause");
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值