-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOOPs-Constructor.cpp
68 lines (49 loc) · 1.34 KB
/
OOPs-Constructor.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# include<iostream>
using namespace std;
class Car{
float price;
public:
string Brand;
string Model;
int year;
Car(float price, string brand, string model, int &year){ // constructor with parameters
this->price = price;
this->Brand = brand;
this->Model = model;
this->year = year;
}
int * printInfo(){
cout<<"Brand = "<<Brand<<endl;
cout<<"Model = "<<Model<<endl;
cout<<"Year = "<<year<<endl;
cout<<"Price = "<<price<<endl;
return 0;
}
// Setter to set the price of a car
void setPrice(float price){
this->price = price;
}
// Getter to print the price of a car
int getPrice(){
return price;
}
};
int main(){
int *year;
string brand, model;
float price;
cout<<"Enter the Brand of the car1 : "<<endl;
cin>>brand;
cout<<"Enter the Model of the car : "<<endl;
cin>>model;
cout<<"Enter the Year of the car : "<<endl;
cin>>*year;
cout<<"Enter the Price of the car : "<<endl;
cin>>price;
Car * car1 = new Car(price, brand, model, *year);
*car1->printInfo();
car1->setPrice(price);
cout<<"The price of the car is = "<<car1->getPrice();
delete car1;
return 0;
}