1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
olchik [2.2K]
2 years ago
11

Your solution should for this assignment should consist of five (5)files:============================================== FuelGaug

e.h (class specification file)FuelGauge.cpp (class implementation file)Odometer.h (class specification file)Odometer.cpp (class implementation file)200_assign6.cpp (application program)=================================================★ For your sixth programming assignment, you will be implementing a program that uses two(2)classes that work together to simulate a car’s fuel gauge and odometer. The classes you will design are: TheFuelGaugeClass: This class will simulate a fuel gauge. Its responsibilities are↘To know the car’s current amount of fuel, in gallons.↘To report the car’s current amount of fuel, in gallons.↘To be able to increment the amount of fuel by 1 gallon. This simulates putting fuel in the car. (The car can hold a maximum of 15 gallons)↘To be able to decrement the amount of fuel by 1 gallon, if the amount of fuel is greater than 0 gallons. This simulates burning fuel as the car runs.TheOdometerClass: This class will simulate the car’s odometer. Its responsibilities are:↘To know the car’s current mileage.↘To report the car’s current mileage.↘To be able to increment the current mileage by 1 mile. The maximum mileage the odometer can store is 999,999 miles. When this amount is execeeded, the odometer resets the current mileage to 0.↘To be able to work with aFuelGaugeobject. It should decrease theFuelGaugeobject’s current amount of fuel by 1 gallon for every 24 miles traveled. (The car’s fuel economy is 24 miles per gallon)The FuelGaugeclass should have at least one constructor, and the appropriate member functions to get the number of gallons, increment the number of gallons, and decrement the number of gallons.★ The odometer class should have at least one constructor, and the appropriate member functions to get the mileage and increment the mileage (unfortunately you cannot decrement the mileage!).★ In the odometer class, you can have a member variable that is a pointer to a FuelGauge object. This is how you can establish a relationship between the two classes that allow them to work together. For every mile the car is driven, the odometer is increased by 1, and for every 24 miles the car is driven, the number of gallons is reduced by one.★ So in the Odometer class, one of the private member variables should be of type fuel gauge* (pointer to a FuelGauge object).★ Demonstrate the two classes by creating instances(objects)of each. Simulate filling the car up with fuel, and then run a loop that increments the odometer until the car runs out of fuel. During each loop iteration, print the car’s current mileage and amount of fuel.
Computers and Technology
1 answer:
olga nikolaevna [1]2 years ago
6 0

Answer: provided in the explanation section

Explanation:

This was implemented in C++

Filename: Car.cpp

#include <iostream>

#include <iomanip>

#include <cstdlib>

#include "Odometer.h"

using namespace std;

int main()

{

  char response;

  do

  {

      FuelGuage* myFuel = new FuelGuage(6);

      int fuelLevel = myFuel->getFuel();

      cout << "Car gas level: " << fuelLevel << endl;

      cout << "Car is filling up" << endl;

      while(myFuel->getFuel() < 15)

      {

          myFuel->addFuel();

      }

      Odometer* car = new Odometer(myFuel, 999990);

      cout << "Car gas level: " << car->getFuelGuage()->getFuel() << endl;

      cout << "Car is off!" << endl;

      cout << "--------------------------" << endl;

      while(car->getFuelGuage()->getFuel() > 0)

      {

          car->addMile();

          int miles = car->getMileage();

          cout << "Mileage: " << setw(6) << miles << ", Fuel Level: " << car->getFuelGuage()->getFuel() << endl;

          cout<<"--------------------------------------------------------------"<<endl;

      }

      delete myFuel;

      delete car;

      cout << "Would you like to run the car again(Y/N)? ";

      cin >> response;

      system("cls||clear");

  } while(toupper(response) != 'N');

  return 0;

}

Filename: FuelGuage.cpp

#include "FuelGuage.h"

FuelGuage::FuelGuage()

{

  init();

}

FuelGuage::FuelGuage(int fuel)

{

  init();

  this->fuel = fuel;

}

FuelGuage::FuelGuage(const FuelGuage& copy)

{

  this->fuel = copy.fuel;

}

void FuelGuage::init()

{

  this->fuel = 0;

}

int FuelGuage::getFuel()

{

  return fuel;

}

void FuelGuage::addFuel()

{

  fuel++;

}

void FuelGuage::burnFuel()

{

  fuel--;

}

Filename:FuelGuage.h

