I keep getting errors on the following programming challenge, any help would be
ID: 3557568 • Letter: I
Question
I keep getting errors on the following programming challenge, any help would be greatly appreciated. Thanks
Car Instrument Simulator:
For this assignment you will design a set of classes that work together to simulate a car's fuel gauge and odometer. The classes you will design are:
* The FuelGauge Class: 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.
* The Odometer Class: 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 exceeded, the odometer resets the current mileage to 0.
--To be able to work with a FuelGauge object. It should decrease the FuelGauge object s current amount of fuel by 1 gallon for every 24 miles traveled. (The car's fuel economy is 24 miles per gallon.)
Demonstrate the classes by creating instances of each. Simulate lling 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.
And here are my code so far:
//Odometer.h:
#pragma once
#include
#include
#include
#include "FuelGauge.h"
class Odometer
{
private:
int currentMileage;
FuelGauge *fuelG;
public:
Odometer(int miles,FuelGauge *f){
currentMileage = miles;
fuelG= f;
}
int getCurrentMileage(){
return currentMileage;
}
void incrementcurrentMileage(){
if(currentMileage < 999999 )
currentMileage++;
else currentMileage = 0;
}
void decrementcurrentMileage(){
if (currentMileage > 24 )
currentMileage--;
(*fuelG).decrementFuelTank();
}
};
****************************************
//Odometer.cpp:
#include "odometer.h"
Odometer::Odometer()
{
//ctor
}
Odometer::~Odometer()
{
//dtor
}
**********************************************
//FuelGauge.h:
#pragma once
#include
#include
#include
using namespace std;
class FuelGauge
{
private:
int currentAmountOfFuel;
public:
FuelGauge(int gallons){
currentAmountOfFuel=gallons;
}
//FuelGauge();
int getCurrentAmountOfFuel()
{
return currentAmountOfFuel;
}
void incrementFuelTank(){
if (currentAmountOfFuel< 15 )
currentAmountOfFuel++;
}
void decrementFuelTank()
{
if(currentAmountOfFuel>0)
currentAmountOfFuel--;
}
};
****************************************
//FuelGauge.cpp:
#include "fuelgauge.h"
FuelGauge::FuelGauge()
{
//ctor
}
FuelGauge::~FuelGauge()
{
//dtor
}
******************************************
//main.cpp:
#include
#include
#include
#include "FuelGauge.h"
#include "Odometer.h"
using namespace std;
int main()
{
FuelGauge fuelG(15);
Odometer odm(0,&fuelG);
while (fuelG.getCurrentAmountOfFuel() > 0)
{
odm.incrementcurrentMileage();
cout<<"Mileage: "< cout<<"Fuel level"<< fuelG.getCurrentAmountOfFuel()<<" gallons"<
}
return 0;
}
**************************************************************
I keep getting these errors:
fuelgauge.cpp error: prototype for 'FuelGauge::FuelGauge()' does not match any in class 'FuelGauge'|
fuelgauge.cpp error: definition of implicitly-declared 'FuelGauge::~FuelGauge()'
fuelgauge.h error: FuelGauge::FuelGauge(int)|
fuelgauge.h error: candidates are: FuelGauge::FuelGauge(const FuelGauge&)|
Explanation / Answer
1.
Please compile with g++ -Wall -H -c Employee.cpp and be sure that the included Employee.h is indeed the file you think it is. It is more likely a problem with your setup than anything else. Check that your directories and files have appropriate permissions (readable files, etc....); it is very unlikely that "your" g++has such weird problems... Much more likely that your setup, or way of using g++, is wrong....
Please compile with g++ -Wall -H -c Employee.cpp and be sure that the included Employee.h is indeed the file you think it is. It is more likely a problem with your setup than anything else. Check that your directories and files have appropriate permissions (readable files, etc....); it is very unlikely that "your" g++has such weird problems... Much more likely that your setup, or way of using g++, is wrong....