Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need to write an object oriented C++ program (a class and a function to use it

ID: 3768289 • Letter: I

Question

I need to write an object oriented C++ program (a class and a function to use it). Also I need to use a file for my input data.

In regards to the problem I need help to use inheritance and polymorphism to calculate the force required to pull (at a constant velocity) and the weight of material that can be carried by a train consisting of different types of cars. The weight (W) and rolling friction coefficient (f) can be used to compute the force (F = fw). Consider flat bed (B), box (X), and tank (T) cars. The volume for each type of car is B (10 m3), and T (15 m3). Read the type of car and density (in kN/m3) of material being carried. A sample data file (train.dat) is : B5.3 X 6.7 X 5.6 X 7.3 T 9.8 T 8.4 T 10.3 B 3.2 B 4.2

Explanation / Answer

#include <iostream>

using namespace std;

class train{

public:

virtual void show(){cout << "train" << endl;}

};

class bed : public train{

void show(){cout << "B" << endl;}

};

class box : public train{

void show(){cout << "X" << endl;}

};

class tank : public train{

void show(){cout << "T" << endl;}

};

int main(void){

train* arr[4];

arr[0] = new train; arr[1] = new bed; arr[2] = new box; arr[3] = new tank;

for(int i = 0; i < 4; i++)

arr[i]->show();

system("PAUSE");

return 0;

}