-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass.cpp
More file actions
55 lines (39 loc) · 1.13 KB
/
Copy pathclass.cpp
File metadata and controls
55 lines (39 loc) · 1.13 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
#include "iostream"
#include <string>
using namespace std;
class Car {
int price = 100000;
public:
Car(string Model, int Speed, int Year) {
model = Model, speed = Speed, year = Year;
}
float speed;
string model;
int year;
string honk() { return "beep beep..."; }
virtual int Price() { return price; }
};
class RacingCar : public Car {
int price = 1000000;
public:
RacingCar(string Model, int Speed, int Year) : Car(Model, Speed, Year) {
model = Model, speed = Speed, year = Year;
};
string honk() { return "hoove hooove..."; }
string getInfo() {
return model + " with " + to_string(speed) + " km/hr speed" + " made at " +
to_string(year) + ".";
}
int Price() override { return price; }
};
int main() {
Car *myCar = new Car("Normal V1", 180, 2025);
cout << myCar->model + " with " + to_string(myCar->speed) + " km/hr speed"
<< endl;
cout << "price: " << myCar->Price() << endl;
cout << myCar->honk() << endl;
RacingCar *myFastCar = new RacingCar("Rose", 350, 2026);
cout << myFastCar->getInfo() << endl;
cout << "price: " << myFastCar->Price() << endl;
return 0;
}