For my class, I was ponderng adding a deconstructor. But would that just be plain redundant? I have no objects to destroy here, What do you think?
Code:
#include <iostream>
using std::cout;
using std::endl;
// create the class
class Vehicle // class name
{
public:
int passengers; // number of passengers
int fuelcap; // fuel capacity in gallons
int mpg; // fuel used ( miles per gallon )
// this is a constructor for Vehicle
Vehicle ( int p, int f, int m );
int range(); // compute and return the range
}; // end class vehicle
// implement the Vehicle constructor
Vehicle::Vehicle( int p, int f, int m )
{
passengers = p;
fuelcap = f;
mpg = m;
}
// implement the range() member function
int Vehicle::range()
{
return mpg * fuelcap;
}
// main function
int _tmain(int argc, _TCHAR* argv[])
{
// pass values to Vehicle constructor
Vehicle miniVan ( 7, 16, 21 );
Vehicle sportsCar ( 2, 14, 12 );
int range; // for first object
int range2; // for second object
// compute the range assuming a full tank of gas
// for miniVan and sportsCar
range = miniVan.range();
range2 = sportsCar.range();
// output results to screen
cout << "A mini van can carry " << miniVan.passengers << " with a range of " << range << endl;
cout << "\nA sports car can carry " << sportsCar.passengers << " with a range of " << range2 << endl;
getchar(); // freeze output
return 0; // indicates sucsessful termination
}