|
#include "stdafx.h"
#include <iostream>
using namespace std;
class Vehicle {
public:
Vehicle (double x)
{
cost = x;
}
Vehicle ()
{
cost = 0;
}
~ Vehicle () {}
virtual void show ()
{
cout << "I am a vehicle.";
}
virtual void costs ()
{
cout << "Cost is" << cost;
}
private:
double cost;
};
class Car: public Vehicle {
public:
Car (double x)
{
cost = x;
}
~ Car () {}
void show ()
{
cout << "I am a car.";
}
void costs ()
{
cout << "Cost is" << cost;
}
private:
double cost;
};
class Truck: public Vehicle {
public:
Truck (double x)
{
cost = x;
}
~ Truck () {}
void show ()
{
cout << "I am a truck.";
}
void costs ()
{
cout << "Cost is" << cost;
}
private:
double cost;
};
void callcost (Vehicle&);
int main ()
{
Vehicle vehi (1.5);
callcost (vehi);
Car c (3.8);
callcost (c);
Truck tr (5.8);
callcost (tr);
return 0;
}
void callcost (Vehicle&vehi)
{
vehi.show ();
vehi.costs ();
} |
|