k revised this gist 1 month ago. Go to revision
1 file changed, 29 insertions
car_oop.cpp(file created)
| @@ -0,0 +1,29 @@ | |||
| 1 | + | #include <iostream> | |
| 2 | + | using namespace std; | |
| 3 | + | ||
| 4 | + | class Car { | |
| 5 | + | private: | |
| 6 | + | string name; | |
| 7 | + | string numberPlate; | |
| 8 | + | ||
| 9 | + | public: | |
| 10 | + | void setDetails(string name, string numberPlate) { | |
| 11 | + | this->name = name; | |
| 12 | + | this->numberPlate = numberPlate; | |
| 13 | + | } | |
| 14 | + | ||
| 15 | + | string getName() { return name; } | |
| 16 | + | string getNumberPlate() { return numberPlate; } | |
| 17 | + | ||
| 18 | + | void display() { | |
| 19 | + | cout << "Car Name: " << name << endl; | |
| 20 | + | cout << "Number Plate: " << numberPlate << endl; | |
| 21 | + | } | |
| 22 | + | }; | |
| 23 | + | ||
| 24 | + | int main(void){ | |
| 25 | + | Car c1; | |
| 26 | + | c1.setDetails("Aston Martin", "MH10-0001"); | |
| 27 | + | c1.display(); | |
| 28 | + | return 0; | |
| 29 | + | } | |
Newer
Older