各位GG,MM帮我看看,那里有错

LANTE80 2004-11-22 11:46:43
#include<iostream.h>
#include<person.h>
#include<employee.h>
#include<student.h>
#include<in_service.h>
class person{
protected:
char *name;
int age;
char *sex;
public:
person(char *x,int y,char *z)
{
name="x";
age=y;
sex="z";
}
~person()
{
}
void show()
{cout<<name<<endl<<sex<<endl<<age<<endl;}
};
class employee:virtual public person
{
protected:
char *department;
float salary;
public:
employee(char *x,int y,char *z,char *m,float n):person(char *x,int y,char *z)
{
department="m";
salary=n;
}
void show()
{ cout<<department<<endl<<salary<<endl;
}
};
class student:virtual public person
{
protected:
char *major;
int grade;
int number;
public:
student(char *x,int y,char *z,char *A,int B,int C):person(char *x,int y,char *
z)
{
major="A";
grade=B;
number=C;
}
void show()
{
cout<<major<<endl<<grade<<endl<<number<<endl;
}
};
class in_service:public employee,public student{
public:
in_service(char *x,int y,char *z,char *m,float n,char *A,int B,int C):
person(char *x,int y,char *z),employee(char *x,int y,char *z,char *m,float n
),
student(char *x,int y,char *z,char *A,int B,int C)
{
}
void show()
{
cout<<employee::department<<endl<<(employee::salary*0.8)<<endl;
}
};
int main()
{
cout<<"employee"<<endl;
employee e("ljj",23,"女","济大",2000.0);
e.show();
cout<<"student"<<endl;
student s("ljj",23,"女","计算机科学与技术",2001,2003370958);
s.show();
cout<<"in_service"<<endl;
in_service i("ljj",23,"女","济大",2000.0,"计算机科学与技术",2001,2003370958)
;
i.show();
return 0;
}
...全文
142 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Popo_CN 2004-11-22
  • 打赏
  • 举报
回复
#include <iostream.h>
class person{
protected:
char *name;
int age;
char *sex;
public:
person(char *x,int y,char *z)
{
name=x;
age=y;
sex=z;
}
~person()
{
}
void show()
{cout<<name<<endl<<sex<<endl<<age<<endl;}
};

class employee:virtual public person
{
protected:
char *department;
float salary;
public:
employee(char *x,int y,char *z,char *m,float n):person(x,y,z)
{
department=m;
salary=n;
}
void show()
{ cout<<department<<endl<<salary<<endl;
}
};
class student:virtual public person
{
protected:
char *major;
int grade;
int number;
public:
student(char *x,int y,char *z,char *A,int B,int C):person(x,y,z)
{
major=A;
grade=B;
number=C;
}
void show()
{
cout<<major<<endl<<grade<<endl<<number<<endl;
}
};
class in_service:public employee,public student{
public:
in_service(char *x,int y,char *z,char *m,float n,char *A,int B,int C):person(x,y,z),employee(x,y,z,m,n),student(x,y,z,A,B,C)
{
}
void show()
{
cout<<employee::department<<endl<<(employee::salary*0.8)<<endl;
}
};
int main()
{
cout<<"employee"<<endl;
employee e("ljj",23,"女","济大",2000.0);
e.show();
cout<<"student"<<endl;
student s("ljj",23,"女","计算机科学与技术",2001,2003370958);
s.show();
cout<<"in_service"<<endl;
in_service i("ljj",23,"女","济大",2000.0,"计算机科学与技术",2001,2003370958)
;
i.show();
return 0;
}
BinaryWorld 2004-11-22
  • 打赏
  • 举报
回复
#include<iostream.h>
#include<person.h>
#include<employee.h>
#include<student.h>
#include<in_service.h>
class person{
protected:
char *name;
int age;
char *sex;
public:
person(char *x,int y,char *z) // ???? x , z ???? what do u want to do ??
{
name="x";
age=y;
sex="z";
}

~person()
{

}

void show()
{
cout<<name<<endl<<sex<<endl<<age<<endl;
}
};

class employee:virtual public person
{
protected:
char *department;
float salary;

public:
employee(char *x,int y,char *z,char *m,float n):
///Modified By Glory
/*** original
person(char *x,int y,char *z)
***/
/// crazy code ! hehe :-)
person( x, y, z )
///End Modify
{
department="m";// I don't understand why use the parameter m
salary=n;
}
void show()
{ cout<<department<<endl<<salary<<endl;
}
};
class student:virtual public person
{
protected:
char *major;
int grade;
int number;

public:
student(char *x,int y,char *z,char *A,int B,int C):
///Modified By Glory
/*** again!!!
person(char *x,int y,char *z)
***/
///End Modify
{
major="A"; // !!! again!!
grade=B;
number=C;
}
void show()
{
cout<<major<<endl<<grade<<endl<<number<<endl;
}
};

class in_service:public employee,public student
{
public:
in_service(char *x,int y,char *z,char *m,float n,char *A,int B,int C):
///Modified By Glory
/*** original error!!!!
person(char *x,int y,char *z),employee(char *x,int y,char *z,char *m,float n),
student(char *x,int y,char *z,char *A,int B,int C)
***/
///End Modify
{
}

void show()
{
cout<<employee::department<<endl<<(employee::salary*0.8)<<endl;
}
};
int main()
{
cout<<"employee"<<endl;
employee e("ljj",23,"女","济大",2000.0);/* !!!!dont use a float vari to set the date and time */
/* if you really want to do this , i think you'b better use a long type or int type vari */
/* e. 20041012, you can use a little parsar to get the year and the month and the date !!!!*/
e.show();
cout<<"student"<<endl;
student s("ljj",23,"女","计算机科学与技术",2001,2003370958);
s.show();
cout<<"in_service"<<endl;
in_service i("ljj",23,"女","济大",2000.0,"计算机科学与技术",2001,2003370958);
i.show();
return 0;
}
redjackwong 2004-11-22
  • 打赏
  • 举报
回复
name="x";
age=y;
sex="z";

这样初始化后name的值为x,而不是字符串x的值。应该是
name=x;
age=y;
sex=z;

danlansky 2004-11-22
  • 打赏
  • 举报
回复
person(char *x,int y,char *z)
{
name="x";//想初始化为“x”呢?还是接受char *x中的值呢
age=y;
sex="z";//想初始化为“z”呢?还是接受char *z中的值呢
}
我理解你的构造函数是想这样吧:
person(char *x,int y,char *z)
{ name=x; age=y; sex=z;}

64,637

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