Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Why is my C++ project not running correctly? // Here's my main driver cpp file #include #include odometer.h using namespace std; int main() { odometer

Why is my C++ project not running correctly?

// Here's my main driver cpp file

#include

#include "odometer.h"

using namespace std;

int main()

{

odometer o;

o.setMilesAndGallons(100,10);

cout<< "Fuel Efficiency :"<

cout<<"Odometer Reading : "<

o.resetToZero();

cout<<"Odometer Reading After Reset : "<

o.setMilesAndGallons(200,25);

cout<< "Fuel Efficiency :"<

cout<<"Odometer Reading : "<

cout<<"Odometer Reading After Reset : "<

o.setMilesAndGallons(320,30);

cout<< "Fuel Efficiency :"<

cout<<"Odometer Reading : "<

o.resetToZero();

cout<<"Odometer Reading After Reset : "<

return 0;

}

// Here's my odometer.cpp file

#include

#include "odometer.h"

using namespace std;

odometer::odometer()

{

totalMilesDriven=0;

gallonsUsed=0;

}

//mutator method to set miles and gallons

void odometer::setMilesAndGallons(long totalMilesDriven, long gallonsUsed)

{

totalMilesDriven= totalMilesDriven;

gallonsUsed= gallonsUsed;

}

//reset the miles and gallons to zero

void odometer::resetToZero()

{

gallonsUsed=0;

totalMilesDriven=0;

}

//mutator function to reset the gallons

void odometer::resetGallons()

{

gallonsUsed=0;

}

//method to check the fuel efficiency

double odometer::fuelEff()

{

return (double)(totalMilesDriven/gallonsUsed);

}

// method to get odometer reading

long odometer::odometerReading()

{

return totalMilesDriven;

}

// Here's my odometer.h header file

#include

#ifndef ODOMETER_H

#define ODOMETER_H

class odometer

{

//private member variables for storing miles and gallons

private:

long totalMilesDriven;

long gallonsUsed;

public:

//using default constructor

odometer();

//mutator method to set miles and gallons

void setMilesAndGallons(long totalMilesDriven, long gallonsUsed);

//reset the miles and gallons to zero

void resetToZero();

//mutator function to reset the gallons

void resetGallons();

//method to check the fuel efficiency

double fuelEff();

// method to get odometer reading

long odometerReading();

};

#endif // ODOMETER_H

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

How To Build A Million Dollar Database

Authors: Michelle Bergquist

1st Edition

0615246842, 978-0615246840

More Books

Students also viewed these Databases questions