在教师类里增加薪水计算函数,还增加学历数据项,该函数用于计算老师的月薪,月薪的多少与教龄和学历有关,自行设计月薪的计算方法。
代码如下:
#include<string.h>
#include<iostream.h>
class CPerson
{//Ex_Class.h
public:
CPerson()
{
strcpy(pName,"");
strcpy(pID,"");
}
CPerson(char*name,char*id,bool isman=1)
{
Input(name,id,isman);
}
//输入函数
void Input(char*name,char*id,bool isman)
{
setName(name);
setID(id);
setSex(isman);
}
//输出函数
void Output()
{
cout<<"姓名:"<<pName<<endl;
cout<<"编号:"<<pID<<endl;
char*str=bMan?"男":"女";
cout<<"性别:"<<str<<endl;
}
public:
char*getName()const
{return(char*)pName;}
//姓名输入
void setName(char*name)
{
int n=strlen(name);
strncpy(pName,name,n);
pName[n]='\0';
}
char*getID()const
{return(char*)pID;}
//编号输入
void setID(char*id)
{
int n=strlen(id);
strncpy(pID,id,n);
pID[n]='\0';
}
bool getSex(){return bMan;}
//性别判断函数
void setSex(bool isman){bMan=isman;}
private:
char pName[20];
char pID[20];
bool bMan;
};
//添加部分
class CStudent:public CPerson
{
public:
CStudent(char*name,char*id,bool isman=1);
~CStudent(){}
void InputScore(double score1,double score2,double score3);
void Print();
CPerson student;
private:
double dbScore[3];
};
class CTeacher:public CPerson
{
public:
CTeacher(char*name,char*id,bool isman=1,int years=10);
~CTeacher(){}
void Print();
private:
int nTeachYears;
};
#include<iostream.h>
#include"Ex_Class.h"
CStudent::CStudent(char*name,char*id,bool isman):student(name,id,isman)
{
dbScore[0]=0;
dbScore[1]=0;
dbScore[2]=0;
}
void CStudent::InputScore(double score1,double score2,double score3)
{
dbScore[0]=score1;
dbScore[1]=score2;
dbScore[2]=score3;
}
void CStudent::Print()
{
student.Output();
for(int i=0;i<3;i++)
cout<<"成绩:"<<i+1<<":"<<dbScore[i]<<endl;
}
CTeacher::CTeacher(char*name,char*id,bool isman,int years)
{
nTeachYears=years;
Input(name,id,isman);
}
void CTeacher::Print()
{
Output();
cout<<""<<nTeachYears<<endl;
}
void main()
{
CStudent stu("LiMing","21010211");
cout<<stu.getName()<<endl;
cout<<stu.student.getName()<<endl;
stu.Print();
stu.student.setName("LingLing");
stu.student.setSex(0);
stu.InputScore(80,90,85);
stu.Print();
CTeacher tea("Ding","911085");
tea.Print();
tea.setID("9110234");
tea.Print();
}
问题:在教师类里增加薪水计算函数,还增加学历数据项,该函数用于计算老师的月薪,月薪的多少与教龄和学历有关,自行设计月薪的计算方法。
3楼大哥,代码插在那边啊