1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>
#include <ctime>
using namespace std;
///////////// Global Variables ///////////////////
int PlatinumTnum=0, GoldTnum=50, SilverTnum=200, BronzeTnum=400; //Tnum stands for Ticket number and all of these variables are counters.
int TC, UNticketnum, UNid, UNphone; // the prefix UN stands for Unassigned and we use that to read from the file, then we assign the stored number to the variables mentioned above.
string UNname;
ifstream in;
ofstream out;
int OneMore;
////////////////////////////////////////////////////////////////
// Prototypes:
void IssueNewTicket();
void tickets_stats();
int income_stats();
int random_winner();
////////////////////////////////////////////////
int main(){
string name;
int ID, phone;
in.open("tickets.txt", ios::app);
out.open("tickets.txt", ios::app);
char entry;
int TC;
do{
cout<<"The main menu:\n a. Issue a new ticket\n b. Cancel ticket reservation\n c. Print out customer purchase\n d. Show income statistics\n e. Choose random winner\n f. Exit\n";
cin>>entry;
do{
if(entry=='a' || entry=='A'){
// a while loop to read from tickets.txt in order to know the last ticket unique number of each category
tickets_stats();
cout<<"Choose a ticket category: \n 1. Platinum\n 2. Gold\n 3. Silver\n 4. Bronze\n";
cin>>TC; //TC stands for Ticktet Category
switch(TC){
case 1:{
if (PlatinumTnum<50)
{PlatinumTnum+=1;
cout<<"Please enter the customer's first name, ID and phone number consecutively.\n\n";
cout<<"ticket ID is: "<<PlatinumTnum<<"\n";
cin>>name>>ID>>phone;
out<<PlatinumTnum<<"\t"<<name<<"\t"<<ID<<"\t"<<phone<<"\n"; }
else cout<<"Sorry, There is no more bookable Platinum tickets\n\n";
IssueNewTicket();//calling a function that asks if they user wants to book a new/different ticket.
break;}
case 2: {
if (GoldTnum<200)
{GoldTnum+=1;
cout<<"Please enter the customer's first name, ID and phone number consecutively.\n\n";
cout<<"ticket ID is: "<<GoldTnum<<"\n";
cin>>name>>ID>>phone;
out<<GoldTnum<<"\t"<<name<<"\t"<<ID<<"\t"<<phone<<"\n"; }
else cout<<"Sorry, There is no more bookable Gold tickets\n\n";
IssueNewTicket();//calling a function that asks if they user wants to book a new/different ticket.
break;}
case 3: {
if (SilverTnum<400)
{SilverTnum+=1;
cout<<"Please enter the customer's first name, ID and phone number consecutively.\n\n";
cout<<"ticket ID is: "<<SilverTnum<<"\n";
cin>>name>>ID>>phone;
out<<SilverTnum<<"\t"<<name<<"\t"<<ID<<"\t"<<phone<<"\n"; }
else cout<<"Sorry, There is no more bookable Gold tickets\n\n";
IssueNewTicket();//calling a function that asks if they user wants to book a new/different ticket.
break;}
case 4: {
if (BronzeTnum<1000)
{BronzeTnum+=1;
cout<<"Please enter the customer's first name, ID and phone number consecutively.\n\n";
cout<<"ticket ID is: "<<BronzeTnum<<"\n";
cin>>name>>ID>>phone;
out<<BronzeTnum<<"\t"<<name<<"\t"<<ID<<"\t"<<phone<<"\n"; }
else cout<<"Sorry, There is no more bookable Gold tickets\n\n";
IssueNewTicket();//calling a function that asks if they user wants to book a new/different ticket.
break;}
}
}
if(entry=='d' || entry=='D'){
cout<<"\t\tTotal income is:\t"<<income_stats()<<" QR"<<endl;
cout<<"Detailed statistics: "<<endl;
cout<<PlatinumTnum<<" Platinum tickets were sold (x250 QR)\n"<<GoldTnum-50<<" Gold tickets were sold (x200 QR)\n"<<(SilverTnum-200)<<" Silver tickets were sold (x150 QR)\n"<<(BronzeTnum-400)<<" Bronze tickets were sold (x50 QR)\n"<<"Total income is "<<income_stats()<<" QR\n\n";
}
if(entry=='e' || entry=='E') {
if(random_winner()!=0)
cout<<"the lucky winner is the person with the ticket id number: "<<random_winner()<<endl;
else cout<<"the chosen random number did not match any sold ticket number, try again.";}
if (TC!=1 && TC!=2 && TC!=3 && TC!=4) cout<<"Invalid choise, please choose again";}while(TC!=1 &&TC!=2 && TC!=3 && TC!=4 || OneMore==1);
}
while(entry != 'f' && entry != 'F');
return 0;}
void IssueNewTicket(){
cout<<"Do you want to book a new or a different ticket?\n1. Yes\n2. No\n";
cin>>OneMore;}
void tickets_stats(){
int total_income;
while(in>>UNticketnum>>UNname>>UNid>>UNphone){
if (UNticketnum<=50) PlatinumTnum+=1;
else if (UNticketnum>50 && UNticketnum<=200) GoldTnum+=1;
else if (UNticketnum>200 && UNticketnum<=400) SilverTnum+=1;
else if (UNticketnum>400 && UNticketnum<=1000) BronzeTnum+=1;}
}
int income_stats(){
int total_income;
while(in>>UNticketnum>>UNname>>UNid>>UNphone){
if (UNticketnum<=50) PlatinumTnum+=1;
else if (UNticketnum>50 && UNticketnum<=200) GoldTnum+=1;
else if (UNticketnum>200 && UNticketnum<=400) SilverTnum+=1;
else if (UNticketnum>400 && UNticketnum<=1000) BronzeTnum+=1;}
total_income = (PlatinumTnum*250) + ((GoldTnum-50)*200) + ((SilverTnum-200)*150) + ((BronzeTnum-400)*50);
return total_income;}
int random_winner(){
int min=1, max=1000;
string winner_info;
srand(time(0));
int ticket_number_winner = 1+(rand()%1000);
while(in>>UNticketnum>>UNname>>UNid>>UNphone){
if(ticket_number_winner==UNticketnum)
return ticket_number_winner;
else return 0;}}
|