Define a class called vehicle that will store two items of information about a vehicle: The fuel capacity and the fuel consumption in kilometers per litre and prototype of four functions a default constructor and a parameterized constructor that initializes the Taxi fuel capacity to 20 litres and Taxi consumption to 10 kpl , a destructor and a friend function that uses the values from the constructors to calculates the taxi range (the maximum distance it would travel if its fuel tank is full without refueling) NB. Show only the prototype of the function in the class
#include <iostream>
using namespace std;
class Vehicle{
float fuelCapacity, fuelConsumption;
public:
Vehicle(){
fuelCapacity = 20;
fuelConsumption = 10;
}
Vehicle(float cap, float cons){
fuelCapacity = cap;
fuelConsumption = cons;
}
~Vehicle(){}
friend float calcRange(Vehicle);
};
float calcRange(Vehicle v){
return v.fuelCapacity * v.fuelConsumption;
}
int main(){
Vehicle v;
cout<<"Max Distance without refueling: "<<calcRange(v)<<"km\n";
return 0;
}
Comments
Leave a comment