Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- William Castle - c17134 - 10/20/19 - MP3c - Locomotive assignment - The
- program takes in a amount of car data depoending on how long the train
- is and then assigns a locomotive combination that is fit to do the job
- and outputs all the data that is relevent. The input is taken from a
- infile that is predone for this assignment and outputs to a outfile
- with data organised to be readable. the program assums you will give it
- the correct info in the order it wants it and of the type it wants.
- */
- #include <iostream>
- #include <fstream>
- #include <iomanip>
- #include <string>
- using namespace std;
- int main()
- {
- ifstream infile;
- ofstream outfile;
- infile.open("mp3cin.txt");
- outfile.open("mp3cout.txt");
- //train weight constants
- int const train_w_2m = 2000000;
- int const train_w_5m = 5000000;
- int const train_w_7m = 7000000;
- //train size constants
- float const train_l_2m = 50.5;
- float const train_l_5m = 65.0;
- float const train_l_7m = 110.3;
- float const train_l_max = 1257.4;
- //warnings
- string const overweight = "Max Weight has been reached";
- string const warning_length =
- "WARNING - The Maxinum legnth has been reached";
- //declaratoins for reused variables
- int train_id, train_length;
- float car_l, car_w, total_length = 0, total_weight = 0;
- string assigned_loc;
- bool warning = false;
- //output manipulation
- int tab = 16, out_total = 35;
- //intake train id and amount of cars before while set
- infile >> train_id >> train_length;
- //structer argument
- while (infile)
- {
- //echo input data
- outfile << right << setw(28) << "Data for Train Number " << train_id
- << endl << setw(tab) << "Car Length" << setw(tab) << "Car Weight"
- << endl << endl;
- //for_loop w/ the number of cars to take in all of the train data
- for (int a = 1; a <= train_length; a++)
- {
- //input for next car
- infile >> car_l >> car_w;
- //echo input data for each car
- outfile << setprecision(3) << setw(tab) << car_l
- << setprecision(6) << setw(tab) << car_w << endl;
- //add the lentgh and weights to a total value to be used later
- total_length += car_l;
- total_weight += car_w;
- }
- //decide what trains are need for the weight sum from above
- if (total_weight > train_w_2m)
- {
- if (total_weight > train_w_2m*2)
- {
- if (total_weight > train_w_5m)
- {
- if (total_weight > train_w_7m)
- {
- if (total_weight > train_w_5m*2)
- {
- if (total_weight > train_w_7m*2)
- {
- if (total_weight > train_w_7m*3)
- {
- assigned_loc = overweight;
- }
- else
- {
- assigned_loc = "3 GP-7";
- total_length += (train_l_7m * 3);
- }
- }
- else
- {
- assigned_loc = "2 GP-7";
- total_length += (train_l_7m * 2);
- }
- }
- else
- {
- assigned_loc = "2 GP-5";
- total_length += (train_l_5m * 2);
- }
- }
- else
- {
- assigned_loc = "GP-7";
- total_length += train_l_7m;
- }
- }
- else
- {
- assigned_loc = "GP-5";
- total_length += train_l_5m;
- }
- }
- else
- {
- assigned_loc = "2 GP-1";
- total_length += (train_l_2m * 2);
- }
- }
- else
- {
- assigned_loc = "GP-1";
- total_length += train_l_2m;
- }
- //testing for maxmium lenght
- if (total_length > train_l_max)
- {
- warning = true;
- }
- //echo/output the length, weight, and the other stuff
- outfile << endl << left << setw(out_total)
- << "Total Number Of Train Cars: " << train_length << endl
- << setw(out_total) << "Total Weight Of Train Cars: "
- << setprecision(8) << total_weight << " pounds" << endl
- << setw(out_total) << "Type Of Locomotive(s) Assigened: "
- << assigned_loc << endl << setw(out_total)
- << "Total Length Of Train: " << setprecision(5)
- << total_length << " ft" << endl;
- //output of length warning
- if (warning == true)
- {
- outfile << warning_length << " for Train " << train_id << endl;
- }
- //reset values/setting new outputlines
- warning = false;
- total_length = 0;
- total_weight = 0;
- outfile << endl << endl;
- //intake train id and amount of cars for new set
- infile >> train_id >> train_length;
- }
- infile.close();
- outfile.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement