Advertisement
Guest User

Untitled

a guest
Oct 15th, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. // Simon Rutgersson, 980617-5718, simru571
  2.  
  3. #include <iostream>
  4. #include <string>
  5. #include <sstream>
  6.  
  7. using namespace std;
  8.  
  9. struct Debit_Note {
  10. string license_plate;
  11. int size;
  12. int days [31];
  13. int fees [200];
  14. int total;
  15. };
  16. int Size_Note = 0;
  17. Debit_Note notes[500];
  18.  
  19. void do_invoice (string month, Debit_Note note, string license_plate)
  20. {
  21. stringstream stream;
  22.  
  23. for(int i = 0; i <= note.size; i++)
  24. {
  25.  
  26. stream << month << "/" << note.days[i] << " ";
  27.  
  28. }
  29.  
  30. for ( int pass = 1; pass <= Size_Note - 1; pass++ ) // passes
  31. {
  32. for (int i = 0; i < Size_Note - 1; i++ ) // one pass
  33. {
  34. if ( license_plate[ i ] > license_plate[ i + 1 ] ) // compare a pair of adjacent values
  35. {
  36. //swap
  37. int temp = license_plate[ i ];
  38. license_plate[ i ] = license_plate[ i + 1 ];
  39. license_plate[ i + 1 ] = temp;
  40. }
  41. }
  42. }
  43.  
  44. string date_string = stream.str();
  45.  
  46. //The output
  47.  
  48. cout << "Invoice: " << note.license_plate << endl;
  49.  
  50. cout << "Dates: " << date_string << endl;
  51.  
  52. cout << "Amount to pay: " << note.total << endl;
  53.  
  54. cout << "====================================" << endl;
  55. }
  56.  
  57.  
  58.  
  59.  
  60.  
  61. void read_debit_notes(string month)
  62. {
  63. string license_plate;
  64.  
  65. int day, fee;
  66.  
  67. bool exists = false;
  68.  
  69. //Reads through input and add or create new and existing notes
  70.  
  71. while (true)
  72. {
  73. cin >> license_plate >> day >> fee;
  74.  
  75. exists = false;
  76.  
  77. if(license_plate == "STOP")
  78. {
  79. cout << "\nCreating invoices...\n\n";
  80.  
  81. for(int i = 0; i < Size_Note; i++)
  82. {
  83.  
  84. do_invoice(month, notes[i], license_plate);
  85.  
  86. }
  87. break;
  88. }
  89.  
  90. //Checking if we have license plate
  91. for(int i = 0; i < Size_Note; i++)
  92. {
  93. if(license_plate == notes[i].license_plate)
  94. {
  95. notes[i].days[notes[i].size+1] = day;
  96.  
  97. notes[i].fees[notes[i].size+1] = fee;
  98.  
  99. notes[i].size += 1;
  100.  
  101. notes[i].total += fee;
  102.  
  103. exists = true;
  104.  
  105. break;
  106. }
  107. }
  108.  
  109. //Adding one if we dont have it
  110. if(!exists)
  111. {
  112. Debit_Note note;
  113.  
  114. note.license_plate = license_plate;
  115.  
  116. note.size = 0;
  117.  
  118. note.total = fee;
  119.  
  120. note.days[0] = day;
  121.  
  122. note.fees[0] = fee;
  123.  
  124. notes[Size_Note] = note;
  125.  
  126. Size_Note += 1;
  127. }
  128. }
  129. }
  130.  
  131. //Where the program runs
  132. int main()
  133. {
  134. string month;
  135.  
  136. cout << "Enter a month followed by debit notes:" << endl;
  137.  
  138. cin >> month;
  139.  
  140. read_debit_notes(month);
  141.  
  142. cout << "\n";
  143.  
  144. return 0;
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement