prog 8 - } double Odometer::getMiles(){ return milesDriven;...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
#include <iostream> using namespace std; /*----------class Odometer-------------*/ class Odometer{ double milesDriven, fuelEfficent; public: Odometer(); //default constructor that setsmiles and fuel to 0 void resetMiles(); //member function to resetmiles void setFuelEfficent(double amount); // memberfunction to set fuel efficent void addMiles(double miles); //member functionadding miles double getConsumption(); //member function toreturn # of gallons of gas since last reset double getMiles(); //member function gettingmiles double getFuelEfficent(); //member functiongetting fuelefficent }; Odometer::Odometer(){ milesDriven = 0; fuelEfficent = 0; }; void Odometer::resetMiles(){ milesDriven = 0; } void Odometer::setFuelEfficent(double amount){ fuelEfficent = amount; } void Odometer::addMiles(double miles){ milesDriven += miles; } double Odometer::getConsumption(){ return milesDriven / 10; //made up value of 10miles per gallon
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: } double Odometer::getMiles(){ return milesDriven; } double Odometer::getFuelEfficent(){ return fuelEfficent; } int main(){ Odometer test1; //constructor that sets all values to 0 cout << "Initial Odometer: " << endl; cout << "Miles Driven: " << test1.getMiles()<< endl; cout << "Fuel Efficency: " <<test1.getFuelEfficent() << endl << endl; cout << "Adding 54.5 miles to odometer" <<endl; test1.addMiles(54.5); //add 54.5 miles cout << "Miles Driven: " << test1.getMiles()<< endl << endl; cout << "The consumption rate of 54.5 is: " <<endl; //find out the consumption rate cout << "Fuel Efficency: " <<test1.getConsumption() << " miles per gallon(MPG)" <<endl << endl; cout << "Reseting the odometer" << endl; test1.resetMiles(); //reset miles cout << "Miles Driven: " << test1.getMiles()<< endl; return 0; }...
View Full Document

This note was uploaded on 04/02/2012 for the course CSC CSC 175 taught by Professor Kraft during the Winter '12 term at Michigan Flint.

Page1 / 2

prog 8 - } double Odometer::getMiles(){ return milesDriven;...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online