16,501
社区成员
发帖
与我相关
我的任务
分享
#include "stdafx.h"
#include "iostream"
#include "string"
#include "targetver.h"
using namespace std;
//////////////////////////////////////////////////////////////////////////基类
class person
{
public:
string no;
string name;
person(string i,string j){ no=i;name=j;}
person();
~person();
};
person::~person(){}
/////////////////////////////////////////////////////////////////////////学生派生
class student :private person
{
private:
int Cno;
float score;
public:
student (string n,string na,int cn,float s );
student();
void s_cin(student &s);
void display()
{
cout<<"编号:"<< no<<endl;
cout<<"姓名:"<< name<<endl;
cout<<"班号:"<< Cno<<endl;
cout<<"成绩:"<< score<<endl;
}
~student();
};
/////////////////////////////////////////////////////////////////////////教师派生类
class teacher :private person
{
private:
string wname;
string wage;
public:
teacher (string n,string na,string wn,string wa );
teacher();
void t_cin(teacher &t);
void display()
{
cout<<"编号:"<< no<<endl;
cout<<"姓名:"<< name<<endl;
cout<<"职称:"<< wname<<endl;
cout<<"部门:"<< wage<<endl;
}
~teacher();
};
/////////////////////////////////////////////////////////////////////////
student::student (string n,string na,int cn,float s ):person(n,na)
{
Cno=cn;
score=s;
}
void student::s_cin(student &s)
{
cout<<"输入学生信息:"<<endl;
cin>>s.no>>s.name>>s.Cno>>s.score;
}
student::~student(){}
//////////////////////////////////////////////////////////////////////////
teacher ::teacher(string n,string na,string wn,string wa ):person(n,na)
{
wname=wn;
wage=wa;
}
void teacher::t_cin(teacher &t)
{
cout<<"输入学生信息:"<<endl;
cin>>t.no>>t.name>>t.wname>>t.wage;
}
teacher::~teacher(){}
/////////////////////////////////////////////////////////////////
int _tmain(int argc, _TCHAR* argv[])
{
teacher t;
student s;
s.s_cin(s);
t.t_cin(t);
s.display();
t.display();
return 0;
}
//////////////////////////////////////////////////////////////////////////基类
class person
{
public:
string no;
string name;
person(string i, string j)
{
no = i;
name = j;
}
person() {}
~person() {}
};
/////////////////////////////////////////////////////////////////////////学生派生
class student: private person
{
private:
int Cno;
float score;
public:
student(string n, string na, int cn, float s);
student() {}
void s_cin(student &s);
void display()
{
cout << "编号:" << no << endl;
cout << "姓名:" << name << endl;
cout << "班号:" << Cno << endl;
cout << "成绩:" << score << endl;
}
~student();
};
/////////////////////////////////////////////////////////////////////////教师派生类
class teacher: private person
{
private:
string wname;
string wage;
public:
teacher(string n, string na, string wn, string wa);
teacher() {}
void t_cin(teacher &t);
void display()
{
cout << "编号:" << no << endl;
cout << "姓名:" << name << endl;
cout << "职称:" << wname << endl;
cout << "部门:" << wage << endl;
}
~teacher();
};
/////////////////////////////////////////////////////////////////////////
student::student(string n, string na, int cn, float s): person(n, na)
{
Cno = cn;
score = s;
}
void student::s_cin(student &s)
{
cout << "输入学生信息:" << endl;
cin >> s.no >> s.name >> s.Cno >> s.score;
}
student::~student()
{
}
//////////////////////////////////////////////////////////////////////////
teacher::teacher(string n, string na, string wn, string wa): person(n, na)
{
wname = wn;
wage = wa;
}
void teacher::t_cin(teacher &t)
{
cout << "输入学生信息:" << endl;
cin >> t.no >> t.name >> t.wname >> t.wage;
}
teacher::~teacher()
{
}
/////////////////////////////////////////////////////////////////
int _tmain(int argc, _TCHAR *argv[])
{
teacher t;
student s;
s.s_cin(s);
t.t_cin(t);
s.display();
t.display();
return 0;
}