Professional Documents
Culture Documents
MTS3063 Labtest (Jasrey)
MTS3063 Labtest (Jasrey)
PRINCIPLE OF PROGRAMMING
LABTEST
DESTINATION PRICE
Alor Setar RM70
Sungai Petani RM44
Kulim RM40
Baling RM65
Tunjang RM50
Gurun RM55
This bus company provides 3% discount on ticket prices for Sungai Petani destination and
10% discount on ticket prices for Baling and Tunjang destinations if the customer makes a
purchase of more than 3 tickets. Other destinations aren’t included.
When a ticket buyer pays a certain amount of money, the system will calculate the balance
that should be given to the ticket buyer. Finally calculate the total income earned by Utara
Express Bus Company. Customer number will be calculated automatically start from number
1.
A Alor Setar
S Sungai Petani
K Kulim
B Baling
T Tunjang
G Gurun
CODING
1 #include <iostream.h>
2
3 void main ()
4
5 {
6 char destination;
7 char nextloop;
8 int numberofticket;
9 int amount_paid_by_the_ticket_buyer;
10 int priceofthetickets;
11 float discount;
12 float total_price;
13 float priceoftheticketafterdiscount;
14 float balance;
15
16 cout<<"Do you want to start the system Yes[Y], No[N]: ";
17 cin>>nextloop;
18 while (nextloop == 'Y')
19 {
20
21 cout<<"Enter you destination :";
22 cin>>destination;
23
24 if (destination == 'A')
25 priceofthetickets = 70;
26 else if (destination == 'S')
27 priceofthetickets = 44;
28 else if (destination =='K')
29 priceofthetickets = 40;
30 else if (destination == 'B')
31 priceofthetickets = 65;
32 else if (destination == 'T')
33 priceofthetickets = 50;
34 else if (destination == 'G')
35 priceofthetickets =55;
36
37 cout<<"Enter number of ticket :";
38 cin>>numberofticket;
39 cout<<"Enter amount paid by the ticket buyer :";
40 cin>>amount_paid_by_the_ticket_buyer;
41
42 total_price = priceofthetickets*numberofticket;
43 balance = total_price - amount_paid_by_the_ticket_buyer;
44
45 cout<<"price of the tickets:";
46 cin>>priceofthetickets;
47
48
49 priceoftheticketafterdiscount = priceofthetickets *
discount;
50
51 if (priceofthetickets == 70)
52 discount = priceofthetickets * 0.0;
53 if (priceofthetickets == 44)
54 discount = priceofthetickets * 0.03;
55 if (priceofthetickets == 40)
56 discount = priceofthetickets * 0.0;
57 if (priceofthetickets == 65)
58 discount = priceofthetickets * 0.10;
59 if (priceofthetickets == 50)
60 discount = priceofthetickets * 0.10;
61 if (priceofthetickets == 55)
62 discount = priceofthetickets * 0.0;
63
64 priceoftheticketafterdiscount = priceofthetickets -
discount;
65
66 cout<<"Utara Express Bus Company"<<endl;
67 cout<<"Destinasi :"<<destination<<endl;
68 cout<<"Number of ticket :"<<numberofticket<<endl;
69 cout<<"amount paid by the ticket
buyer :"<<amount_paid_by_the_ticket_buyer<<endl;
70 cout<<"Price of the
tickets :"<<priceofthetickets<<endl;
71 cout<<"Discount :"<<discount<<endl;
72 cout<<"Price of the ticket after
discount:"<<priceoftheticketafterdiscount<<endl;
73 cout<<"Balance :"<<balance<<endl;
74
75 cout<<"Do you want to continue yes[Y], no[N] :";
76 cin>>nextloop;
77
78 }
79 }
OUTPUT