【c++基础】075汽车类的设计

简介:汽车类的设计

汽车的抽象描述

汽车类的特征和功能——分析抽象汽车个体的特征和功能

  • 特征:型号、颜色、价格、出厂日期、载客量、载重量……
  • 功能:运动、鸣笛、倒车、播放音乐、恒温、定位……

汽车类的定义

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86

#include <cstring>
#include <mmsystem.h>
#include <windows.h>
using namespace std;
class
{
private:
char type[20];
char color[20]; //汽车颜色
float price; //价格
int carry_weight; //载重量
int carry_customer; //载客量
public:
void set_data(char *t, char *c, float pri, int cw, int cc); //初始化或修改数据成员
void movecar(int l, int k); //汽车水平运动k部
void horming(int num); //汽车鸣笛
void downcar(int l); //汽车垂直向下运动
void play_mp3(char *ps); //播放歌曲
char *show_type() { return type; } //取出汽车型号
};
void automobile::set_data(char *t, char *c, float pri, int cw, int cc)
{
strcpy(type, t);
strcpy(color, c);
price = pri;
carry_weight = cw;
carry_customer = cc;
}
void automobile::movecar(int l, int k)
{
cout << "n"
<< type << "水平直线运动:" << endl;
for (int i = 0; i < l; i++)
{
cout << ' ' << "o_o";
Sleep(1000 / k);
cout << "bbb";
}
}
void automobile::downcar(int l)
{
cout << "n"
<< type << "垂直下降运动:" << endl;
for (int i = 0; i < l; i++)
{
cout << "o_o";
Sleep(500);
cout << "bbb"
<< " ";
cout << endl;
}
}
void automobile::horming(int num)
{ //鸣笛
for (int i = 0; i < num; i++)
{
cout << type;
cout << '