};
intmain()
{
Derivedd;
return(0);
}
#include
#include
#include
classperson
{
public:
voidprint();
person(chara[],intb,charc[]);
protected:
charname[20];
intage;
charsex[5];
};
person:
:
person(chara[],intb,charc[])
{
strcpy(name,a);
age=b;
strcpy(sex,c);
}
voidperson:
:
print()
{
cout<<"姓名"<<""<}
classteacher:
virtualpublicperson
{
public:
teacher(chara[],intb,charc[],chard[]);
voidprint();
protected:
chardepartment[50];
};
teacher:
:
teacher(chara[],intb,charc[],chard[]):
person(a,b,c)
{
strcpy(department,d);
}
voidteacher:
:
print()
{
person:
:
print();
cout<}
classstudent:
virtualpublicperson
{
public:
student(chara[],intb,charc[],chard[]);
voidprint();
protected:
charspeciality[50];
};
student:
:
student(chara[],intb,charc[],chard[]):
person(a,b,c)
{
strcpy(speciality,d);
}
voidstudent:
:
print()
{
person:
:
print();
cout<}
classprofessor:
publicperson
{
public:
voidprint();
professor(chara[],intb,charc[],chard[],chare[]);
protected:
charposition[50];
chardepartment[50];
};
professor:
:
professor(chara[],intb,charc[],chard[],chare[]):
person(a,b,c)
{
strcpy(position,d);
strcpy(department,e);
}
voidprofessor:
:
print()
{
person:
:
print();
cout<}
classstuTeacher:
publicteacher,publicstudent
{
public:
stuTeacher(chara[],intb,charc[],chard[],chare[]);
voidprint();
};
stuTeacher:
:
stuTeacher(chara[],intb,charc[],chard[],chare[]):
person(a,b,c),student(a,b,c,d),teacher(a,b,c,e)
{}
voidstuTeacher:
:
print()
{
person:
:
print();
cout<}
intmain()
{
teachera("zhang",30,"男","电院");
a.print();
studentb("刘道广",20,"男","计算机");
b.print();
professorc("wang",40,"女","教授","材工");
c.print();
stuTeacherd("zhou",25,"女","国际贸易","管院");
d.print();
return(0);
}
#include
#include
#include
floatm,n;
classfraction
{
public:
fraction(floatx=1,floaty=1);
fractionoperator+(fraction&c);
fractionoperator-(fraction&c);
fractionoperator*(fraction&c);
fractionoperator/(fraction&c);
voiddisplay(void);
private:
floata;
floatb;
};
fraction:
:
fraction(floatx,floaty)
{
a=x;
b=y;
}
fractionfraction:
:
operator+(fraction&c)
{
m=a+c.a;
n=b+c.b;
return(fraction(m,n));
}
fractionfraction:
:
operator-(fraction&c)
{
m=a-c.a;
n=b-c.b;
return(fraction(m,n));
}
fractionfraction:
:
operator*(fraction&c)
{
m=a*c.a-b*c.b;
n=a*c.b+b*c.a;
return(fraction(m,n));
}
fractionfraction:
:
operator/(fraction&c)
{
if(c.a==0&&c.b==0)
{
cout<<"输入错误"<exit(0);
}
m=(a*c.a+b*c.b)/(c.a*c.a+c.b*c.b);
n=(b*c.a-a*c.b)/(c.a*c.a+c.b*c.b);
return(fraction(m,n));
}
voidfraction:
:
display()
{
cout<}
intmain()
{
fractionx(3,4),y(1,2),z;
z=x+y;
z.display();
z=x-y;
z.display();
z=x*y;
z.display();
z=x/y;
z.display();
return(0);
}
运行结果:
4+6i
2+2i
-5+10i
2.2+-0.4i