HIS IS VERY IMPORTANT, MUST BE WRITTEN IN OBJECT ORIENTED C++ STYLE WITH CLASSES
ID: 662899 • Letter: H
Question
HIS IS VERY IMPORTANT, MUST BE WRITTEN IN OBJECT ORIENTED C++ STYLE WITH CLASSES ONLY
NO PROCEDURAL STYLE, IF YOU ARE NOT USING CLASSES AS OBJECTS THEN THAT IS PROCEDRUAL STYLE TOP TO BOTTOM. USE OBJECTS AND CLASSES
THIS IS VERY IMPORTANT MUST BE READ FROM A FILE
VERY VERY IMPORTANT MUST WORK
VERY VERY VERY IMPORTANT, FOLLOW THE DIRECTIONS, DONT BOTHER IF YOU CAN NOT FOLLOW IT I WILL MARK WITH NEGATIVE FEED BACK IF JUST ANYTHING IS THROWN UP.
I AM GETTING FED UP WITH PAYING FOR THIS SERVICE AND I END UP THROWING MONEY OUT THE WINDOW
use inheritance and polymorphism to calculate the force required to pull (at a constact velocity) and the weight of material that can be carried by a train consisting of many different types of cars. The weight(W) and rolling friction coefficient(f) can be used to compute the force(F=fw). Consider FLAT BED CAR(B),BOX CAR(X) and TANK CAR(T). The VOLUME for each type of carisB(10m3),X(20m3) and T(15m3). Read (FROM A FILE) the type of car and density (in kN/m3) of material being carried. A sample data file (train.dat) is :
B 5.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
THIS IS VERY IMPORTANT, MUST BE WRITTEN IN OBJECT ORIENTED C++ STYLE WITH CLASSES ONLY
THIS IS VERY IMPORTANT MUST BE READ FROM A FILE
VERY VERY IMPORTANT MUST WORK
VERY VERY VERY IMPORTANT, FOLLOW THE DIRECTIONS, DONT BOTHER IF YOU CAN NOT FOLLOW IT I WILL MARK WITH NEGATIVE FEED BACK IF JUST ANYTHING IS THROWN UP.
I AM POSTING THIS FOUR TIMES BECAUSE I END UP DOING SO BEFORE I GET AN ACTUAL ANSWER
Explanation / Answer
#include <bits/stdc++.h>
using namespace std;
class car{
public:
string name;
int volume;
double density;
car(string n,int v,double d){
name = n;
volume = v;
density = d;
}
double cal_weight(){
return volume*density;
}
};
class B : public car{
public:
B(string n,double d = 1.0):car(n,10,d) {}
};
class X : public car{
public:
X(string n, double d = 1.0):car(n,20,d) {}
};
class T : public car{
public:
T(string n, double d = 1.0):car(n,15,d) {}
};
void removeInitSpaces(string& str){
int i=str.length();
int j=0;
while ((j<i) && ((str[j] == ' ') || (str[j] == ' '))){
j++;
}
str.erase(0,j);
}
int main(){
ifstream infile;
infile.open("grades.txt");
string s;
while (!infile.eof()){
getline(infile,s);
string str;
for (int i = 0; i < s.length(); i++){
if (s[i] == ','){
removeInitSpaces(str);
int index = str.find(" ");
string c = str.substr(0,index);
double den = atof(str.substr(index+1).c_str());
car *cart;
if (c == "B"){
B b(c,den);
cart = &b;
double weight = cart->cal_weight();
cout << "Force is " << weight*0.5 << endl;
}
else if (c == "X"){
X x(c,den);
cart = &x;
double weight = cart->cal_weight();
cout << "Force is " << weight*0.5 << endl;
}
else{
T t(c,den);
cart = &t;
double weight = cart->cal_weight();
cout << "Force is " << weight*0.5 << endl;
}
str = "";
}
else{
str = str + s[i];
}
}
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.