0% found this document useful (0 votes)
29 views

Mycode CPP

Uploaded by

inourall00
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Mycode CPP

Uploaded by

inourall00
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 8

#include <iostream>

#include <string>

using namespace std;

// structure to store information about a customer


struct Customer
{
string name;
string phone;
int ID;

};

// structure to store information about a sport area


struct SportArea
{
string gameType;
int numberOfPlayers;
float reservationPrice;
bool availabilityStatus;
int assignedCustomerIDs[100];
int numAssignedCustomers;
int capacity;
int customerID;
};

// function to add a customer


void addCustomer(Customer customers[], int &numCustomers)
{
cout << "Enter customer name: ";
cin >> customers[numCustomers].name;
cout << "Enter customer phone: ";
cin >> customers[numCustomers].phone;
cout << "Enter customer ID: ";
cin >> customers[numCustomers].ID;

// increase the count of the number of customers


numCustomers++;
}

// function to add a sport area


void addSportArea(SportArea sportAreas[], int &numSportAreas)
{
cout << "Enter sport area game type: ";
cin >> sportAreas[numSportAreas].gameType;
cout << "Enter number of players for this sport area: ";
cin >> sportAreas[numSportAreas].numberOfPlayers;
// set the capacity of the sport area to the number of players
sportAreas[numSportAreas].capacity = sportAreas[numSportAreas].numberOfPlayers;
cout << "Enter reservation price for this sport area: ";
cin >> sportAreas[numSportAreas].reservationPrice;

// increase the count of the number of sport areas


numSportAreas++;
}

// 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;

// Prompt the user to enter the customer ID


cout << "Enter customer ID: ";
cin >> customerID;

// 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--;

// Check if the sport area is not fully booked


if (sportAreas[sportAreaIndex].numAssignedCustomers <
sportAreas[sportAreaIndex].capacity)
{
// Assign the customer to the sport area by storing their ID in the
assignedCustomerIDs array

sportAreas[sportAreaIndex].assignedCustomerIDs[sportAreas[sportAreaIndex].numAssigned
Customers++] = customerID;

// Confirm the customer has been assigned to the sport area


cout << customers[i].name << " is now assigned to " <<
sportAreas[sportAreaIndex].gameType << endl;

}
else
{
// If the sport area is fully booked, display a message
cout << "Sport area is fully booked." << endl;
}

// End the loop


break;
}
}
}
// function to update the customer information
void updateCustomer(Customer customers[],int numCustomers )
{
int customerID;
// prompt the user to enter the customer ID
cout << "Enter customer ID: ";
cin >> customerID;

// 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;
}
}
}

// function to update the sport area information


void updateSportArea(SportArea sportAreas[], int numSportAreas)
{
int sportAreaIndex;
// prompt the user to enter the sport area index
cout << "Enter sport area index (1 - " << numSportAreas << "): ";
cin >> sportAreaIndex;
sportAreaIndex--;

// 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;
}
}

// This function displays the sport area information.


void showSportAreas(SportArea sportAreas[], int numSportAreas)
{
cout << "Sport Areas:" << endl;
// Loop through all the sport areas
for (int i = 0; i < numSportAreas; i++)
{
// Display each sport area information
cout << "Game Type: " << sportAreas[i].gameType << endl;
cout << "Number of Players: " << sportAreas[i].numberOfPlayers << endl;
cout << "Reservation Price: " << sportAreas[i].reservationPrice << endl;
cout << "Availability Status: " << ((sportAreas[i].numAssignedCustomers <
sportAreas[i].capacity) ? "Availabil" : "not Availabil")<< endl;
cout << endl;
}
}
// Function to delete a customer from the customers array
void deleteCustomer(Customer customers[], int &numCustomers)
{
int customerID;

cout << "Enter customer ID: ";


cin >> customerID;

// loop through all customers


for (int i = 0; i < numCustomers; i++)
{
// if the current customer ID matches the customer ID entered by the user
if (customers[i].ID == customerID)
{
// shift all customers after the current customer one position to the left
for (int j = i; j < numCustomers - 1; j++)
{
customers[j] = customers[j + 1];
}
// decrement the number of customers
numCustomers--;

cout << "Customer deleted." << endl;


break;
}
}
}

// Function to delete a sport area from the sportAreas array


void deleteSportArea(SportArea sportAreas[], int &numSportAreas)
{
int sportAreaIndex;

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];
}

// decrement the number of sport areas


numSportAreas--;

cout << "Sport area deleted." << endl;


}
// This function searches for a customer based on the customer ID.
// If the customer is found, it displays their name, phone number, and ID,
// and also lists the sport areas they have been assigned to.
void searchCustomer(Customer customers[], int numCustomers, SportArea sportAreas[], int
numSportAreas)
{
int customerID;

// Request customer ID from the user


cout << "Enter customer ID: ";
cin >> customerID;

// Loop through all customers


for (int i = 0; i < numCustomers; i++)
{
// If the customer ID is found, print the customer information
if (customers[i].ID == customerID)
{
cout << "Customer name: " << customers[i].name << endl;
cout << "Customer phone: " << customers[i].phone << endl;
cout << "Customer ID: " << customers[i].ID << endl;

// Loop through all sport areas


for (int j = 0; j < numSportAreas; j++)
{
// Loop through all assigned customers in the sport area
for (int k = 0; k < sportAreas[j].numAssignedCustomers; k++)
{
// If the customer ID is found, print the sport area information
if (sportAreas[j].assignedCustomerIDs[k] == customerID)
{
cout << "Assigned sport area: " << endl;
cout << "Game Type: " << sportAreas[j].gameType << endl;
cout << "Number of Players: " << sportAreas[j].numberOfPlayers
<< endl;
cout << "Reservation Price: " << sportAreas[j].reservationPrice <<
endl;
break;
}
}
}

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 the information of the SportArea object being searched


cout << "Game Type: " << sportAreas[sportAreaIndex].gameType << endl;
cout << "Number of Players: " << sportAreas[sportAreaIndex].numberOfPlayers <<
endl;
cout << "Reservation Price: " << sportAreas[sportAreaIndex].reservationPrice << endl;
cout << "Availability Status: " << ((sportAreas[sportAreaIndex].numAssignedCustomers
< sportAreas[sportAreaIndex].capacity) ? "Availabil" : "not Availabil")<< endl;

// Output a header for the list of customers assigned to the SportArea object5
cout << "Customers assigned to " << sportAreas[sportAreaIndex].gameType << ": " <<
endl;

// Loop through the array of Customer objects


for (int i = 0; i < numCustomers ; i++)
{
// Loop through the list of assigned customer IDs for the SportArea object
for (int j=0 ; j < sportAreas[sportAreaIndex].numAssignedCustomers; j++)
{
// Check if the current Customer object has an ID that matches one of the
assigned IDs
if (sportAreas[sportAreaIndex].assignedCustomerIDs[j] == customers[i].ID)
{
// If a match is found, output the information of the Customer object
cout << "Name: " << customers[i].name << endl;
cout << "Phone: " << customers[i].phone << endl;
cout << "ID: " << customers[i].ID << 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

int option; // menu option selected by the user

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";
}

} while (option != 12); // repeat until user selects exit option

return 0;
}

You might also like