#include <iostream>
#include <vector>
#include<string>
using namespace std;
// structures
struct NewCar {
string model;
int ManufactureYear;
int miles;
string months;
};
struct parts {
string name;
int cost;
string model;
};
struct Maintenance {
string model;
int mileage;
string requiredItems[10]; // part/service names
int itemCount;
};
Maintenance maintenanceData[100];
int maintenanceCount = 0;
// global vectors
vector<NewCar>Cars;
vector<parts>options;
// services functions
void AddParts(); // done
void UpdateParts(); // done
void AddService();//done
void UpdateService();//done
void taxRate();//done
int login();
void AdminMenu();
void UserMenu();
bool AdminLogin();
void AdminParts();
void AdminService();
void checkMaintenance(NewCar);
void maintenenceSchedule();
int main()
{
int choice = login();
if (choice == 2) {
int Succesfull = AdminLogin();
if (Succesfull) {
AdminMenu();
}
}
}
void UserMenu() {
NewCar UserCar;
cout << "Enter the car model" << endl;
cin >> UserCar.model;
cout << "Enter the car manufuctur year" << endl;
cin >> UserCar.ManufactureYear;
cout << "Enter the covered distance" << endl;
cin >> UserCar.miles;
cout << "Enter the number of months" << endl;
cin >> UserCar.months;
checkMaintenance(UserCar);
}
void AdminMenu() {
int AdminChoice;
char cont;
do {
cout << "enter 1 for maintanence schedule"<< endl;
cout << "enter 2 for parts" << endl;
cout << "enter 3 for service" << endl;
cout << "enter 4 for tax rate " << endl;
cin >> AdminChoice;
switch (AdminChoice)
{
case 1: maintenenceSchedule();
break;
case 2: AdminParts();
break;
case 3: AdminService();
break;
case 4: taxRate();
break;
default:
cout << "invalid option" << endl;
cout << "Do you want to continue(y/n)";
cin >> cont;
continue;
}
} while (cont == 'y' || cont == 'Y');
}
bool AdminLogin() {
string mail;
string password;
cout << "enter username" << endl;
cin >> mail;
cout << "enter password" << endl;
cin >> password;
if (mail == "Admin@18" && password == "1234") {
return 1;
}
else return 0;
}
void taxRate() {
float tax = .14;
char update;
cout << " (last TaxRate " << tax * 100 << "% )" << "do you Want to update TaxRate ? " << endl;
cin >> update;
if (update == 'y') {
cin >> tax;
cout << "TaxRate Updated!!! " << "(New taxRate is " << tax * 100 << "%)" << endl;
}
else {
AdminMenu();
}
}
void AddParts() {
parts NewPart;
cout << "enter new part name";
cin >> NewPart.name;
cout << "enter new part cost";
cin >> NewPart.cost;
cout << "enter new part car model";
cin >> NewPart.model;
options.push_back(NewPart);
}
void AddService() {
parts service;
cout << "Enter the service :";
cin >> service.name;
cout << "Enter the cost of the service :";
cin >> service.cost;
cout << "Enter the car model :";
cin >> service.model;
options.push_back(service);
}
int login() {
cout << "enter 1 if you are a user "<< endl;
cout << "enter 2 if you are admin" << endl;
int choice;
cin >> choice;
return choice;
}
void UpdateParts() {
string part_check;
cin >> part_check;
bool check = true;
for (int i = 0; i < options.size(); i++) {
if (options[i].name == part_check) {
cout << "Enter the new cost";
cin >> options[i].cost;
}
else {
cout << "please choose a valid option";
AdminMenu();
}
}
}
void UpdateService() {
string name;
cout << "Enter the name of the service :";
cin >> name;
for (int i = 0; i < options.size(); i++)
{
if (options[i].name == name) {
cout << "Enter the new service cost";
cin >> options[i].cost;
}
else {
cout << "invalid option" << endl;
AdminMenu();
}
}
}
void AdminParts() {
int choice;
cout << "Enter 1 for adding a new part" << endl;
cout << "Enter 2 for updating an existing part" << endl;
cin >> choice;
if (choice == 1) AddParts();
else if (choice == 2) UpdateParts();
else {
cout << "Invalid option";
AdminMenu();
}
}
void AdminService() {
int choice;
cout << "Enter 1 for adding a new service" << endl;
cout << "Enter 2 for updating an existing service" << endl;
cin >> choice;
if (choice == 1) AddService();
else if (choice == 2) UpdateService();
else {
cout << "Invalid option";
AdminMenu();
}
}
void maintenenceSchedule() {
Maintenance m;
cout << "Enter car model: ";
cin >> m.model;
cout << "Enter mileage (KM) for this schedule: ";
cin >> m.mileage;
cout << "Enter how many items are required for this schedule: ";
cin >> m.itemCount;
for (int i = 0; i < m.itemCount; ++i) {
cout << "Enter name of item (part or service): ";
cin >> m.requiredItems[i];
}
maintenanceData[maintenanceCount++] = m;
cout << "ā
Maintenance schedule added!\n";
}
void checkMaintenance(NewCar userCar) {
bool found = false;
int total = 0;
float taxRate = 0.14;
for (int i = 0; i < maintenanceCount; ++i) {
if (maintenanceData[i].model == userCar.model &&
userCar.miles >= maintenanceData[i].mileage) {
found = true;
cout << "\nš Maintenance needed for " << userCar.model << " at "
<< userCar.miles << " KM:\n";
for (int j = 0; j < maintenanceData[i].itemCount; ++j) {
string item = maintenanceData[i].requiredItems[j];
// Find item in parts/services list
for (int k = 0; k < options.size(); ++k) {
if (options[k].name == item && options[k].model == userCar.model) {
cout << " - " << item << " : " << options[k].cost << " EGP\n";
total += options[k].cost;
}
}
}
int tax = total * taxRate;
cout << "Tax: " << tax << " EGP\n";
cout << "Total Cost: " << total + tax << " EGP\n";
break; // stop after first matching maintenance schedule
}
}
if (!found) {
cout << "ā
No maintenance required for the current mileage.\n";
}
}