Write a program to define a virtual car. Car has these features: number of wheels, max speed, current speed, isMoving, remainingFuel, distanceTravelled. The car can move when the programmer decides to accelerate. With each acceleration current speed increases by 10. Fuel decreases depending on the speed of the car and follows this formula: fuel= fuel-(speed/2). Your program should display “Out of fuel” when there is no remaining fuel. Fuel starts form 100. Use a constructor to initialize the car object.
Write appropriate class with member variables and functions. Also update status of variables when applicable. Variables:
number of wheels, max speed, current speed, isMoving, remainingFuel, distanceTravelled.
Functions:
Void Accelerate() Void fuelCheck()
Sample code and output: //Incomplete code
class car {
.......
void accelerate(); Void fuelCheck();
};
int main() {
......
...... car1.accelerate(); car1.accelerate(); car1.accelerate();
car1.accelerate(); car1.accelerate(); car1.accelerate();
return 0;
} Output:
Out of fuel!!!
After six acceleration fuel should run out.
#include<iostream>
using namespace std;
//class Car
class Car
{ //data members
private:
int
now,max_speed,curr_speed;
bool isMoving;
double
remainingFuel,distanceTravelled;
public:
//member functions
void Accelerate();
void fuelCheck();
Car(); //constructor
};
//initialize the data members
Car :: Car()
{
now=4;
max_speed=160;
curr_speed=0;
isMoving=false;
remainingFuel=100;
distanceTravelled=0;
}
//accelerate method
void Car :: Accelerate()
{
//update the status of car
isMoving = true;
//increase the speed
curr_speed+=10;
//display the status of car
if(curr_speed <=80)
cout<<endl<<"Economic Speed,Keep it
up";
else
if(curr_speed<=120)
cout<<endl<<" Manageable Speed,
Drive Carefully";
else
if(curr_speed>120 &&
curr_speed<160)
cout<<endl<<"Over Speed, Decrease
Speed";
//set the distance travelled
distanceTravelled = distanceTravelled +
curr_speed;
//display the details of status, STATUS IS 1 for
moving
cout<<endl<<"Status of Moving
"<<isMoving;
cout<<endl<<"Current Speed
"<<curr_speed;
cout<<endl<<"Distance Covered
"<<distanceTravelled;
//update the fuel
remainingFuel=remainingFuel -
(double)curr_speed/2;
//call to fuelCheck()
fuelCheck();
}
//defination of fuelCheck()
void Car :: fuelCheck()
{
//out of fuel condition
if(remainingFuel<=0)
{
cout<<endl<<"Out of Fuel!!!";
exit(0);
}
else
{ //display the fuel amount
cout<<endl<<"Remaining Fuel
"<<remainingFuel;
if(remainingFuel<=30)
cout<<endl<<"Fuel level
decreased";
else
if(remainingFuel>30)
cout<<endl<<"Sufficient
Fuel.";
}
}
int main()
{
//char ch;
//declarethe object of VirtualCar
Car car1;
//loop to accelerate the car
/* do
{
cout<<endl<<"Do you want to
accelerate the car[Y/N]";
cin>>ch;
car1.Accelerate();
}while(ch=='y'|| ch=='Y');*/
car1.Accelerate();
car1.Accelerate();
car1.Accelerate();
car1.Accelerate();
car1.Accelerate();
car1.Accelerate();
}
OUTPUT
NOTE: YOU MAY USE DO...WHILE LOOP instead of calling Accelerate() six times..
Write a program to define a virtual car. Car has these features: number of wheels, max speed, current speed, isMoving, remainingFuel, distanceTravelled. The car can move when the programmer decides...
C++ Program 1a. Purpose Practice the creation and use of a Class 1b. Procedure Write a class named Car that has the following member variables: year. An int that holds the car’s model year. make. A string object that holds the make of the car. speed. An int that holds the car’s current speed. In addition, the class should have the following member functions. Constructor. The constructor should accept the car’s year and make as arguments and assign these values...
Car Class Background: Write a class named Car that will be used to store information and control the acceleration and brake of a car. Functionality: 1. Write a class named "Car” that has the following member variables: • year Model - an int that holds the car's year model • make-A string that holds the make of the car • speed - an int that holds the car's current speed 2. In addition the class should have the following member...
Java Program Write a class named Car that has the following fields: yearModel- The yearModel field is an int that holds the car’s year model. make- The make field is a String object that holds the make of the car, such as “Ford”, “Chevrolet”, etc. speed- This speed field is an int that holds the car’s current speed. In addition, the class should have the following methods: Constructor- The constructor should accept the car’s year model and make as arguments....
(C++)This is the problem that I'm supposed to write a program for: This is the layout that we are supposed to fill out for the project: If anything is unclear, comment and I'll try to clarify. Thank you! Objective Reading Dala Files Project This is a variation of ng challenge 133 de Write a class named Car that has the following pelvate member variables. model Year An ie car's uodd year. make A string that bolds the make of the...
cpp Lab Quiz 2 Time Slot: Mon 1-2 PM Deadline: 05/13/2019 2:00 PM Submission: Email Subject: CSC 102 CC3/CC4 LabQuiz 2TS 2 FileType: cpp Write a program to define a music player. Music player has these features: isPlaying, isStopped, currentSongTitle, nextSong Title, currentSongLength. Programmer can play or stop a song. You can also choose to skip to the next song. Songs are stored in array of strings. When you choose to move to the next song, currentSong Title and nextSongTitle...
java Write a class named Car that has the following fields: • yearModel: The yearModel field is an int that holds the car's year model. • make: The make field is a String object that holds the make of the car. • speed: The speed field is an int that holds the car's current speed. In addition, the class should have the following methods: • Constructor: The constructor should accept the car's year model and make as arguments. These values...
Need help doing program In bold is problem E2 #include<iostream> #include<string> #include<vector> using namespace std; //Car class //Defined enum here enum Kind{business,maintenance,other,box,tank,flat,otherFreight,chair,seater,otherPassenger}; //Defined array of strings string KIND_ARRAY[]={"business","maintenance","other,box","tank,flat","otherFreight","chair","seater","otherPassenger"}; class Car { private: string reportingMark; int carNumber; Kind kind; //changed to Kind bool loaded; string destination; public: //Defined setKind function Kind setKind(string knd) { for(int i=0;i<8;i++) //repeat upto 8 kinds { if(knd.compare(KIND_ARRAY[i])==0) //if matched in Array kind=(Kind)i; //setup that kind } return kind; } //Default constructor Car() { } //Parameterized constructor...
Codes: (car.h ; car.cpp ; carDemo.cpp) /* ----------------------- Car ----------------------- - make: string - year : int ----------------------- + Car() + setMake(m: string) : void + getMake() : string + setYear(y: int) : void + getYear() : int ---------------------- */ #ifndef CAR_H #define CAR_H #include <iostream> using namespace std; class Car { private: string make; int year; public: Car(); Car(string); Car(int); Car(string, int); void setMake (string); string getMake() {return make;} void setYear (int); int getYear() {return year;} }; #endif #include...
Write a program to compute miles per gallon of a car, over a long trip. The car begins the trip with a full tank, and each fuel stop along the way fills the tank again. You will not do any math, arithmetic, or computations in the main() function. All output will be displayed from the main() function. Start the program by asking the user for the starting odometer reading. All odometer readings will be in whole miles only. The fuel...
Hello, please solve this problem for object oriented programming in C++ program language. I have final tomorrow so it will be very helpful. thank you. PROBLEM 1: application that simulates the highway Create an In order to solve above mentioned requirements, it is necessary to implement several classes: 1. Class Vehicle contains information about the vehicles that drive on the highway. Each vehicle has information about its a Type (can be one of these: Motorcycle, Car, Truck) b. License number...