Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
708
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.25 KB | None | 0 0
  1. /*
  2. William Castle - c17134 - 10/20/19 - MP3c - Locomotive assignment - The
  3. program takes in a amount of car data depoending on how long the train
  4. is and then assigns a locomotive combination that is fit to do the job
  5. and outputs all the data that is relevent. The input is taken from a
  6. infile that is predone for this assignment and outputs to a outfile
  7. with data organised to be readable. the program assums you will give it
  8. the correct info in the order it wants it and of the type it wants.
  9. */
  10.  
  11. #include <iostream>
  12. #include <fstream>
  13. #include <iomanip>
  14. #include <string>
  15.  
  16. using namespace std;
  17.  
  18. int main()
  19. {
  20. ifstream infile;
  21. ofstream outfile;
  22.  
  23. infile.open("mp3cin.txt");
  24. outfile.open("mp3cout.txt");
  25.  
  26. //train weight constants
  27. int const train_w_2m = 2000000;
  28. int const train_w_5m = 5000000;
  29. int const train_w_7m = 7000000;
  30.  
  31. //train size constants
  32. float const train_l_2m = 50.5;
  33. float const train_l_5m = 65.0;
  34. float const train_l_7m = 110.3;
  35. float const train_l_max = 1257.4;
  36.  
  37. //warnings
  38. string const overweight = "Max Weight has been reached";
  39. string const warning_length =
  40. "WARNING - The Maxinum legnth has been reached";
  41.  
  42. //declaratoins for reused variables
  43. int train_id, train_length;
  44. float car_l, car_w, total_length = 0, total_weight = 0;
  45. string assigned_loc;
  46. bool warning = false;
  47.  
  48. //output manipulation
  49. int tab = 16, out_total = 35;
  50.  
  51. //intake train id and amount of cars before while set
  52. infile >> train_id >> train_length;
  53.  
  54. //structer argument
  55. while (infile)
  56. {
  57. //echo input data
  58. outfile << right << setw(28) << "Data for Train Number " << train_id
  59. << endl << setw(tab) << "Car Length" << setw(tab) << "Car Weight"
  60. << endl << endl;
  61.  
  62. //for_loop w/ the number of cars to take in all of the train data
  63. for (int a = 1; a <= train_length; a++)
  64. {
  65. //input for next car
  66. infile >> car_l >> car_w;
  67.  
  68. //echo input data for each car
  69. outfile << setprecision(3) << setw(tab) << car_l
  70. << setprecision(6) << setw(tab) << car_w << endl;
  71.  
  72. //add the lentgh and weights to a total value to be used later
  73. total_length += car_l;
  74. total_weight += car_w;
  75. }
  76.  
  77. //decide what trains are need for the weight sum from above
  78. if (total_weight > train_w_2m)
  79. {
  80. if (total_weight > train_w_2m*2)
  81. {
  82. if (total_weight > train_w_5m)
  83. {
  84. if (total_weight > train_w_7m)
  85. {
  86. if (total_weight > train_w_5m*2)
  87. {
  88. if (total_weight > train_w_7m*2)
  89. {
  90. if (total_weight > train_w_7m*3)
  91. {
  92. assigned_loc = overweight;
  93. }
  94. else
  95. {
  96. assigned_loc = "3 GP-7";
  97. total_length += (train_l_7m * 3);
  98. }
  99. }
  100. else
  101. {
  102. assigned_loc = "2 GP-7";
  103. total_length += (train_l_7m * 2);
  104. }
  105. }
  106. else
  107. {
  108. assigned_loc = "2 GP-5";
  109. total_length += (train_l_5m * 2);
  110. }
  111. }
  112. else
  113. {
  114. assigned_loc = "GP-7";
  115. total_length += train_l_7m;
  116. }
  117. }
  118. else
  119. {
  120. assigned_loc = "GP-5";
  121. total_length += train_l_5m;
  122. }
  123. }
  124. else
  125. {
  126. assigned_loc = "2 GP-1";
  127. total_length += (train_l_2m * 2);
  128. }
  129. }
  130. else
  131. {
  132. assigned_loc = "GP-1";
  133. total_length += train_l_2m;
  134. }
  135.  
  136. //testing for maxmium lenght
  137. if (total_length > train_l_max)
  138. {
  139. warning = true;
  140. }
  141.  
  142. //echo/output the length, weight, and the other stuff
  143. outfile << endl << left << setw(out_total)
  144. << "Total Number Of Train Cars: " << train_length << endl
  145. << setw(out_total) << "Total Weight Of Train Cars: "
  146. << setprecision(8) << total_weight << " pounds" << endl
  147. << setw(out_total) << "Type Of Locomotive(s) Assigened: "
  148. << assigned_loc << endl << setw(out_total)
  149. << "Total Length Of Train: " << setprecision(5)
  150. << total_length << " ft" << endl;
  151.  
  152. //output of length warning
  153. if (warning == true)
  154. {
  155. outfile << warning_length << " for Train " << train_id << endl;
  156. }
  157.  
  158. //reset values/setting new outputlines
  159. warning = false;
  160. total_length = 0;
  161. total_weight = 0;
  162. outfile << endl << endl;
  163.  
  164. //intake train id and amount of cars for new set
  165. infile >> train_id >> train_length;
  166. }
  167.  
  168. infile.close();
  169. outfile.close();
  170.  
  171. return 0;
  172. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement