-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCar_Implement.cpp
More file actions
79 lines (72 loc) · 1.33 KB
/
Copy pathCar_Implement.cpp
File metadata and controls
79 lines (72 loc) · 1.33 KB
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
// 20190414_ex1.cpp: 主要專案檔。
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
class CAR{
private:
int no;
int speed;
string name;
public:
static int iCount;
CAR(){
++iCount;
speed = 0;
name = "";
no = iCount;
cout << name << no << " 物件被建立....\n";
}
CAR(string n){
++iCount;
speed = 0; //留意 要給初始值
name = n;
no = iCount;
cout << name << no << " 物件被建立....\n";
}
~CAR(){
cout << name << "物件被消滅....\n";
--iCount;
}
void speedup(const int s = 0){
speed += s;
//speed = speed + s;
}
void speeddown(const int s = 0){
speed -=s;
}
void setBreak(){
speed = 0;
}
int showSpeed() const {
return speed;
}
string showName() const {
return name;
}
int showno() const {
return no;
}
};
//第一次CAR物件被建立時 執行
int CAR::iCount = 0;
//一般函式
void showCar(const CAR &);
int main()
{
CAR TOYOTA, BMW("小白");
TOYOTA.speedup(5);
TOYOTA.speedup(100);
BMW.speedup(99);
//cout << TOYOTA.showName() << " : " << TOYOTA.showSpeed() << endl;
//cout << BMW.showName() << " : " << BMW.showSpeed() << endl;
showCar(TOYOTA);
showCar(BMW);
cout << CAR::iCount << endl;
system("pause");
return 0;
}
void showCar(const CAR &c){
cout << "第" << c.showno() << "車 : " << c.showName() << " : " << c.showSpeed() << endl;
static CAR HONDA("小黑");
}