Design, edit, compile, and execute a C++ application. This application will be a
ID: 3662732 • Letter: D
Question
Design, edit, compile, and execute a C++ application. This application will be a project that should have at least three files:
vehicle.h: This file contains the vehicle class definition.
vehicle.cpp: This file contains vehicle class member-function definitions.
vehicleTest.cpp: This file tests vector class.
Design a Vehicle class that contains the following properties of motor vehicles: fuel tank capacity, average fuel consumption per 100 km, and the distance a vehicle can travel on a full tank. The Vehicle class should be designed as an abstract base class from which the Car and Truck classes are derived. The derived classes should have the following member functions:
A function that obtains data for a vehicle from the user (the fuel tank capacity and average fuel consumption)
A function that computes and returns how many times a vehicle can travel has to be refueled to travel a given distance.
A print function that shows the fuel tank capacity, the average fuel consumption, and how many times a vehicle must be refueled to travel given a distance.
These functions should be defined as pure virtual functions in the Vehicle class and redefined by the derived classes. Design the main( ) function that instantiates a pointer of Vehicle type, and Car and Truck object, respectively. The pointer should be used to invoke appropriate member functions to get and process data for a car and truck. The program should output how many times each vehicle has to be refueled to travel the distance entered by the user, as well the distance each vehicle can travel on a full tank.
Rubrics
In order to obtain all credits (15 points) in this project:
The application must execute correctly (no compilation and execution errors).
The application must have all requirement defined above.
The application must be developed in C++ programming language.
The students must submit all sources files created (files with extension .cpp and .h).
The student must submit the project files on time.
Note: Late submissions will be penalized with the loss of points.
Explanation / Answer
working c++ code compiled on ideone. I have written the classes and the functions required.
you can add some further things if you want. The code is working fine and compiling on ideone.
#include <iostream>
using namespace std;
class Vehicle
{
public:
int capacity;
int avg;
int distance;
virtual void getdata();
virtual void caldistance();
virtual void print();
};
class Car:public Vehicle
{
void getdata()
{
cout<<"Enter the details of the car capacity,avg"<<endl;
cin>>capacity;
cin>>avg;
}
void caldistance()
{
int refuel;
refuel=capacity*avg;
}
void print()
{
cout<<"print car details";
}
};
class Truck:public Vehicle
{
void getdata()
{
cout<<"Enter the details of the truck capacity,avg"<<endl;
cin>>capacity;
cin>>avg;
}
void caldistance()
{
int refuel;
refuel=capacity*avg;
}
void print()
{
cout<<"print truck details";
}
};
int main() {
// your code goes here
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.