#include <iostream>
#include <cstring>
#include <cctype>
using namespace std;
class Car
{
private:
int YearModel;
int Speed;
string Make;
public:
Car(int, string, int);
string getMake();
int getModel();
int getSpeed();
void Accelerate();
void Brake();
void displayMenu();
};
Car::Car(int YearofModel, string Makeby, int Spd)
{
YearModel = YearofModel;
Make = Makeby;
Speed = Spd;
}
//To get who makes the car.
string Car::getMake()
{
return Make;
}
//To get the year of the car.
int Car::getModel()
{
return YearModel;
}
//To holds the car actual speed.
int Car::getSpeed()
{
return Speed;
}
//To increase speed by 5.
void Car::Accelerate()
{
Speed = Speed + 5;
}
//To drop the speed of the car by 5.
void Car::Brake()
{
Speed = Speed - 5;
}
void displayMenu()
{
cout <<"\n Menu\n";
cout << "----------------------------\n";
cout << "A)Accelerate the Car\n";
cout << "B)Push the Brake on the Car\n";
cout << "C)Exit the program\n\n";
cout << "Enter your choice: ";
}
int main()
{
int Speed = 0; //Start Cars speed at zero.
char choice; //Menu selection
cout << "The speed of the SUV is set to: " << Speed <<endl;
Car first( 2007, "GMC", Speed);
//Display the menu and get a valid selection
do
{
displayMenu();
cin >> choice;
while(toupper(choice) < 'A' || toupper(choice) > 'C')
{
cout << "Please make a choice of A or B or C:";
cin >> choice;
}
//Process the user's menu selection
{
{
switch (choice)
{
case 'a':
case 'A': cout << "You are accelerating the car. ";
cout << Accelerate(first) << endl;
break;
case 'b':
case 'B': cout << "You have choosen to push the brake.";
cout << Brake(first) << endl;
break;
}
}
}while (toupper(choice) != 'C');
return 0;
}
akase2010 -1 Newbie Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
akase2010 -1 Newbie Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
papanyquiL 45 Junior Poster
akase2010 -1 Newbie Poster
Saith 74 Junior Poster
akase2010 -1 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.