Mycode CPP
Mycode CPP
#include <string>
};
// This function assigns a customer to a sport area based on the customer ID and sport area
index.
void assignSportArea(Customer customers[], int numCustomers, SportArea sportAreas[], int
numSportAreas)
{
int customerID, sportAreaIndex;
// Loop through all customers to find the customer with the entered ID
for (int i = 0; i < numCustomers; i++)
{
if (customers[i].ID == customerID)
{
// Prompt the user to enter the sport area index
cout << "Enter sport area index (1 - " << numSportAreas << "): ";
cin >> sportAreaIndex;
// Decrement the sport area index to match the 0-based index in the sportAreas
array
sportAreaIndex--;
sportAreas[sportAreaIndex].assignedCustomerIDs[sportAreas[sportAreaIndex].numAssigned
Customers++] = customerID;
}
else
{
// If the sport area is fully booked, display a message
cout << "Sport area is fully booked." << endl;
}
// loop through the list of customers to find the customer with the matching ID
for (int i = 0; i < numCustomers; i++)
{
if (customers[i].ID == customerID)
{
// once the matching customer is found, prompt the user to enter the updated
phone number
cout << "Enter updated customer phone: ";
cin >> customers[i].phone;
// print a message to confirm that the customer information has been updated
cout << "Customer information updated." << endl;
break;
}
}
}
// prompt the user to enter the updated number of players, and reservation price
cout << "Enter updated number of players for this sport area: ";
cin >> sportAreas[sportAreaIndex].numberOfPlayers;
cout << "Enter updated reservation price for this sport area: ";
cin >> sportAreas[sportAreaIndex].reservationPrice;
// print a message to confirm that the sport area information has been updated
cout << "Sport area information updated." << endl;
}
// This function displays the customer information.
void showCustomers(Customer customers[], int numCustomers)
{
cout << "Customers:" << endl;
// Loop through all the customers
for (int i = 0; i < numCustomers; i++)
{
// Display each customer information
cout << "Name: " << customers[i].name << endl;
cout << "Phone: " << customers[i].phone << endl;
cout << "ID: " << customers[i].ID << endl;
cout << endl;
}
}
cout << "Enter sport area index (1 - " << numSportAreas << "): ";
cin >> sportAreaIndex;
// decrement the sportAreaIndex to match the 0-based indexing of the sportAreas array
sportAreaIndex--;
// shift all sport areas after the current sport area one position to the left
for (int i = sportAreaIndex; i < numSportAreas - 1; i++)
{
sportAreas[i] = sportAreas[i + 1];
}
break;
}
}
}
// This function takes in an array of SportArea objects, the number of SportArea objects,
// an array of Customer objects, and the number of Customer objects as inputs
void searchSportArea(SportArea sportAreas[], int numSportAreas, Customer customers[],
int numCustomers)
{
// Declare an integer variable to store the index of the SportArea object to be searched
int sportAreaIndex;
// Prompt the user to enter the index of the SportArea object to be searched
cout << "Enter sport area index (1 - " << numSportAreas << "): ";
cin >> sportAreaIndex;
// Decrement the sportAreaIndex by 1 to match the 0-based indexing used in the arrays
sportAreaIndex--;
// Output a header for the list of customers assigned to the SportArea object5
cout << "Customers assigned to " << sportAreas[sportAreaIndex].gameType << ": " <<
endl;
int main()
{
Customer customers[100]; // array to store customer information
SportArea sportAreas[100]; // array to store sport area information
int numCustomers = 0; // number of customers
int numSportAreas = 0; // number of sport annnnnn
nnnnnnreas
do
{
cout << "=============================================="<< endl;
cout << " Sport Area Reservation System" << endl;
cout << "=============================================="<< endl;
cout << "1. Add new customer" << endl;
cout << "2. Add new sport area" << endl;
cout << "3. Assign sport area to customer" << endl;
cout << "4. Update customer details" << endl;
cout << "5. Update sport area details" << endl;
cout << "6. Show customers list" << endl;
cout << "7. Show sport areas list" << endl;
cout << "8. Delete customer" << endl;
cout << "9. Delete sport area" << endl;
cout << "10. Search customer details" << endl;
cout << "11. Search sport area details" << endl;
cout << "12. Exit" << endl;
cout << "=============================================="<< endl;
cout << "Enter option: ";
cin >> option;
switch (option)
{
case 1: // add new customer
addCustomer(customers, numCustomers);
break;
case 2: // add new sport area
addSportArea(sportAreas, numSportAreas);
break;
case 3: // assign sport area to customer
assignSportArea(customers, numCustomers, sportAreas, numSportAreas );
break;
case 4: // update customer details
updateCustomer(customers, numCustomers);
break;
case 5: // update sport area details
updateSportArea(sportAreas, numSportAreas);
break;
case 6: // show customers list
showCustomers(customers, numCustomers);
break;
case 7: // show sport areas list
showSportAreas(sportAreas, numSportAreas);
break;
case 8: // delete customer
deleteCustomer(customers, numCustomers);
break;
case 9: // delete sport area
deleteSportArea(sportAreas, numSportAreas);
break;
case 10: // search customer details
searchCustomer(customers, numCustomers, sportAreas, numSportAreas);
break;
case 11: // search sport area details
searchSportArea(sportAreas, numSportAreas, customers, numCustomers);
break;
case 12: // exit
cout << "thank you";
}
return 0;
}