Created
June 20, 2020 11:33
-
-
Save javedbaloch4/392c6a9d4be8a9e4af83963902097559 to your computer and use it in GitHub Desktop.
The C++ Car class to work increase/decrees speed and check the status.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Writting by Javed Ahmed (F2019266402) | |
| #include<iostream> | |
| using namespace std; | |
| class Car { | |
| private: | |
| int yearModel; | |
| string make; | |
| int speed; | |
| public: | |
| Car () { | |
| yearModel = 0; | |
| make = ""; | |
| speed = 0; | |
| } | |
| Car (int yearModel, string make) { | |
| this->yearModel = yearModel; | |
| this->make = make; | |
| this->speed = 0; | |
| } | |
| // Accessors | |
| int getYearModel () { | |
| return this->yearModel; | |
| } | |
| string getMake () { | |
| return this->make; | |
| } | |
| int getSpeed () { | |
| return this->speed; | |
| } | |
| // Other Functions | |
| void accelerate() { | |
| this->speed += 5; | |
| } | |
| void brake() { | |
| this->speed -= 5; | |
| } | |
| }; | |
| int main() { | |
| Car c(2020, "BMW"); | |
| for (int i = 0; i < 5; i++) { | |
| c.accelerate(); | |
| } | |
| cout << "The Current Speed of car is : " << c.getSpeed() << endl; | |
| for (int i = 0; i < 5; i++) { | |
| c.brake(); | |
| } | |
| cout << "The Current Speed of car is : " << c.getSpeed() << endl; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment