两个C++的小题目

1.编写一个程序设计一个汽车类vehicle,包含的数据成员有车轮个数wheels和车重weight。小车类car是它的私有派生类其中包含载人数passenger_loa... 1.编写一个程序设计一个汽车类vehicle,包含的数据成员有车轮个数wheels和车重weight。小车类car是它的私有派生类其中包含载人数passenger_load。卡车类truck是vehicle的私有派生类其中包含载人数passenger_load和载重量payload,每个类都有相关数据的输出方法。
2.设计一个圆类circle和一个桌子类table,另设计一个圆桌类roundtable,它是从前两个类派生的,要求输出一个圆桌的高度、面积和颜色等数据。
展开
 我来答
百度网友4fee1d0
2009-09-29 · TA获得超过340个赞
知道小有建树答主
回答量:411
采纳率:0%
帮助的人:275万
展开全部
第一题:
#include <iostream>
using namespace std;
class vehicle
{
public:
//vehicle(){}
vehicle(int wh,double wei)
{
wheels = wh;
weight = wei;
}
void show()
{
cout<<"wheels= "<<wheels<<",weight= "<<weight<<endl;
}
private:
int wheels;
double weight;
};
class car: private vehicle
{
public:
car(int wh,double wei,int pass):vehicle(wh,wei)
{
//vehicle(wh,wei);
passenger_load = pass;
}
void show()
{
vehicle::show();
cout<<"passenger_load= "<<passenger_load<<endl;
}
private:
int passenger_load;
};
class truck:private vehicle
{
public:
truck(int wh,double wei,int pass,double payL):vehicle(wh,wei)
{
//vehicle(wh,wei);
passenger_load = pass;
payload = payL;
}
void show()
{
vehicle::show();
cout<<"passenger_load = "<<passenger_load
<<",payload = "<<payload<<endl;
}
private:
int passenger_load;
double payload;
};
void main()
{
vehicle v(4,6);
v.show();
car c(4,4,6);
c.show();
truck t(6,8,2,6);
t.show();
}

第二题:
#include <string>
#include <iostream>
using namespace std;

class Circle
{
public:
Circle(double r){radius=r;}
double Area(){return 3.14*radius*radius;}
private:
double radius;
};
class Table
{
public:
Table(double h,string col){height=h;color=col;}
double GetH(){return height;}
string GetCol(){return color;}
private:
double height;
string color;
};
class roundTable:public Circle,Table
{
public:
roundTable(double r,double h,string col):Circle(r),Table(h,col){}
void Display();
};
void roundTable::Display()
{
cout<<"Height of the roundTable is: "<<GetH()<<endl;
cout<<"Area of the roundTable is: "<<Area()<<endl;
cout<<"Color of the roundTable is: "<<GetCol()<<endl;
}
void main()
{
roundTable rt(1,1,"red");
rt.Display();
}
百度网友0974edce8
2009-09-29 · TA获得超过490个赞
知道小有建树答主
回答量:381
采纳率:0%
帮助的人:253万
展开全部
第一个:
#include<iostream>
using namespace std;

class vehicle{
protected:
int wheels;
float weight;
public:
void display();
};

class car:private vehicle{
private:
int passenger_load;
public:
void display();
};

class truck:private vehicle{
private:
int passenger_load;
float payload;
public:
void display();
};

void vehicle::display(){
cout<<"wheels are :"<<wheels<<endl;
cout<<"weight is :"<<weight<<"kg"<<endl;
}

void car::display(){
cout<<"the car's wheels are :"<<wheels<<endl;
cout<<"weight is :"<<weight<<"kg"<<endl;
cout<<"max passenger load are :"<<passenger_load<<endl;
}

void truck::display(){
cout<<"the truck's wheels are :"<<wheels<<endl;
cout<<"weight is :"<<weight<<"kg"<<endl;
cout<<"max passenger load are :"<<passenger_load<<endl;
cout<<"pay load is"<<payload<<endl;
}
void main(){

}

好像第二个也差不多,不想写了。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
s3938931
2009-09-29 · TA获得超过871个赞
知道小有建树答主
回答量:577
采纳率:100%
帮助的人:173万
展开全部
第一题:
class vehicle
{
private:
int wheels;
float weight;
vehicle(0,0.0);
int get_wheels();
float get_weight();
void printV();
};
class car:private vehicle
{
private:
int passenger_load;
public:
car(4);
int get_passengers();
void printC();
}
class truck:private vehicle
{
private:
int passenger_load;
float payload;
public:
truck(0,0.0);
int get_passengers();
float get_payload();
void printT();
}
第二题:
class circle
{
float r;
void area(float R);
void Print();
}
class table
{
float high;
char color;
void print();
}
class roundtable : public circle,table
{
}
期中内容你可以自己加,我给的是框架;函数内容自己写。。。。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式