各位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;
}
...全文
143 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;}
各位XDJM好, 你有没有因为在BBS上发了一篇征友贴苦等回复而每30秒看一次BBS?傻傻的.. 你有没有因为没注意到网络学堂作业信息而无辜的缺交作业?拉GPA的.. 你有没有因为各种事务缠身而遗憾的忘记了和mm的约会?百辞莫辩的.. 好消息,由于深深体会到以上各种悲剧,清华大学计算机科学实验班Dragon爷小组专门为大家编写网络资源管理器Cute Reminder(免安装试用包附件). 有了它,杯具将变为洗具 -.- 非主流评论: 《Times》: Cute Reminder是2010年第2天第3个小时里的最Out standing的软件,你值得拥有! 芙蓉姐姐:Cute Reminder我知道啊,男人好兄弟,女人好手,藕的小可爱t┓( ̄ε ̄)┏? 春哥曾爷:信春哥,用Cute Reminder;信曾爷,用Cute Reminder;是男的,用Cute Reminder;是女的,也用Cute Reminder 主要功能: 1.BBS(newsmth,各系bbs等)消息管理、消息提醒; 2.网络学堂信息管理、信息提醒; 3.备忘录功能、日程提醒。 主要特点: 1. 界面清秀; 2. 操作简单; 3. 功能强大; 4. 离perfect很近! 下载资源: 1.在百度或者google下搜索关键字 Cute Reminder Dragon或者Cute Reminder清华大学,第一条都是我们! 2.CSDN下载 http://download.csdn.net/source/1964308 3.纳米盘下载http://d.namipan.com/d/b8b19229ee6e471641a5838ebfa6d6c195273ea9cb8d0800 4.登录邮箱cutereminder2009@gmail.com(密码lovingyou)下载邮件附件! 联系我们: 如果任何疑问或者建议, 或者哪位DGG想严肃的拍我们Dragon组, 或者哪位mm/dd想认识我们组的优秀GG, 都请发送邮件至CuteReminder2010@gmail.com 或者联系站内:jacky@9# sbly@newsmth 您的支持,是我们前进的动力之源,请不吝回复邮件! --Dragon爷 --2010年1月4日

64,637

社区成员

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

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