急急急!!!在线等!!C++改错!!
/*要求:运用多态性与虚函数计算工资总工资=基本工资+每节课工资*上课总数教授:基本工资5000每节课50补贴;副教授:基本工资3000每节课30补贴;普通教师:基本工资...
/*要求:运用多态性与虚函数 计算工资 总工资=基本工资+每节课工资*上课总数 教授:基本工资5000 每节课50补贴; 副教授:基本工资3000 每节课30补贴; 普通教师:基本工资2000 每节课20补贴;我定义Aprofseeor 副教授; NormalTeacher 普通教师*/
#include<iostream>
using namespace std;
class Teacher
{
protected:
int Basewage,Totalwage,Totalcourse,wagepercourse;
char Post;
public:
virtual void wage()=0;
int Computwage(int Basewage,int wagepercourse,int Totalcourse)
{
Totalwage=Basewage+wagepercourse*Totalcourse;
return Totalwage;
}
void show(char post)
{
cout<<"The total wage of the"<<Post<<"is"<<Totalwage<<endl;
}
};
class Professor:public Teacher
{
public:
Professor()
{
Basewage=5000;
wagepercourse=50;
cout<<"Please intput the total course !\n";
cin>>Totalcourse;
}
virtual void wage()
{
Computwage(5000,50,Totalcourse);
}
};
class AProfessor:public Teacher
{
public:
AProfessor()
{
Basewage=3000;
wagepercourse=30;
cout<<"Please intput the total course !\n";
cin>>Totalcourse;
}
virtual void wage()
{
Computwage(3000,30,Totalcourse);
}
};
class NormalTeacher:public Teacher
{
public:
NormalTeacher()
{
Basewage=2000;
wagepercourse=20;
cout<<"Please intput the total course !\n";
cin>>Totalcourse;
}
virtual void wage()
{
Computwage(2000,20,Totalcourse);
}
};
void main()
{
char post;
Teacher *t;
star:cout<<"************Please select the post of the teacher**************\n";
cout<<"1 for Professor 2 for A-Professor 3 for Normal-teacher\n";
cin>>post;
if(post==1)
{
Professor p;
t=&p;
t->wage();
t->show(professor);
}
else if(post==2)
{
Aprofessor a;
t=&a;
t->wage();
t->show(Aprofessor);
}
else if(post==3)
{
Normalteacher n;
t=&n;
t->wage();
t->show(Normalteacher);
}
else
{
cout<<"Error !!! There have no such option!!!\nPlease select again !!!\n";
goto star;
}
} 展开
#include<iostream>
using namespace std;
class Teacher
{
protected:
int Basewage,Totalwage,Totalcourse,wagepercourse;
char Post;
public:
virtual void wage()=0;
int Computwage(int Basewage,int wagepercourse,int Totalcourse)
{
Totalwage=Basewage+wagepercourse*Totalcourse;
return Totalwage;
}
void show(char post)
{
cout<<"The total wage of the"<<Post<<"is"<<Totalwage<<endl;
}
};
class Professor:public Teacher
{
public:
Professor()
{
Basewage=5000;
wagepercourse=50;
cout<<"Please intput the total course !\n";
cin>>Totalcourse;
}
virtual void wage()
{
Computwage(5000,50,Totalcourse);
}
};
class AProfessor:public Teacher
{
public:
AProfessor()
{
Basewage=3000;
wagepercourse=30;
cout<<"Please intput the total course !\n";
cin>>Totalcourse;
}
virtual void wage()
{
Computwage(3000,30,Totalcourse);
}
};
class NormalTeacher:public Teacher
{
public:
NormalTeacher()
{
Basewage=2000;
wagepercourse=20;
cout<<"Please intput the total course !\n";
cin>>Totalcourse;
}
virtual void wage()
{
Computwage(2000,20,Totalcourse);
}
};
void main()
{
char post;
Teacher *t;
star:cout<<"************Please select the post of the teacher**************\n";
cout<<"1 for Professor 2 for A-Professor 3 for Normal-teacher\n";
cin>>post;
if(post==1)
{
Professor p;
t=&p;
t->wage();
t->show(professor);
}
else if(post==2)
{
Aprofessor a;
t=&a;
t->wage();
t->show(Aprofessor);
}
else if(post==3)
{
Normalteacher n;
t=&n;
t->wage();
t->show(Normalteacher);
}
else
{
cout<<"Error !!! There have no such option!!!\nPlease select again !!!\n";
goto star;
}
} 展开
1个回答
展开全部
请紧记C语言中区分大小写,例如post和Post是不同的两个词。
void show(char post)
{
cout<<"The total wage of the"<<post<<"is"<<Totalwage<<endl;
}
void main()
{
char post;
Teacher *t;
star:cout<<"************Please select the post of the teacher**************\n";
cout<<"1 for Professor 2 for A-Professor 3 for Normal-teacher\n";
cin>>post;
if(post=='1')
{
Professor p;
t=&p;
t->wage();
t->show(post);
}
else if(post=='2')
{
AProfessor a;
t=&a;
t->wage();
t->show(post);
}
else if(post=='3')
{
NormalTeacher n;
t=&n;
t->wage();
t->show(post);
}
else
{
cout<<"Error !!! There have no such option!!!\nPlease select again !!!\n";
goto star;
}
}
void show(char post)
{
cout<<"The total wage of the"<<post<<"is"<<Totalwage<<endl;
}
void main()
{
char post;
Teacher *t;
star:cout<<"************Please select the post of the teacher**************\n";
cout<<"1 for Professor 2 for A-Professor 3 for Normal-teacher\n";
cin>>post;
if(post=='1')
{
Professor p;
t=&p;
t->wage();
t->show(post);
}
else if(post=='2')
{
AProfessor a;
t=&a;
t->wage();
t->show(post);
}
else if(post=='3')
{
NormalTeacher n;
t=&n;
t->wage();
t->show(post);
}
else
{
cout<<"Error !!! There have no such option!!!\nPlease select again !!!\n";
goto star;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询