您的位置:首页 > 其它

学生 老师 类

2015-04-29 21:53 211 查看

#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<<"::"<<"id:"<<id<<"english= "<<english<<"   math=  "<<math<<endl; 

    } 

};   

class  teacher 

{    string  name; 

     string num; 

public: 

    teacher(string n1,string n2) 

    { 

     name=n1; 

     num=n2; 

    } 

 void show_teacher_data()

 {cout<<"name:"<<name<<'\n'<<"num:"<<num<<endl;

 }

    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 st("lipengfei",14213); 

 

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

    mingge.show_teacher_data();

    mingge.score_keying(st);  

 

    st.show_score(); 

 

        system("pause"); 

    return 0; 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: