Uploaded by Dâng Triều

CS Code

advertisement
TASK 1
DECLARE TicketType[], Attr[], Weekday[] as STRING
DECLARE Day1[], Day2[], Attrcost[] as REAL
TicketType[1:5] <- [" 1. Adults", “Children (2 for 1 Adult)", "Seniors", “2. Family (2A or 2S and
3C)", “3. Group (Min 6)"]
Day1[1:5] <- [20.00, 12.00, 16.00, 60.00, 15.00]
Day2[1:5] <- [30.00, 18.00, 24.00, 90.00, 22.50]
Attr[1:3] <- ["Lion feeding", " Penguin feeding", " Barbecue (two days)"]
Attrcost[1:3] <- [2.50, 2.00, 5.00]
Weekday[1:7] <- [" 1. Sunday", " 2. Monday", " 3. Tuesday", " 4. Wednesday", " 5. Thursday", "
6. Friday", " 7. Saturday"]
OUTPUT "Ticket Type", "1 Day cost", "2 Day cost"
FOR i = 1 TO 5
OUTPUT TicketType[i], Day1[i], Day2[i]
NEXT i
OUTPUT " Attraction Type ", " Attraction Cost"
FOR x <- 1 TO 3
OUTPUT Attr[x], Attrcost[x]
NEXT x
OUTPUT "AVAILABLE BOOKING DAYS"
FOR z = 1 TO 7
OUTPUT Weekday[z]
NEXT z
TASK 2
DECLARE Totalpay, Lionpay, Pengpay, BBQpay, Grouppay as REAL
DECLARE Daychoice, Weekdaychoice, Adult, Child, Senior as INTEGER
Bookingnum = 1000
REPEAT
Adult = 0; Child = 0; Senior = 0
OUTPUT "Enter number of days 1 or 2"
INPUT Daychoice
WHILE Daychoice < 1 OR Daychoice > 2
OUTPUT " 1 or 2 days only allowed for a booking"
OUTPUT "Enter number of days 1 or 2”
INPUT Daychoice
END WHILE
OUTPUT "Enter day number of the weekday (1-7)"
INPUT Weekdaychoice
WHILE Weekdaychoice < 1 OR Weekdaychoice > 7
OUTPUT " Choose between 1 to 7 only. Enter day number of the weekday "
INPUT Weekdaychoice
END WHILE
OUTPUT " Enter number of adults "
INPUT Adult
WHILE Adult < 0
OUTPUT " Cannot be a negative value. Enter number of adults "
INPUT Adult
END WHILE
OUTPUT " Do you wish to continue to book for children? (y/n) "
INPUT ChildContinue
IF ChildContinue = "y" THEN
OUTPUT " Enter number of children "
INPUT Child
WHILE Child < 0
OUTPUT " Cannot be a negative value. Enter number of children "
INPUT Child
END WHILE
END IF
OUTPUT " Do you wish to continue to book for seniors? (y/n) "
INPUT SeniorContinue
IF SeniorContinue = "y" THEN
OUTPUT " Enter number of seniors "
INPUT Senior
WHILE Senior < 0
OUTPUT “Cannot be a negative value. Enter number of seniors "
INPUT Senior
END WHILE
END IF
TotalPassenger = Adult + Child + Senior
OUTPUT " Do you wish to add extra attraction (y/n)? "
INPUT AttractionContinue
IF AttractionContinue = "y" THEN
OUTPUT " Do you wish to opt for Lion Feeding (y/n)? "
INPUT LionChoice
IF LionChoice = "y" THEN
Lionpay = TotalPassenger * Attrcost(1)
END IF
OUTPUT " Do you wish to opt for Penguin Feeding (y/n)? "
INPUT PengChoice
IF PengChoice = "y" THEN
Pengpay = TotalPassenger * Attrcost(2)
END IF
OUTPUT " Do you wish to opt for Barbecue (y/n)? "
INPUT BBQChoice
IF BBQChoice = "y" THEN
IF Daychoice = 1 THEN
OUTPUT " Barbecue for 2 days booking only!"
BBQChoice = "n"
ELSEIF Daychoice = 2 THEN
BBQpay = TotalPassenger * Attrcost(3)
END IF
END IF
END IF
REPEAT
REPEAT
OUTPUT " Enter your choice of booking using either 1, 2 or 3 "
INPUT BookingChoice
UNTIL BookingChoice = 1 OR BookingChoice = 2 OR BookingChoice = 3
IF BookingChoice = 1 THEN
IF (Adult = 0 AND Child > 0) OR (Adult > 0 AND Child > Adult * 2) THEN
chngbk$ = "y"
OUTPUT " Cannot place this booking. Children are more than
allowed or without adults"
OUTPUT " Do you wish to change the booking option (y/n)"
INPUT chngbk$
IF chngbk$ = "n" THEN GOTO ED
ELSE
IF Daychoice = 1 THEN
Totalpay = Adult * Day1[1] + Child * Day1[2] + Senior *
Day1[3]
ELSEIF Daychoice = 2 THEN
Totalpay = (Adult * Day2[1] + Child * Day2[2] + Senior *
Day2[3]
END IF
chngbk$ = "n"
END IF
ELSEIF BookingChoice = 2 THEN
IF (Adult + Senior) > 2 OR Child >3 THEN
chngbk$ = "y"
OUTPUT " Family booking not eligible"
OUTPUT " Do you wish to change the booking option (y/n)"
INPUT chngbk$
IF chngbk$ = "n" THEN GOTO ED
ELSEIF (Adult + Senior) <= 2 AND Child <= 3 THEN
IF Daychoice = 1 THEN
Totalpay = 60
ELSEIF Daychoice = 2 THEN
Totalpay = 90
END IF
chngbk$ = "n"
END IF
ELSEIF BookingChoice = 3 THEN
IF TotalPassenger < 6 THEN
chngbk$ = "Y"
OUTPUT " Cannot place GROUP TICKET booking "
OUTPUT " Do you wish to change the booking option (y/n) “
INPUT chngbk$
IF chngbk$ = "n" THEN GOTO ED
ELSE
IF Daychoice = 1 THEN
Totalpay = TotalPassenger * Day1[5]
ELSEIF Daychoice = 2 THEN
Totalpay = TotalPassenger * Day2[5]
END IF
chngbk$ = "n"
END IF
END IF
UNTIL chngbk$ = "n"
Finalpay = Totalpay + Pengpay + Lionpay + BBQpay
OUTPUT " BOOKING DETAILS"
OUTPUT " BOOKING NUMBER ", Bookingnum + 1
OUTPUT " Adults: ", Adult
OUTPUT " Children: ", Child
OUTPUT " Seniors: ", Senior
OUTPUT " The total number of people: ", TotalPassenger
IF BookingChoice = 1 THEN
OUTPUT " You have made an individual booking"
ELSEIF BookingChoice = 2 THEN
OUTPUT " You have made a Family booking"
ELSEIF BookingChoice = 3 THEN
OUTPUT " You have made a Group Booking"
END IF
IF Daychoice = 1 THEN
OUTPUT " You have booked for "; wk(Weekdaychoice)
ELSEIF Daychoice = 2 AND Weekdaychoice = 7 THEN
OUTPUT " You have booked for "; wk(Weekdaychoice); " and "; wk(1)
ELSEIF Daychoice = 2 AND Weekdaychoice <> 7 THEN
OUTPUT " You have booked for "; wk(Weekdaychoice); " and ";
wk(Weekdaychoice + 1)
END IF
IF AttractionContinue = "y" THEN OUTPUT " EXTRA ATTRACTIONS "
IF LionChoice = "y" THEN OUTPUT " You booked for Lion Feeding and it costs ", Lionpay
IF PengChoice = "y" THEN OUTPUT " You booked for Penguin Feeding and it costs ",
Pengpay
IF BBQChoice = "y" THEN OUTPUT " You booked for Barbecue and it costs ", BBQpay
OUTPUT " The total amount to pay is ", Finalpay
Bookingnum = Bookingnum + 1
OUTPUT " Do you wish to make a new reservation (y/n)"
INPUT NewChoice
ED:
UNTIL NewChoice = "n"
END
TASK 3
REPEAT
IF BookingChoice = 1 THEN
IF Daychoice = 1 THEN Grouppay = TotalPassenger * 15
IF Daychoice =2 THEN Grouppay = TotalPassenger * 22.50
IF Totalpay > Grouppay AND TotalPassenger >= 6 OR Adult + Senior > = 4 THEN
OUTPUT " You are advised to choose single group or multiple family bookings "
OUTPUT " Do you wish to change the booking option (y/n)"
INPUT chngbk$
IF chngbk$ = "y" THEN GOTO ED
END IF
ELSEIF BookingChoice = 3 THEN
IF Adult + Senior >= 4 AND Child >= 6 THEN
OUTPUT " You can choose family and/or individual booking "
OUTPUT " Do you wish to change the booking option (y/n) "
INPUT chngbk$
IF chngbk$ = "y" THEN GOTO ED
END IF
ENDIF
ED:
UNTIL newbk$ = "n"
END
DealCheck = 0
DealDiff = 0
IF BookingChoice = 1 AND TotalPassenger >= 6 AND DayChoice = 1 THEN
DealCheck = TotalPassenger * Day1[5]
DealDiff = Totalpay - DealCheck
END IF
IF BookingChoice = 1 AND TotalPassenger >= 6 AND DayChoice = 2 THEN
DealCheck = TotalPassenger * Day2[5]
DealDiff = Totalpay – DealCheck
END IF
IF DealDiff > 0 THEN
OUTPUT "You have chosen to buy", TotalPassenger, “Tickets. Which
cost : ", Totalpay, "$ (Not including extra attractions)"
OUTPUT"You can avail Group Tickets (Option 3) and can save", DealDiff, “$"
ELSE
OUTPUT "You have availed best deal. There is no other value deal
than this."
END IF
IF BookingChoice = 3 AND Adult + Senior >= 4 AND Child >= 6 THEN
DealCheck = (TotalPassenger / 5) * Day1[2]
DealDiff = Totalpay - DealCheck
IF DealDiff > 0 THEN
OUTPUT"You have opted Group Tickets. Which
cost : ", Totalpay, "$ (Not including extra attractions)"
OUTPUT"You can avail Family Tickets(Option 2) and can save", DealDiff, “$"
END IF
END IF
Download