Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.32 KB | None | 0 0
  1. #include <iostream> //WAGON
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. class Wagon {
  7. int mcapacity;
  8. double mamortization; //iznos
  9. public:
  10. string mnumber;
  11. double mweight;
  12. string mtype;
  13. int mdistdone;
  14.  
  15. Wagon();
  16. Wagon (const Wagon &wagon);
  17. ~Wagon();
  18. void FillingPrivate(Wagon &wag);
  19. int Needed();
  20. void PrintWagon();
  21. };
  22.  
  23. Wagon::Wagon() {
  24. mcapacity = 0;
  25. mamortization = 0;
  26. mweight = 0;
  27. mnumber = "0";
  28. mtype = "not set";
  29. mdistdone = 0;
  30. }
  31.  
  32. Wagon::Wagon (const Wagon &wagon) {
  33. mcapacity = wagon.mcapacity;
  34. mamortization = wagon.mamortization;
  35. mweight = wagon.mweight;
  36. mnumber = wagon.mnumber;
  37. mtype = wagon.mtype;
  38. mdistdone = wagon.mdistdone;
  39. }
  40.  
  41. Wagon::~Wagon () {}
  42.  
  43. void Wagon::FillingPrivate(Wagon &wag) {
  44. if (wag.mtype == "PASSENGER") {
  45. cout << "Enter Capacity for wagon (amount of people) > ";
  46. cin >> mcapacity;
  47. }
  48. else {
  49. cout << "Enter Capacity for wagon (tons of cargo) > ";
  50. cin >> mcapacity;
  51. }
  52. cout << "Enter Amortization for wagon > ";
  53. cin >> mamortization;
  54. while (mamortization <= 0 || mamortization > 1) {
  55. cout << "Incorrect! Enter Amortization for wagon again > ";
  56. cin >> mamortization;
  57. }
  58. return;
  59. }
  60.  
  61. int Wagon::Needed() {
  62. int n;
  63. int get;
  64. n = mdistdone / mamortization;
  65. get = n - mdistdone;
  66. return get;
  67. }
  68.  
  69. void Wagon::PrintWagon() {
  70. cout << "Number: " << mnumber << endl;
  71. cout << "Type: " << mtype << endl;
  72. cout << "Capacity: " << mcapacity << endl;
  73. cout << "Weight: " << mweight << endl;
  74. cout << "Amortization: " << mamortization << endl;
  75. cout << "Distance: " << mdistdone << endl;
  76. return;
  77. }
  78.  
  79. void Filling(Wagon &train) {
  80. cout << endl << "Filling..." << endl;
  81. cout << "Enter Number for wagon > ";
  82. cin >> train.mnumber;
  83. cout << "Enter Type for wagon ( 1-4 )" << endl;
  84. cout << "1 - PASSENGER" << endl;
  85. cout << "2 - CARGO" << endl;
  86. cout << "3 - MAIL" << endl;
  87. cout << "4 - TANKER" << endl;
  88. cout << "Type > ";
  89. cin >> train.mtype;
  90. if (train.mtype < "1" || train.mtype > "4") {
  91. cout << "WRONG TYPE! Enter Type again" << endl;
  92. cout << "Type > ";
  93. cin >> train.mtype;
  94. }
  95. if (train.mtype == "1") { train.mtype = "PASSENGER"; }
  96. else if (train.mtype == "2") { train.mtype = "CARGO"; }
  97. else if (train.mtype == "3") { train.mtype = "MAIL"; }
  98. else if (train.mtype == "4") { train.mtype = "TANKER"; }
  99. cout << "Type set to " << train.mtype << endl;
  100. train.FillingPrivate(train);
  101. cout << "Enter Weight for wagon > ";
  102. cin >> train.mweight;
  103. cout << "Enter Made Distance for wagon > ";
  104. cin >> train.mdistdone;
  105. return;
  106. }
  107.  
  108. bool CheckNumber(Wagon &wag, string iden) {
  109. string getid = wag.mnumber;
  110. if (getid == iden) { return true; }
  111. else { return false; }
  112. }
  113.  
  114. int main(void) {
  115. Wagon w1, w2;
  116. w1.PrintWagon();
  117. Filling(w1);
  118. w2 = Wagon(w1);
  119. w1.PrintWagon();
  120. cout << "To end: " << w1.Needed() << endl;
  121. cout << "Copy of w1 - w2. Printing it" << endl;
  122. w2.PrintWagon();
  123. cout << endl;
  124. cout << CheckNumber(w1, "1") << endl;
  125. cout << CheckNumber(w1, "2") << endl;
  126.  
  127. return 0;
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement