题目:
定义一个学生类和一个老师类。学生类有学号、姓名、两门或多门成绩数据,老师有职工号和姓名数据。学生对象能查看自己成绩信息,教师能对学生成绩进行录入。编程实现初始化一个或多个学生信息,初始化一个老师信息。实现学生成绩的输入和相关学生的成绩查看功能。
#include<iostream>
#include<string>
using namespace std;
class student
{
friend class teacher;
string name;
int id;
int english;
int math;
public:
student(string n,int i)
{
name=n;
id =i;
english=0;
math=0;
}
void show_score()
{
cout<<name<<"::"<<"english="<<english<<"math="<<math<<endl;
}
};
class teacher
{
string name;
string num;
public:
teacher(string n1,string n2)
{
name=n1;
num =n2;
}
void score_keying(student&s)
{
int e,m;
cout<<"please input score of "<<s.name<<endl;
cout<<"englsih:";
cin>>e;
cout<<"math:";
cin>>m;
s.english=e;
s.math=m;
}
};
int main()
{
student st1("Zhangsan",201401),st2("Lisi ",201411);
teacher Wangwu("Wangwu","000000");
Wangwu.score_keying(st1);
Wangwu.score_keying(st2);
st1.show_score();
st2.show_score();
system("pause");
return 0;
}
#include<string>
using namespace std;
class student
{
friend class teacher;
string name;
int id;
int english;
int math;
public:
student(string n,int i)
{
name=n;
id =i;
english=0;
math=0;
}
void show_score()
{
cout<<name<<"::"<<"english="<<english<<"math="<<math<<endl;
}
};
class teacher
{
string name;
string num;
public:
teacher(string n1,string n2)
{
name=n1;
num =n2;
}
void score_keying(student&s)
{
int e,m;
cout<<"please input score of "<<s.name<<endl;
cout<<"englsih:";
cin>>e;
cout<<"math:";
cin>>m;
s.english=e;
s.math=m;
}
};
int main()
{
student st1("Zhangsan",201401),st2("Lisi ",201411);
teacher Wangwu("Wangwu","000000");
Wangwu.score_keying(st1);
Wangwu.score_keying(st2);
st1.show_score();
st2.show_score();
system("pause");
return 0;
}