fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include<string>
  4. using namespace std;
  5.  
  6. // structures
  7. struct NewCar {
  8. string model;
  9. int ManufactureYear;
  10. int miles;
  11. string months;
  12. };
  13. struct parts {
  14. string name;
  15. int cost;
  16. string model;
  17. };
  18. struct Maintenance {
  19. string model;
  20. int mileage;
  21. string requiredItems[10]; // part/service names
  22. int itemCount;
  23. };
  24. Maintenance maintenanceData[100];
  25. int maintenanceCount = 0;
  26.  
  27. // global vectors
  28. vector<NewCar>Cars;
  29. vector<parts>options;
  30.  
  31. // services functions
  32. void AddParts(); // done
  33. void UpdateParts(); // done
  34. void AddService();//done
  35. void UpdateService();//done
  36. void taxRate();//done
  37. int login();
  38. void AdminMenu();
  39. void UserMenu();
  40. bool AdminLogin();
  41. void AdminParts();
  42. void AdminService();
  43. void checkMaintenance(NewCar);
  44. void maintenenceSchedule();
  45. int main()
  46. {
  47. int choice = login();
  48. if (choice == 2) {
  49. int Succesfull = AdminLogin();
  50. if (Succesfull) {
  51. AdminMenu();
  52. }
  53. }
  54. }
  55. void UserMenu() {
  56. NewCar UserCar;
  57. cout << "Enter the car model" << endl;
  58. cin >> UserCar.model;
  59. cout << "Enter the car manufuctur year" << endl;
  60. cin >> UserCar.ManufactureYear;
  61. cout << "Enter the covered distance" << endl;
  62. cin >> UserCar.miles;
  63. cout << "Enter the number of months" << endl;
  64. cin >> UserCar.months;
  65. checkMaintenance(UserCar);
  66. }
  67. void AdminMenu() {
  68.  
  69. int AdminChoice;
  70. char cont;
  71. do {
  72. cout << "enter 1 for maintanence schedule"<< endl;
  73. cout << "enter 2 for parts" << endl;
  74. cout << "enter 3 for service" << endl;
  75. cout << "enter 4 for tax rate " << endl;
  76. cin >> AdminChoice;
  77. switch (AdminChoice)
  78. {
  79. case 1: maintenenceSchedule();
  80. break;
  81. case 2: AdminParts();
  82. break;
  83. case 3: AdminService();
  84. break;
  85. case 4: taxRate();
  86. break;
  87. default:
  88. cout << "invalid option" << endl;
  89. cout << "Do you want to continue(y/n)";
  90. cin >> cont;
  91. continue;
  92. }
  93. } while (cont == 'y' || cont == 'Y');
  94. }
  95. bool AdminLogin() {
  96. string mail;
  97. string password;
  98. cout << "enter username" << endl;
  99. cin >> mail;
  100. cout << "enter password" << endl;
  101. cin >> password;
  102. if (mail == "Admin@18" && password == "1234") {
  103. return 1;
  104. }
  105. else return 0;
  106. }
  107. void taxRate() {
  108. float tax = .14;
  109. char update;
  110. cout << " (last TaxRate " << tax * 100 << "% )" << "do you Want to update TaxRate ? " << endl;
  111. cin >> update;
  112. if (update == 'y') {
  113. cin >> tax;
  114. cout << "TaxRate Updated!!! " << "(New taxRate is " << tax * 100 << "%)" << endl;
  115. }
  116. else {
  117. AdminMenu();
  118. }
  119. }
  120. void AddParts() {
  121. parts NewPart;
  122. cout << "enter new part name";
  123. cin >> NewPart.name;
  124. cout << "enter new part cost";
  125. cin >> NewPart.cost;
  126. cout << "enter new part car model";
  127. cin >> NewPart.model;
  128. options.push_back(NewPart);
  129. }
  130. void AddService() {
  131. parts service;
  132. cout << "Enter the service :";
  133. cin >> service.name;
  134. cout << "Enter the cost of the service :";
  135. cin >> service.cost;
  136. cout << "Enter the car model :";
  137. cin >> service.model;
  138. options.push_back(service);
  139. }
  140. int login() {
  141. cout << "enter 1 if you are a user "<< endl;
  142. cout << "enter 2 if you are admin" << endl;
  143. int choice;
  144. cin >> choice;
  145. return choice;
  146.  
  147. }
  148. void UpdateParts() {
  149. string part_check;
  150. cin >> part_check;
  151. bool check = true;
  152. for (int i = 0; i < options.size(); i++) {
  153. if (options[i].name == part_check) {
  154. cout << "Enter the new cost";
  155. cin >> options[i].cost;
  156. }
  157. else {
  158. cout << "please choose a valid option";
  159. AdminMenu();
  160. }
  161. }
  162. }
  163. void UpdateService() {
  164. string name;
  165. cout << "Enter the name of the service :";
  166. cin >> name;
  167. for (int i = 0; i < options.size(); i++)
  168. {
  169. if (options[i].name == name) {
  170. cout << "Enter the new service cost";
  171. cin >> options[i].cost;
  172. }
  173. else {
  174. cout << "invalid option" << endl;
  175. AdminMenu();
  176. }
  177. }
  178. }
  179. void AdminParts() {
  180. int choice;
  181. cout << "Enter 1 for adding a new part" << endl;
  182. cout << "Enter 2 for updating an existing part" << endl;
  183. cin >> choice;
  184. if (choice == 1) AddParts();
  185. else if (choice == 2) UpdateParts();
  186. else {
  187. cout << "Invalid option";
  188. AdminMenu();
  189. }
  190. }
  191. void AdminService() {
  192. int choice;
  193. cout << "Enter 1 for adding a new service" << endl;
  194. cout << "Enter 2 for updating an existing service" << endl;
  195. cin >> choice;
  196. if (choice == 1) AddService();
  197. else if (choice == 2) UpdateService();
  198. else {
  199.  
  200. cout << "Invalid option";
  201. AdminMenu();
  202.  
  203. }
  204. }
  205. void maintenenceSchedule() {
  206. Maintenance m;
  207. cout << "Enter car model: ";
  208. cin >> m.model;
  209. cout << "Enter mileage (KM) for this schedule: ";
  210. cin >> m.mileage;
  211. cout << "Enter how many items are required for this schedule: ";
  212. cin >> m.itemCount;
  213.  
  214. for (int i = 0; i < m.itemCount; ++i) {
  215. cout << "Enter name of item (part or service): ";
  216. cin >> m.requiredItems[i];
  217. }
  218.  
  219. maintenanceData[maintenanceCount++] = m;
  220.  
  221. cout << "āœ… Maintenance schedule added!\n";
  222. }
  223. void checkMaintenance(NewCar userCar) {
  224. bool found = false;
  225. int total = 0;
  226. float taxRate = 0.14;
  227.  
  228. for (int i = 0; i < maintenanceCount; ++i) {
  229. if (maintenanceData[i].model == userCar.model &&
  230. userCar.miles >= maintenanceData[i].mileage) {
  231.  
  232. found = true;
  233. cout << "\nšŸ›  Maintenance needed for " << userCar.model << " at "
  234. << userCar.miles << " KM:\n";
  235.  
  236. for (int j = 0; j < maintenanceData[i].itemCount; ++j) {
  237. string item = maintenanceData[i].requiredItems[j];
  238.  
  239. // Find item in parts/services list
  240. for (int k = 0; k < options.size(); ++k) {
  241. if (options[k].name == item && options[k].model == userCar.model) {
  242. cout << " - " << item << " : " << options[k].cost << " EGP\n";
  243. total += options[k].cost;
  244. }
  245. }
  246. }
  247.  
  248. int tax = total * taxRate;
  249. cout << "Tax: " << tax << " EGP\n";
  250. cout << "Total Cost: " << total + tax << " EGP\n";
  251. break; // stop after first matching maintenance schedule
  252. }
  253. }
  254.  
  255. if (!found) {
  256. cout << "āœ… No maintenance required for the current mileage.\n";
  257. }
  258. }
  259.  
Success #stdin #stdout 0.01s 5292KB
stdin
Standard input is empty
stdout
enter 1 if you are a user 
enter 2 if you are admin