CSCFINAL

CSCFINAL - // tank, whichever is smaller void drive(double...

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

View Full Document Right Arrow Icon
/************************/ /* Brian Apple */ /* Assignment 0 */ /* CSC 1254 */ /* October 5 */ /************************/ #include<iostream> using namespace std; class Car { private: double fuel_efficiency; //mileage in miles/gallon double fuel_capacity; // capacity of fuel in gallons double fuel_in_tank; //current fuel in tank in gallons public: Car(double efficiency, double capacity); //all cars start with empty tanks double get_fuel() const; //returns current fuel level void add_fuel(double gallons); //increases fuel in tank // either by the gallons specified // or by the amount which fills the
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: // tank, whichever is smaller void drive(double miles); //reduces fuel in the tank }; Car::Car(double efficiency, double capacity) { fuel_efficiency = efficiency; fuel_capacity = capacity; } void Car::add_fuel(double gallons) { if(gallons < (fuel_capacity - fuel_in_tank)) fuel_in_tank = gallons + fuel_in_tank; else fuel_in_tank = (fuel_capacity - fuel_in_tank) + fuel_in_tank; } void Car::drive(double miles) { fuel_in_tank = fuel_in_tank - (miles * (1/fuel_efficiency)); } double Car::get_fuel() const { return fuel_in_tank; } int main() { Car c1(15.0, 20.0), c2(29.5, 30.0); c2.add_fuel(10.0); c2.drive(82.5); c1.add_fuel(25.0); &n...
View Full Document

This note was uploaded on 10/02/2011 for the course EE 2720 taught by Professor Desouza during the Fall '08 term at LSU.

Page1 / 2

CSCFINAL - // tank, whichever is smaller void drive(double...

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