-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcar.cpp
More file actions
53 lines (46 loc) · 1.26 KB
/
Copy pathcar.cpp
File metadata and controls
53 lines (46 loc) · 1.26 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
#include <iostream>
#include <string>
using namespace std;
class Car
{
public: // access specifier e.g private (default), public, protected
string brand;
string model;
int year;
Car(string brand, string model, int year); // Constructor declaration
// Car(string brand, string model, int year)
// { // Constructor with parameters
// brand = brand;
// model = model;
// year = year;
// }
// Default empty constructor will call when instantiate object e.g Car myCar;
public:
Car()
{
brand = "";
model = "";
year = 0;
}
// Parameterized constructor
// Car(string brand, string model, int year) : brand(brand), model(model), year(year) {}
public:
int speed(int maxSpeed); // method/function declaration with parameter
public: // Access specifier
void repair() // method/function definition inside class
{ // Method/function defined inside the class
cout << "Repair car";
}
};
// Constructor definition outside the class
Car::Car(string brand, string model, int year)
{
brand = brand;
model = model;
year = year;
}
// method/function definition outside class with parameter
int Car::speed(int maxSpeed)
{
return maxSpeed;
}