#2
家力掠2016-01-31 17:21
|
程序代码:
#include <iostream>
#include <string>
using namespace std;
class Teacher
{
public:
Teacher(string n, int ag, char s, string a, string te, string ti)
:{age = ag; sex = s; tel = te; title = ti; addr = a; name = n; }
void display();
protected:
int age;
char sex;
string tel;
string title;
string addr;
string name;
};
class Cadre: public Teacher
{
public:
Cadre(string n, int ag, char s, string a, string te, string p, string ti)
:Teacher(string n, int age, string a, string te, string ti) {post = p;}
protected:
string post;
};
class Teacher_Cadre :public Cadre
{
public:
void show();
Teacher_Cadre(string n, int ag, char s, string a, string te, int w, string p, string ti)
:Cadre(string n, int ag, char s, string a, string te, string p, string ti){wages = w; }
protected:
int wages;
};
void Teacher_Cadre::show()
{
display();
cout << "wage:" << wages << endl;
cout << "post:" << Cadre::post << endl;
}
void Teacher::display()
{
cout << "name:" << name << endl;
cout << "age:" << age << endl;
cout << "sex:" << sex << endl;
cout << "title" << title << endl;
cout << "address:" << addr << endl;
cout << "telephone:" << tel << endl;
}
int main(void)
{
Teacher_Cadre tea("chenxingyin", 18, 'f', "YangqiaoRoad,fuzhou", "15386479123", 5600, "teacher", "dr.");
tea.show();
return 0;
}
编译出来挺多错误的,又不知道怎么改,只能过来求助。#include <string>
using namespace std;
class Teacher
{
public:
Teacher(string n, int ag, char s, string a, string te, string ti)
:{age = ag; sex = s; tel = te; title = ti; addr = a; name = n; }
void display();
protected:
int age;
char sex;
string tel;
string title;
string addr;
string name;
};
class Cadre: public Teacher
{
public:
Cadre(string n, int ag, char s, string a, string te, string p, string ti)
:Teacher(string n, int age, string a, string te, string ti) {post = p;}
protected:
string post;
};
class Teacher_Cadre :public Cadre
{
public:
void show();
Teacher_Cadre(string n, int ag, char s, string a, string te, int w, string p, string ti)
:Cadre(string n, int ag, char s, string a, string te, string p, string ti){wages = w; }
protected:
int wages;
};
void Teacher_Cadre::show()
{
display();
cout << "wage:" << wages << endl;
cout << "post:" << Cadre::post << endl;
}
void Teacher::display()
{
cout << "name:" << name << endl;
cout << "age:" << age << endl;
cout << "sex:" << sex << endl;
cout << "title" << title << endl;
cout << "address:" << addr << endl;
cout << "telephone:" << tel << endl;
}
int main(void)
{
Teacher_Cadre tea("chenxingyin", 18, 'f', "YangqiaoRoad,fuzhou", "15386479123", 5600, "teacher", "dr.");
tea.show();
return 0;
}