Вы находитесь на странице: 1из 4

Write a complete program and answer each of the following questions.

a) Given the following destination and the destination fare. Destination Kangar KL Kangar Butterworth Kangar Kuala Terengganu Kangar Kota Bharu Kangar Johor Bahru Fare (RM) 48 12 54 49 65

b) Your program must enter :a. The persons name who booked the ticket b. The destination c. Total ticket for adult and children i. Given that the ticket price for children is half of the adult ticket price c) Display the persons name, destination and total ticket price. d) Apply the while loop, so that the next person able to book the ticket.

/* Name: Siti Normalia Binti Sulaiman Copyright: Author: Siti Normalia Date: 26/04/13 04:22 Description: Assignment 4 */ #include <iostream.h> #include <conio.h> #include <iomanip.h> int main ( ) { int destination, adult, children; float ticPrice,totPrice; char Name[100]; char cont = 'y'; cout.setf (ios::fixed); cout.setf (ios::showpoint); while (cont == 'y') { { cout << "\n Please enter the passanger name : " ; cin >> Name; cin.ignore (80,'\n'); cout << "\n Please enter the quantity of adult ticket : " ; cin >> adult; cout << "\n Please enter the quantity of children ticket : " ; cin >> children; } { cout << " \n 1. Kangar to Kuala Lumpur \t \n 2. Kangar to Butterworth \t \n 3. Kangar to Kuala Terengganu \t \n 4. Kangar to Kota Bharu \t \n 5. Kangar to Johor Bahru " ; cout << "\n Please enter the destination :" ; cin >> destination ; } { if (destination ==1){ ticPrice = 48; cout << "\n The destination is :" << destination; cout << " Kangar to Kuala Lumpur " <<endl; }

else if (destination ==2){ ticPrice = 12; cout << "\n The destination is :" << destination; cout << " Kangar to Butterworth " <<endl; } else if (destination ==3){ ticPrice = 54; cout << "\n The destination is :" << destination ; cout << " Kangar to Kuala Terengganu " << endl ; } else if (destination ==4){ ticPrice = 49; cout << "\n The destination is :" << destination ; cout << " Kangar to Kota Bharu " << endl ; } else if (destination ==5){ ticPrice = 65; cout << "\n The destination is :" << destination ; cout << " Kangar to Johor Bahru " << endl; } else { ticPrice = 0; cout << "\n Invalid Option" ; } } totPrice = (adult * ticPrice) + (children * (ticPrice/2)) ; cout << "\n The passenger's name is :" << Name ; cout << "\n The total ticket price is RM " <<setprecision (2) << totPrice ; cout << "\n Do you want to continue? [y/n] :" ; cin >> cont; } cout << "\n Thank You, enjoy your ride with us :)" ; getche ( ) ; return 0;

Вам также может понравиться