car_oop.cpp
· 581 B · C++
Raw
#include <iostream>
using namespace std;
class Car {
private:
string name;
string numberPlate;
public:
void setDetails(string name, string numberPlate) {
this->name = name;
this->numberPlate = numberPlate;
}
string getName() { return name; }
string getNumberPlate() { return numberPlate; }
void display() {
cout << "Car Name: " << name << endl;
cout << "Number Plate: " << numberPlate << endl;
}
};
int main(void){
Car c1;
c1.setDetails("Aston Martin", "MH10-0001");
c1.display();
return 0;
}
| 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 | } |