定义一个汽车类,数据成员包括汽车品牌、型号、颜色和发动机排量,成员函数包括启动发动机和熄火功能。生成一个汽车类的对象,并用构造函数给这个对象赋初值,该汽车对象为比亚迪黑色秦pro 1.5L排量的小轿车
#include <stdio.h>
#include <string>
#include <vector>
#include <map>
#include <iostream>
using namespace std;
class car
{
public:
car(string brand, string model, string color, string displacement);
~car();
public:
void StartUpCar();
void StopUpCar();
private:
bool m_bIsStartUp;
string m_brand;
string m_model;
string m_color;
string m_displacement;
};
car::car(string brand, string model, string color, string displacement):
m_brand(brand),m_model(model), m_color(color), m_displacement(displacement), m_bIsStartUp(false)
{
}
car::~car()
{
}
void car::StartUpCar()
{
if (m_bIsStartUp)
cout << "车已启动" << endl;
else
{
cout << "正在启动" << endl;
m_bIsStartUp = true;
}
}
void car::StartUpCar()
{
if (!m_bIsStartUp)
cout << "车已熄火" << endl;
else
{
cout << "正在熄火" << endl;
m_bIsStartUp = false;
}
}
int main(void)
{
car mycar("比亚迪", "秦pro", "黑色", "1.5L排量");
return 0;
}
??? 问题呢?就是写这么一个类? 你这不是定义完了吗