CSC126
unknown
c_cpp
a year ago
11 kB
6
Indexable
#include <iostream> #include <string.h> using namespace std; void DisplayStadium(char stadiumName[]); double CalcPackagePrice(); double CalcAdultPrice (int quantityAdult); double CalcChildrenPrice (int quantityChildren); double CalcSeniorPrice (int quantitySenior); double CalcZonePrice (int quantity); double CalcTotalPrice (double priceAdult, double priceChildren, double priceSenior, double totalPackagePrice, double zonePrice); int main() { double priceAdult = 0.0, priceChildren = 0.0, priceSenior = 0.0, zonePrice = 0.0, totalPrice = 0.0, totalPackagePrice = 0.0; int phoneNum, quantity, quantityAdult, quantityChildren, quantitySenior, totalTicket; char name[60], stadiumName[60]; cout<<"Welcome to TixSport Ticketing System!"<<endl; cout<<"Do you wish to buy ticket(s) to watch a sport match?\nWe can help you!"<<endl; cout<<"Firstly, Enter Your Name : "; cin.ignore(); cin.getline(name, 60); cout<<"\nEnter Your Mobile Number : +60 "; cin>>phoneNum; while (phoneNum < 100000000 || phoneNum > 1999999999) { cout<<"Invalid Phone Number. Enter Again : +60 "; cin>>phoneNum; } cout<<"\nHow many tickets would you like to buy? : "; cin>>totalTicket; cout<<"\nHow many ADULT tickets would you like to buy? : "; cin>>quantityAdult; cout<<"\nHow many CHILDREN tickets would you like to buy? : "; cin>>quantityChildren; cout<<"\nHow many SENIOR tickets would you like to buy? : "; cin>>quantitySenior; quantity = quantityAdult + quantityChildren + quantitySenior; while (totalTicket != quantity) { cout<<"\nThe number that you have entered for all three categories does not equal to the total tickets that you want to buy.\nEnter again : "; cout<<"\nHow many ADULT tickets would you like to buy? : "; cin>>quantityAdult; cout<<"\nHow many CHILDREN tickets would you like to buy? : "; cin>>quantityChildren; cout<<"\nHow many SENIOR tickets would you like to buy? : "; cin>>quantitySenior; quantity = quantityAdult + quantityChildren + quantitySenior; } DisplayStadium(stadiumName); totalPackagePrice = CalcPackagePrice(); priceAdult = CalcAdultPrice (quantityAdult); priceChildren = CalcChildrenPrice (quantityChildren); priceSenior = CalcSeniorPrice (quantitySenior); zonePrice = CalcZonePrice(quantity); totalPrice = CalcTotalPrice (priceAdult, priceChildren, priceSenior, totalPackagePrice, zonePrice); cout << "\nYou have chosen " << stadiumName << " to watch a sports match." << endl; cout << "\nYour total price is RM "<<totalPrice; } void DisplayStadium(char stadiumName[]) { int chooseStadium; cout<<"These are the list of stadiums that you can choose to watch a match.\n\n "; cout << "==========================================================================================="<<endl; cout << "|| NUMBER || STADIUM ||"<<endl; cout << "==========================================================================================="<<endl; cout << "==========================================================================================="<<endl; cout << "|| 1 || BUKIT JALIL NASIONAL STADIUM, KUALA LUMPUR ||"<<endl; cout << "==========================================================================================="<<endl; cout << "|| 2 || MERDEKA STADIUM, KUALA LUMPUR ||"<<endl; cout << "==========================================================================================="<<endl; cout << "|| 3 || SHAH ALAM STADIUM, SHAH ALAM ||"<<endl; cout << "==========================================================================================="<<endl; cout << "|| 4 || TUANKU ABDUL RAHMAN STADIUM, NEGERI SEMBILAN ||"<<endl; cout << "==========================================================================================="<<endl; cout << "|| 5 || SULTAN MIZAN ZAINAL ABIDIN STADIUM, TERENGGANU ||"<<endl; cout << "==========================================================================================="<<endl; cout << "\nChoose the stadium that you want (Enter the correct number only) : "; cin >> chooseStadium; while (chooseStadium < 1 || chooseStadium > 5) { cout << "You've entered the wrong number. Enter the correct number."; cin >> chooseStadium; } if (chooseStadium >= 1 && chooseStadium <= 5) { if (chooseStadium == 1) strcpy(stadiumName, "BUKIT JALIL NASIONAL STADIUM, KUALA LUMPUR"); else if (chooseStadium == 2) strcpy(stadiumName, "MERDEKA STADIUM, KUALA LUMPUR"); else if (chooseStadium == 3) strcpy(stadiumName, "SHAH ALAM STADIUM, SHAH ALAM"); else if (chooseStadium == 4) strcpy(stadiumName, "TUANKU ABDUL RAHMAN STADIUM, NEGERI SEMBILAN"); else strcpy(stadiumName, "SULTAN MIZAN ZAINAL ABIDIN STADIUM, TERENGGANU"); } } double CalcPackagePrice() { int package, quantityPackage; double price,totalPackagePrice = 0.0; char choosePackage; cout<<"\n\nThese are the prices for the different food packages that we offer. "<<endl<<endl; cout << "=============================================================================================="<<endl; cout << "|| NUMBER || PACKAGES || PRICE PER SET ||"<<endl; cout << "=============================================================================================="<<endl; cout << "=============================================================================================="<<endl; cout << "|| 1 || ONE POPCORN, ONE SOFT DRINK || RM 9.00 ||"<<endl; cout << "=============================================================================================="<<endl; cout << "|| 2 || ONE POPCORN, TWO SOFT DRINKS || RM 11.00 ||"<<endl; cout << "=============================================================================================="<<endl; cout << "|| 3 || TWO POPCORNS, ONE SOFT DRINK || RM 15.00 ||"<<endl; cout << "=============================================================================================="<<endl; cout << "|| 4 || ONE HOTDOG BUN, ONE SOFT DRINK || RM 8.00 ||"<<endl; cout << "=============================================================================================="<<endl; cout << "|| 5 || ONE HOTDOG BUN, TWO SOFT DRINKS || RM 10.00 ||"<<endl; cout << "=============================================================================================="<<endl; cout << "|| 6 || TWO HOTDOG BUNS, ONE SOFT DRINK || RM 13.00 ||"<<endl; cout << "=============================================================================================="<<endl; cout<<"\nDo you wish to buy any of the food packages shown? (Y-Yes, N-No) : "; cin>>choosePackage; while (choosePackage !='Y' && choosePackage !='y' && choosePackage !='N' && choosePackage !='n') { cout<<"Invalid Input. Enter Again : "; cin>>choosePackage; } if (choosePackage =='Y' || choosePackage =='y') { cout<<"\nWhat type of food sets do you desire? (Enter the correct number) : "; cin>>package; while (package < 1 || package > 6) { cout<<"\nYou have entered the wrong number. Enter the correct number : "; cin>>package; } cout<<"\nEnter the quantity of the set that you want: "<<endl; cin>>quantityPackage; if (package == 1) price = 9.00; else if (package == 2) price = 11.00; else if (package == 3) price = 15.00; else if (package == 4) price = 8.00; else if (package == 5) price = 10.00; else if (package == 6) price = 13.00; totalPackagePrice += quantityPackage * price; cout<<"\nDo you wish to choose another food packages? (Y-Yes, N-No) : "<<endl; cin>>choosePackage; while (choosePackage != 'Y' && choosePackage != 'y' && choosePackage != 'N' && choosePackage != 'n') { cout<<"Invalid Input. Enter Again : "; cin>>choosePackage; } } return totalPackagePrice; } double CalcAdultPrice(int quantityAdult) { double priceAdult; priceAdult = quantityAdult * 17.50; return priceAdult; } double CalcChildrenPrice(int quantityChildren) { double priceChildren; priceChildren = quantityChildren * 12.50; return priceChildren; } double CalcSeniorPrice(int quantitySenior) { double priceSenior; priceSenior = quantitySenior * 12.50; return priceSenior; } double CalcZonePrice (int quantity) { double zonePrice; int chooseZone; cout<<"What zone do you wish to be seated? \nWe have the REGULAR ZONE and the VIP ZONE"<<endl; cout<<"Choose which zone do you want to be seated. (Enter 1 for REGULAR ZONE, 2 for VIP ZONE) : "; cin>>chooseZone; while ( chooseZone != 1 && chooseZone != 2 ) { cout<<"\nYou just entered the wrong number. Enter again : "; cin>>chooseZone; } if (chooseZone == 1) { zonePrice = quantity * 10.00; cout<<"\nWe have Zone A, B, C and D for Regular Zone. You can seat anywhere within these four zone as long as it is vacant."; } else { zonePrice = quantity * 30.00; cout<<"\nWe have Zone VIP 1 and Zone VIP 2. You can seat anywhere within these four zone as long as it is vacant."; } return zonePrice; } double CalcTotalPrice (double priceAdult, double priceChildren, double priceSenior, double totalPackagePrice, double zonePrice) { double totalPrice; totalPrice = priceAdult + priceChildren + priceSenior + totalPackagePrice + zonePrice; return totalPrice; }
Editor is loading...
Leave a Comment