赏100分请高人进来帮帮

来源:百度知道 编辑:UC知道 时间:2024/06/25 06:00:54
1. 定义一个类来描述手机电池,类的名称是battery,类中要描述电池的重量(float heavy)和储电量(int column)。(1分)
2. 根据下面的输出和主函数语句,定义构造函数。(2分)
void main()
{
battery bat1;
cout<<"电池bat1的储电量:"<<bat1.cloumn<<"毫安"<<endl
<<"电池bat1的重量:"<<bat1.heavy<<"克"<<endl;

battery bat2(100.0,20000);
battery* pt = NULL;
pt = &bat2;
cout<<"电池bat2的储电量:"<<pt->cloumn<<"毫安"<<endl
<<"电池bat2的重量:"<<pt->heavy<<"克"<<endl;
}
执行结果
3. 根据第一第二道题的提示,模仿定义一个类Mobile用来描述手机,类中描述手机的重量和通话时长,要求用你定义的Mobile定义变量和指针,分别通过变量名和指针来访问类中的成员。

#include<iostream.h>

class battery
{
public:
float heavy;
int cloumn;
public:
battery(float h=0,int c=0):heavy(h),cloumn(c){};
};

class mobile
{
public:
float heavy;
float time;
mobile(float h=0,float t=0):heavy(h),time(t){};
};

void main()
{
battery bat1;

cout<<"电池bat1的储电量:"<<bat1.cloumn<<"毫安"<<endl
<<"电池bat1的重量:"<<bat1.heavy<<"克"<<endl;

battery bat2(100.0,20000);
battery* pt = NULL;
pt = &bat2;
cout<<"电池bat2的储电量:"<<pt->cloumn<<"毫安"<<endl
<<"电池bat2的重量:"<<pt->heavy<<"克"<<endl;

mobile mob(73.0,23.8),*pmob=&mob;
cout<<"手机mob的重量:"<<mob.heavy<<"克"<<endl
<<"手