第一题, 至于 用对象 指针 体会, 那 要自己写了, 我要上课了~~
#include<iostream.h>
#include<string.h>
class Cperson
{
protected:
char Cname[8];
char Csex[5];
int Iage;
public:
Cperson(){};
Cperson(char *n,char *s,int a)
{
strcpy(Cname,n);
strcpy(Csex,s);
Iage=a;
}
virtual void show()
{
cout<<"姓名:"<<Cname<<endl;
cout<<"性别:"<<Csex<<endl;
cout<<"年龄:"<<Iage<<endl;
}
};
class Cemployee : public Cperson
{
protected:
char Caddress[7];
double Fyingfawage;
double Fshifawage;
public:
Cemployee(){};
Cemployee(char *n,char *s,int a,char *d,double ying,double shi):Cperson(n,s,a)
{
strcpy(Cname,n);
strcpy(Csex,s);
Iage=a;
strcpy(Caddress,d);
Fyingfawage=ying;
Fshifawage=shi;
}
void show()
{
Cperson::show();
cout<<"单位:"<<Caddress<<endl;
cout<<"应发工资:"<<Fyingfawage<<endl;
cout<<"实发工资:"<<Fshifawage<<endl;
}
};
class Cstudent : public Cperson
{
protected:
char Cspecialty[10];
char Cgrade[10];
int Cid;
public:
Cstudent(){};
Cstudent(char *p,char *g,int i)
{
strcpy(Cspecialty,p);
strcpy(Cgrade,g);
Cid=i;
}
Cstudent(char *n,char *s,int a,char *p,char *g,int i):Cperson(n,s,a)
{
strcpy(Cspecialty,p);
strcpy(Cgrade,g);
Cid=i;
}
void show1()
{
cout<<"专业:"<<Cspecialty<<endl;
cout<<"年级:"<<Cgrade<<endl;
cout<<"学号:"<<Cid<<endl;
}
void show()
{
Cperson::show();
cout<<"专业:"<<Cspecialty<<endl;
cout<<"年级:"<<Cgrade<<endl;
cout<<"学号:"<<Cid<<endl;
}
};
class Cin_service:public Cemployee,public Cstudent
{
public:
Cin_service(char *n,char *s,int a,char *d,double ying,double shi,char *p,char *g,int i):Cemployee(n,s,a,d,ying,shi*0.8),Cstudent(p,g,i)
{
}
void show()
{
Cemployee::show();
Cstudent::show1();
}
};
int main()
{
Cperson person("张三","男",20);
person.show();
cout<<"*-------------------------------------------*"<<endl;
Cemployee employee("李四","女",20,"会计部",1500,1500);
employee.show();
cout<<"*-------------------------------------------*"<<endl;
Cstudent student("王五","男",20,"计算机","大三",456);
student.show();
cout<<"*-------------------------------------------*"<<endl;
Cin_service in_service("小样","男",20,"教研室",2000,2000,"计算机","大四",456);
in_service.show();
cout<<"*-------------------------------------------*"<<endl;
return 0;
}