学生老师类

来源:互联网 发布:淘宝提升排名 编辑:程序博客网 时间:2024/04/29 08:27


#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 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("heminghan",14213); 
 
    teacher  mingge("mingge","000000"); 

    mingge.score_keying(st);  
 
    st.show_score(); 
 
        system("pause"); 
    return 0; 

0 0