As the yard manager you are responsible for calculating train length and total w
ID: 3541384 • Letter: A
Question
As the yard manager you are responsible for calculating train length and total weight. You have decided to write a program to help you. To start out, you are only concerned about three types of cars: gondola, box, and passenger. The average lengths and weights of the car types: BOX 53 TONS, 45.0 FEET GONDOLA 65 TONS, 70.0 FEET PASSENGER 70 TONS 80.5 FEET
You also need to calculate the number of locomotives needed to pull each train. Every locomotive is 55.0 feet long and weighs 52 tons. Each can pull 1000 tons. Use the ceil () function found in cmath.
You want your program to report the total number of rail cars (excluding engines), the number of each car type, the total weight of the train (with and without engines), the total number of engines required, and the total length of the train (including engines).
The input will consist of the number of each car type - Box, Gondola,and Passenger - in that order.
You must run your program a total of three times on the following data:
5 7 4
12 10 0
0 0 12
Explanation / Answer
please rate - thanks
any questions/problems just ask
tested with DEV C++
#include <cmath>
#include <iostream>
using namespace std;
int main()
{int boxW=53,gondolaW=65,passW=70,locoW=52,locoPull=1000,totalW;
double boxL=45,gondolaL=70,passL=80.5,locoL=55,totalL;
int box,gondola,pass,total,loco;
cout<<"Enter number of box cars: ";
cin>>box;
cout<<"Enter number of gondola cars: ";
cin>>gondola;
cout<<"Enter number of passenger cars: ";
cin>>pass;
total=box+gondola+pass;
totalL=box*boxL+gondola*gondolaL+pass*passL;
totalW=box*boxW+gondola*gondolaW+pass*passW;
loco=(int)ceil(totalW/1000.);
cout<<"Totals without locomotive(s) ";
cout<<"cars: "<<total<<endl;
cout<<"weight: "<<totalW<<endl;
cout<<"length: "<<totalL<<endl<<endl;
cout<<"Totals with locomotive(s) ";
total+=loco;
totalW=totalW+locoW*loco;
totalL=totalL+locoL*loco;
cout<<"cars: "<<total<<endl;
cout<<"weight: "<<totalW<<endl;
cout<<"length: "<<totalL<<endl<<endl;
cout<<"The train: ";
cout<<"Locomotives: "<<loco<<endl;
cout<<"Box cars: "<<box<<endl;
cout<<"Gondolas: "<<gondola<<endl;
cout<<"Passenger cars: "<<pass<<endl;
system("pause");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.