Question: 7 . 1 9 LAB * : Program: Fancy car Program Specifications Write a FancyCar class to support basic operations such as drive, add gas,

7.19 LAB*: Program: Fancy car
Program Specifications Write a FancyCar class to support basic operations such as drive, add gas, honk horn, and start engine. FancyCar.h declares the functions necessary to complete the exercise. FancyCar.cpp provides the function stubs. Follow each step to gradually complete all functions in FancyCar.cpp.
Note: This program is designed for incremental development. Complete each step and submit for grading before starting the next step. Only a portion of tests pass after each step but confirm progress. The main() function includes basic function calls. Add statements in main() as functions are completed to support development mode testing.
Step 0. In FancyCar.h, declare private members for miles driven as shown on the odometer (int), gallons of gas in tank (double), miles per gallon or MPG (double), driving capacity (double), and car model (string). Note the provided constant variable indicates the gas tank capacity of 14.0 gallons.
Step 1(2 pts).1) Complete the default constructor by initializing the odometer to five miles, tank is full of gas, miles per gallon is 24.0, and the model is "Old Clunker". 2) Complete the second constructor by passing the model (string) and miles per gallon (double), and initializing all other private members the same as the default constructor. 3) Complete the accessor functions to check the odometer, check the gas guage, get the model, and get the miles per gallon. Submit for grading to confirm 2 tests pass.
Step 2(1 pt). Complete the HonkHorn() function to output the car model. If the car model is:
Honda Civic
the HonkHorn() function outputs:
The Honda Civic says beep beep!
Submit for grading to confirm 3 tests pass.
Step 3(1 pt). Complete the Drive() function. Miles driven should increase by parameter distance, and the amount of gas should decrease by distance / MPG. Variables are only updated if parameter distance is positive. Submit for grading to confirm 4 tests pass.
Step 4(2 pts). Complete the AddGas() function. Increase gas tank by parameter amount only if parameter is positive. Set gas tank to FULL_TANK if too much gas was added. Submit for grading to confirm 5 tests pass.
Step 5(2 pts). Update the Drive() function to identify if the car runs out of gas. If so, the parameter distance will not be achieved, and the gas tank will have 0.0 gallons. Ex: Drive(100) will not be possible with only three gallons of gas and MPG of 20.0. The maximum driving distance is 60 miles with three gallons of gas and MPG of 20.0. Therefore, the odometer will only increase by 60 instead of the requested 100, and the gas tank will have 0.0 gallons (not a negative amount). Submit for grading to confirm 6 tests pass.
Step 6(2 pts).1) Add a boolean private data member in FancyCar.h to indicate if the car engine is on or off. 2) Complete the StartEngine() function to set the boolean variable to true. 3) Complete the StopEngine() function to set the boolean variable to false. 4) Update the constructors to start with the engine off. 5) Update the Drive() function to only update private members if the engine is on, and the engine turns off if the car runs out of gas. 6) Update the AddGas() function to only add gas if the engine is off. Submit for grading to confirm all tests pass.
use the given cod#ifndef FANCY_CAR_H
#define FANCY_CAR_H
#include
#include
using namespace std;
const int FULL_TANK =14;
#include
#include
class FancyCar {
public:
// Default constructor
FancyCar();
// Constructor (string make, double mpg)
FancyCar(string carMake, double carMpg);
// Return car model
string GetModel();
// Return miles per gallon (MPG)
double GetMPG();
// Return miles on odometer
int CheckOdometer();
// Return amount of gas in tank
double CheckGasGauge();
// Honk horn
void HonkHorn();
// Drive car requested miles but check for enough
// gas and check for positive value
void Drive(int milesToDrive);
// Add gas to tank. Check for positive value.
void AddGas(double amtToAdd) ;
// Set boolean variable to true
void StartEngine();
// Set boolean variable to false
void StopEngine();
private:
// TODO: Declare private data members
};
#endife
Main.cpp
#include "FancyCar.h"
#include
int main(){
FancyCar car1;
FancyCar car2("Honda Civic", 30.0);
std::cout << "Car 1 Model: "<< car1.getModel()<<", MPG: "<< car1.getMPG()<< std::endl;
std::cout << "Car 2 Model: "<< car2.getModel()<<", MPG: "<< car2.getMPG()<< std::endl;
car1.HonkHorn();
car2.HonkHorn();
car1.StartEngine();
car1.Drive(50);
std::cout << "Car 1 Odometer: "<< car1.getOdometer()<<", Gas Tank: "<< car1.getGasTank()<< std::endl;
car2.AddGas(10);

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!