数据结构的题目如下,急用、、、、、1 定义一个汽车类(car),至少包括构造函数,汽车行驶、停车等成员函数和型号、价格.重量、油耗、行驶速度等成员变量.2 将(1)中提到的成员变量定义为

来源:学生作业帮助网 编辑:作业帮 时间:2024/04/30 16:40:38

数据结构的题目如下,急用、、、、、1 定义一个汽车类(car),至少包括构造函数,汽车行驶、停车等成员函数和型号、价格.重量、油耗、行驶速度等成员变量.2 将(1)中提到的成员变量定义为
数据结构的题目如下,急用、、、、、
1 定义一个汽车类(car),至少包括构造函数,汽车行驶、停车等成员函数和型号、价格.重量、油耗、行驶速度等成员变量.
2 将(1)中提到的成员变量定义为私有访问权限,将成员函数定义为共有访问权限.
3 在主函数中定义三个汽车类的对象,并调用相关的成员函数.

数据结构的题目如下,急用、、、、、1 定义一个汽车类(car),至少包括构造函数,汽车行驶、停车等成员函数和型号、价格.重量、油耗、行驶速度等成员变量.2 将(1)中提到的成员变量定义为
#include
#include
using namespace std;
class car
{
private:
string style;//车型
float weight;//重量
float fconsum;//油耗
float speed;//速度
public:
car(string style,float weight,float fconsum,float speed)//构造函数
{
this->style = style;
this->weight = weight;
this->fconsum = fconsum;
this->speed = speed;
}
void driving();//行驶
void stop();//停车
void printstyle();//输出车型
};
void car::driving()
{
cout