All pastes #413926 Raw Edit

Untitled

public text v1 · immutable
#413926 ·published 2007-03-28 19:39 UTC
rendered paste body
#include <iostream>  
#include <iomanip>  
using namespace std;

//------------------------------------------------------------------
// This is the BASE CLASS.
//------------------------------------------------------------------
class Vehicle
{
  protected:
    int wheels, horsepower, weight;
    double fuel_tank_capacity;
  public:
    int    get_wheels ()        const { return wheels;             }
    int    get_horsepower ()    const { return horsepower;         }
    int    get_weight ()        const { return weight;             }
    double get_fuel_capacity () const { return fuel_tank_capacity; }

    void set_wheels        (int    w  ) { wheels             = w;   }
    void set_horsepower    (int    h  ) { horsepower         = h;   }
    void set_weight        (int    www) { weight             = www; }
    void set_fuel_capacity (double ftc) { fuel_tank_capacity = ftc; }

  friend istream& operator >> (istream&, Vehicle&);
  friend ostream& operator << (ostream&, const Vehicle&);
};

ostream& operator << (ostream& output , const Vehicle& v)
{
  output << "This vehicle has " << v.wheels << " wheels and a "
         << v.horsepower << " horsepower engine." << endl
         << "Its gross vehicle weight is " << v.weight << " pounds, and" << endl
         << "its fuel tank capacity is " << v.fuel_tank_capacity
         << " gallons." << endl;
  return output;
}

//------------------------------------------------------------------
// This is where your code will be inserted.  Your code should
// include enough to make the program run as required.
//------------------------------------------------------------------
#include "hw10.h"

//------------------------------------------------------------------
// This is the driving program.  Note that the classes "Automobile",
// "Pickup_Truck", and "Bus" inherit the base class "Vehicle".
// The terms "static_cast<Vehicle>(A)" etc. print out the base
// class parts of the objects A, B, and C, respectively, using the
// base class output (<<) operator.
//------------------------------------------------------------------
int main ()
{
  Automobile A;
  Pickup_Truck B;
  Bus C;

  // Set formatting of floating point numbers.
  cout << setiosflags (ios::fixed | ios::showpoint) << setprecision(2);

  cin >> A;
  cout << static_cast<Vehicle>(A) << A;

  cin >> B;
  cout << static_cast<Vehicle>(B) << B;

  cin >> C;
  cout << static_cast<Vehicle>(C) << C;

  return 0;
}