复制代码
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
87
88
89
90
91
92#include <iostream> #include <windows.h> //Sleep函数调用的头文件 #include <mmsystem.h> //媒体控制函数的头文件 //在VC2008和VC6.0环境中从此头文件 #pragma comment(lib, "winmm.lib") using namespace std; class automobile { private: char type[20]; char color[20]; float price; int carry_weight; int carry_customer; public: void set_date(char *t, char *c, float pri, int cw, int cc); //初始化或修改数据成员 void movecar(int l, int k); void horming(int num); void downcar(int l); void play_mp3(char *ps); char *show_type() { return type; } }; void automobile::set_date(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; for(int i=0; i<l; i++) { cout<<"o-o"; Sleep(1000); cout<<"bbb"<<" "; cout<<endl; } } void automobile::horming(int num) { for(int i=0; i<num; i++) { cout<<type; cout<<"07"<<"di.."<<endl; Sleep(1000); } } void automobile::play_mp3(char *ps) { char str[100]="play "; //play后面有空格 strcat(str,ps); cout<<str; mciSendString(str, NULL, 0, NULL); //如果不进行如下操作的话:会报错误: // C:UserssjcnhAppDataLocalTempcczFSVYd.o Car.cpp:(.text+0x2c6): undefined reference to `__imp_mciSendStringA' // D:60417collect2.exe [Error] ld returned 1 exit status //在Dec-C++环境中还要进行设置; //工具编译器选项编译器在连接器命令中加入一下命令-lwinmm char a; cin>>a; //输入任何字符结束播放 } int main() { automobile nisson; char tp[]="yyida"; char ys[]="white"; nisson.set_date(tp, ys, 5000, 20, 3); nisson.horming(5); nisson.movecar(10, 3); nisson.downcar(6); char mp[]="e:\爱很简单.mp3"; nisson.play_mp3(mp); return 0; // 1a2s3d45f67j8k90l90l }
最后
以上就是个性毛衣最近收集整理的关于C++汽车类实例的全部内容,更多相关C++汽车类实例内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复