前四章课堂小测

来源:互联网 发布:公务员网络视频课程 编辑:程序博客网 时间:2024/06/10 19:00


定义一个学生类和一个老师类。学生类有学号、姓名、两门或多门成绩数据,老师有职工号和姓名数据。学生对象能查看自己成绩信息,教师能对学生成绩进行录入。编程实现初始化一个或多个学生信息,初始化一个老师信息。实现学生成绩的输入和相关学生的成绩查看功能。

#include<iostream>  #include<string>  using namespace std;  class student{public:    student(string n,string i)   {name=n;id=i;chinese=0;english=0;    }friend class teacher;void student::showstudent(){    cout<<"姓名:"<<name<<endl;    cout<<"学生学号:"<<id<<endl;    cout<<"语文成绩:"<<chinese<<endl;    cout<<"英语成绩:"<<english<<endl;}private:string name;string id;int chinese;int english;};class teacher{public:teacher(string n1,string n2){    name=n1;    num=n2;}void showteacher(){cout<<"教师姓名:"<<name<<"职工号:"<<num<<endl;}void input(student &s);private:string name;string num;};void teacher::input(student &s){    int a,b;    cout<<"please input score of "<<s.name<<":"<<endl;    cout<<"chinese:";    cin>>a;    cout<<"please input score of "<<s.name<<":"<<endl;    cout<<"english:";    cin>>b;    s.chinese=a;    s.english=b;}int main(){    teacher mingge("mingge","01");    student stu1("Hehuiqing","201411671105");    mingge.showteacher();    mingge.input(stu1);    stu1.showstudent();    system("pause");    return 0;}

0 0
原创粉丝点击