-
Notifications
You must be signed in to change notification settings - Fork 0
/
34-Struct-pt2.cpp
50 lines (40 loc) · 984 Bytes
/
34-Struct-pt2.cpp
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
#include <iostream>
#include <stack>
using namespace std;
struct Car {
string name;
string color;
int hp;
int topSpd;
int spd
void insertdata (string stname, string stcolor, int sthp, int sttopspd){
name = stname;
color = stcolor;
hp = sthp;
topSpd = sttopspd;
}
void display(){
cout << "Car Name: ............ " << name << "\n";
cout << "Car Color: ........... " << color << "\n";
cout << "Car Horse Power: ..... " << hp << "\n";
cout << "Car Current Speed: ... " << spd<< "\n";
cout << "Car Top Speed: ....... " << topSpd << "\n";
}
void changeSpd(int chspd){
spd = chspd;
if(spd > topSpd){
spd = topSpd;
}
if(spd < 0){
spd = 0;
}
}
};
int main(){
Car car1;
car1.insertdata("Tornado", "Red", 450, 350);
car1.display();
car1.changeSpd(150);
car1.display();
return 0;
}