c++ program Create a class called CAR. Have several variables - use necessary va
ID: 3787942 • Letter: C
Question
c++ program
Create a class called CAR.
Have several variables - use necessary variables that store
gas level, amount of gas, gear car is in, car in motion.. etc
Have functions that do:
Check the battery level
Check the gas level
Turn right, Left,
Go Straight
Put car in forward gear
Put car in backward gear
Start Car (function should check if batter is good and you have gas)
Example: If good then print message "car started", if not "print car not started because ...."
Park Car
Move car # number of feet. (Car uses 1 unit of gas per 50 feet)
(subtract 1 unit of gas per 50 feet traveled)
As the car moves (determine if it needs gas)
Note: as you instruct the computer to perform a command in the main function, have your
function print out messages for each action.
Have a dashboard/Interface in which the user can make interactive/Live choices on how to drive the car.
Explanation / Answer
#include<iostream>
using namespace std;
class car
{
char gaslvl;//gaslevel can take h or l corresponding to high or low
int amtgas;//amount of gas can be between 0 and 30 units
char btlvl;//battery level can be good or bad
char gear; //gear can take f(front) or b(back)
int feet;
public:
car()
{
gaslvl='l';
amtgas=0;
btlvl='g';
}
car(char gl,int ag,char bl)
{
gaslvl=gl;
amtgas=ag;
btlvl=bl;
}
void startcar()//char bt,int amt)
{
//int c=0;
//btlvl=bt;
//amtgas=amt;
if(btlvl=='g')
{
//c=1;
if(amtgas>0)
cout<<"Car started ";
else
cout<<"Car could be started as amount of gas is low ";
}
else
{
cout<<"Car could not started because battery is not good ";
}
}
void movecar(int f)
{
feet=f;
while(amtgas<=1)
{
amtgas=amtgas-feet/50;
cout<<"car is moving";
}
cout<<"Gas is low n u need to fill gas ";
}
void parkcar()
{
cout<<"car is parked ";
}
};
int main()
{
int f;
car c1('h',20,'g');
c1.startcar();
cout<<"enter feet to move:";
cin>>f;
c1.movecar(f);
c1.parkcar();
return 1;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.