#ifndef FUEL_GUAGE_H

#define FUEL_GUAGE_H

class FuelGuage

{

private:

  int fuel;

  void init();

public:

  FuelGuage();

  FuelGuage(int fuel);

  FuelGuage(const FuelGuage& copy);

  int getFuel();

  void addFuel();

  void burnFuel();

};

#endif

Filename : Odometer.cpp

#include "Odometer.h"

Odometer::Odometer()

{

  init();

}

Odometer::Odometer(FuelGuage* inFuel, int inMileage)

{

  init();

  this->fuel = new FuelGuage(*inFuel);

  this->mileage = inMileage;

  this->milesSinceAddingFuel = 0;

}

void Odometer::init()

{

  fuel = new FuelGuage();

  mileage = 0;

  milesSinceAddingFuel = 0;

}

FuelGuage* Odometer::getFuelGuage()

{

  return fuel;

}

int Odometer::getMileage()

{

  return mileage;

}

void Odometer::addMile()

{

  if(mileage < 999999)

  {

      mileage++;

      milesSinceAddingFuel++;

  }

  else

  {

      mileage = 0;

      milesSinceAddingFuel++;

  }

  if((milesSinceAddingFuel % 24) == 0)

  {

      fuel->burnFuel();

  }

}

void Odometer::resetMiles()

{

  milesSinceAddingFuel = 0;

}

Odometer::~Odometer()

{

  delete fuel;

}

Filename: Odometer.h

#ifndef ODOMETER_H

#define ODOMETER_H

#include "FuelGuage.h"

class Odometer

{

private:

  void init();

  int mileage;

  int milesSinceAddingFuel;

  FuelGuage* fuel;

public:

  Odometer();

  Odometer(FuelGuage* inFuel, int inMileage);

  FuelGuage* getFuelGuage();

  int getMileage();

  void addMile();

  void resetMiles();

  ~Odometer();

};

#endif

You might be interested in
There are two kinds of emotions: positive and negative. True False
fgiga [73]

Answer:

False

Explanation:

There are many emotions the human brain can experience

6 0
2 years ago
Read 2 more answers
Methods used to change variables are called ______. equals accessors toString void mutators
Sindrei [870]
Look this up on Quizlet. Besure to check the question and the answers carefully by using "define + the vocabulary word" you think answers the question.

Here is the exact site: just copy it and search and click...

<span>AP Comp Sci Chapter 5</span>
6 0
2 years ago
How many times should the start function be defined in a program?
tatyana61 [14]

Answer:

0 1 2 However many you like

✓ I think its 2x they will start to define the program

4 0
2 years ago
You decide to use a packet sniffer to identify the type of traffic sent to a router. You run the packet sniffing software on a d
ycow [4]

Answer:

Promiscuous mode

Explanation:

You decide to use a packet sniffer to identify the type of traffic sent to a router. You run the packet sniffing software on a device connected to the same hub that is connected to the router. When you run the software, you only see frames addresse…

✓ Promiscuous mode

7 0
2 years ago
Which of the following solutions should an administrator use to reduce the risk from an unknown vulnerability in a third-party s
ser-zykov [4K]

Answer:

A. Sandboxing

Explanation:

The best solution to apply for this task would be Sandboxing. This is a software management strategy that isolates applications from critical system resources and other programs. In doing so you effectively add a secondary security layer on top of the application in order to prevent any and all malware from entering and damaging your overall system. Thus effectively reducing the risk.

4 0
2 years ago
Other questions:
  • In one sentences describe how to change your home page
    10·1 answer
  • You are adding a new 500 GB hard drive to your computer. The hard drive must be formatted with a file system to organize files i
    8·1 answer
  • In Modern operating system, the __ feature has dramatically improved user productivity.
    11·1 answer
  • Computer design replaced ______________
    6·1 answer
  • Which magazine introduced the first microcomputer kit for the mits altair in its january 1975 issue?
    8·1 answer
  • Of the various trends affecting the advertising and promotion industry, _____________ offers an opportunity for advertisers to d
    9·1 answer
  • PLEASE HELP ME I WILL GIVE BRAINIEST AND 40 POINTSPython Project Worksheet
    12·1 answer
  • Write 3 things that can't be done without technology.
    14·2 answers
  • What is the<br>Way to<br>keep the tool<br>Screw​
    6·1 answer
  • ________ technologies are technologies that enable the incremental improvement of products and services.
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!