-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathticket.cpp
More file actions
140 lines (125 loc) · 3.31 KB
/
ticket.cpp
File metadata and controls
140 lines (125 loc) · 3.31 KB
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
133
134
135
136
137
138
139
140
#include "Ticket.h"
Ticket::Ticket() : ID(count+1), price(800.0), customer {nullptr} {}
Ticket::Ticket(int ID, float price, const Screening& screening, const Hall& seat, const Customer& customer)
: ID(ID), price(price), screening(screening), seat(seat) {}
Ticket::~Ticket(){
delete customer;
}
void Ticket::setID(int ID) {
this->ID = ID;
}
int Ticket::getID() const {
return ID;
}
void Ticket::setPrice(float price) {
this->price = price;
}
float Ticket::getPrice() const {
return price;
}
void Ticket::setScreening(const Screening& screening) {
this->screening = screening;
}
Screening Ticket::getScreening() const {
return screening;
}
void Ticket::setSeat(const Hall& seat) {
this->seat = seat;
}
Hall Ticket::getSeat() const {
return seat;
}
void Ticket::sellTicket() {
ID=count+1;
screening=Screening::selectScreening();
if (screening.getId()==0){
sellTicket();
}
int option;
do {
cout<<"\n1.Regular Customer \n2.VIP Customer \n";
cin>>option;
cin.ignore();
if (option==1){
customer = new RegularCustomer;
customer->addCustomer();
}
else if(option==2){
customer = new VIPCustomer;
customer->selectCustomer();
price-=price*customer->calculateDiscount(); //calculating the discounted price for the customer
}
else {
cout<<"Invalid option";
}
}while(option!=1 && option!=2);
int seatno;
cout<<"\nEnter seat no: ";
cin>>seatno;
screening.allotHall(seat); //alloting the same values to hall as in screening
seat.setSeat(seatno); //setting row and col number
cout<<"\nTicket price: "<<price<<endl;
cout<<"Confirm purchase? \n1.Yes \n2.No\n";
int opt;
do{
cin>>opt;
switch (opt)
{
case 1:
cout << "Selling ticket. Seat: " << seatno << endl;
saveToFile();
count++;
break;
case 2:
cout<<"Transaction Discarded."<<endl;
break;
default:
cout<<"Invalid option! ";
break;
}
}while (opt!=1 && opt!=2);
}
void Ticket:: refundTicket(vector<Ticket>& tickets){
cout<<"Enter the id of the Ticket you want to refund: ";
int refundId,opt;
cin>>refundId;
bool found=false;
for (int i=0; i<tickets.size(); i++){
if (refundId==tickets[i].ID){
cout<<"The ticket cost RS: "<<tickets[i].price<<endl;
cout<<"Press 1 to confirm refund. "<<endl;;
found=true;
cin>>opt;
if (opt==1){
tickets.erase(tickets.begin()+i);
cout<<"Ticket Refunded. "<<endl;
return;
}
else{
cout<<"Refund Cancelled. Enjoy your show!"<<endl;
return;
}
}
}
if (!found){
cout<<"No ticket found with ID: "<<refundId<<endl;
}
}
void Ticket::saveToFile() {
ofstream fout;
try{
fout.open("tickets.txt",ios::app);
if (fout.fail()){
throw runtime_error("Error opening screenings.txt for writing");
}
}
catch(runtime_error &e){
cout<<e.what()<<endl;
return;
}
fout<<ID<<endl;
fout<<price<<endl;
fout<<getScreening()<<endl;
fout.close();
cout << "Transaction Saved!" << endl;
}