一道的C++编程题目(在线等)

在教师类里增加薪水计算函数,还增加学历数据项,该函数用于计算老师的月薪,月薪的多少与教龄和学历有关,自行设计月薪的计算方法。
代码如下:
#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楼大哥,代码插在那边啊

下面是完整的代码
#define ZHUANKE 1
#define BENKE 2
#define SHUOSHI 3
#define BOSHI 4

#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(){}
float CalSalary() {return 1000+(float)Xueli*100+(float)nTeachYears; }//薪水计算函数
void SetXueli(int x) {Xueli = x;}//设置学历函数
void Print();
private:
int nTeachYears;
int Xueli;
};

#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);
Xueli = BENKE;//缺省学历为本科
}
void CTeacher::Print()
{
Output();
cout<<"教龄:"<<nTeachYears<<endl;
cout<<"学历:";
switch (Xueli)
{
case BENKE:
cout<<"本科"<<endl;
break;
case ZHUANKE:
cout<<"专科"<<endl;
break;
case SHUOSHI:
cout<<"硕士研究生"<<endl;
break;
case BOSHI:
cout<<"博士研究生"<<endl;
break;
default:
break;
}
cout<<"月薪:"<<CalSalary()<<endl<<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.SetXueli(SHUOSHI);
tea.Print();
}
温馨提示:内容为网友见解,仅供参考
第1个回答  2008-10-13
啥意思?
第2个回答  2008-10-13
对啊,什么问题呢?要改错吗?
第3个回答  2008-10-13
问题都没提,怎么回答咩
相似回答