}
voidmain()
{
inta,b;
cin>>a>>b;
Pointp1(a,b);
cin>>a>>b;
Pointp2(a,b);
Distancedis(p1,p2);
}
8、定义一个描述员工(Employee)基本情况的类,数据成员包括编号(num)、姓名(name)、性别(sex)、
工资(wage)、人数(count)、总工资(totalWage)。
其中姓名定义为长度为18的字符数组,
性别定义为长度为3的字符数组,其它数据类型为整型,总工资和人数为静态数据成员,函
数成员包括构造函数、显示基本函数(ShowBase)和显示静态数据函数(ShowStatic),其
中构造函数由已知参数编号(nu),姓名(nm)、性别(sx)和工资(wg)构造对象,
显示基本数据函数用于显示学生的编号、姓名、性别和工资,显示静态数据函数为静态成员
函数,用于显示人数和总工资;
要求所有数据成员为protected访问权限,所有成员函数为public访问权限,在主函数中定
义若干个员工对象,分别显示员工基本信息,以及显示员工人数和总工资。
#include
#include
usingnamespacestd;
classEmployee
{
protected:
intnum,wage;
staticintcount;
staticinttotalWage;
charname[18],sex[3];
public:
Employee(intnu,char*nm,char*sx,intwg);
Employee(){};
~Employee();ShowBase();
staticintShowStatic();
};
Employee:
:
ShowBase()
{
cout<<"\n个人基本信息:
";
cout<<"\n编号:
"<cout<<"姓名:
"<cout<<"性别:
"<cout<<"工资:
"<}
Employee:
:
ShowStatic()
{
cout<<"人数:
"<cout<<"总工资:
"<returntotalWage;
}
intEmployee:
:
count=0;
intEmployee:
:
totalWage=0;
Employee:
:
Employee(intnu,char*nm,char*sx,intwg)
{
num=nu;
wage=wg;
strcpy(name,nm);
strcpy(sex,sx);
++count;
totalWage+=wg;
}
Employee:
:
~Employee(){}
intmain()
{
intn;
cin>>n;
Employee*m=newEmployee[n];
intnu,wg;
charnm[18],sx[3];
for(inti=0;i{
cin>>nu>>nm>>sx>>wg;
m[i]=Employee(nu,nm,sx,wg);
}
Employee:
:
ShowStatic();
for(i=0;im[i].ShowBase();
return0;
delete[]m;
}
9、定义一个时间类Time,能提供和设置由时、分、秒组成的时间。
编写程序,提供类的构造函数用于根据输入初始化时间类Time的对象;提供函数用于输出时间类对象的时间,按照如下格式输出:
hh:
mm:
ssAM/PM
#include
usingnamespacestd;
classTime{
inthour;
intminute;
intsecond;
public:
voidtime(inth,intm,ints)
{
hour=h;
minute=m;
second=s;
}
voidtest()
{
if((hour>24)||(hour<0)||(minute>60)||(minute<0)||(second>60)||(second<0))
cout<<"ERRORTIME"<elseif(hour<=9&&hour>=0)
{
if(minute<=9&&minute>=0)
{
if(second<=9&&second>=0)
cout<<"0"<0"<0"<else
cout<<"0"<0"<"<}
if(minute>9)
{
if(second<=9&&second>=0)
cout<<"0"<"<0"<else
cout<<"0"<"<"<}
}
elseif(hour<12)
{
if(minute<=9&&minute>=0)
{
if(second<=9&&second>=0)
cout<0"<0"<else
cout<0"<"<}
if(minute>9)
{
if(second<=9&&second>=0)
cout<"<0"<else
cout<"<"<}
}
elseif(hour==12)
{
if(minute<=9&&minute>=0)
{
if(second<=9&&second>=0)
cout<0"<0"<else
cout<0"<"<}
if(minute>9)
{
if(second<=9&&second>=0)
cout<"<0"<else
cout<"<