Answer to Question #271331 in C++ for Sam

Question #271331

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


1
Expert's answer
2021-11-25T07:05:05-0500
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS