Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

SECTION A: (30 marks) Instruction: Answer all questions. (Arahan : Jawab semua soalan.) 1. The Program Segment A should determine the grade based on the

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

SECTION A: (30 marks) Instruction: Answer all questions. (Arahan : Jawab semua soalan.) 1. The Program Segment A should determine the grade based on the score earned by the student. However, it's not working correctly. Explain why this situation happen. Rewrite the Program Segment A correctly by using if-else-if statement in C++. (Program Segment A perlu menentukan gred berdasarkan skor yang diperolehi oleh pelajar. Namun, ia tidak berfungsi dengan betul. Terangkan mengapa keadaan ini berlaku. Tulis semula Program Segment A dengan betul menggunakan pernyataan if- else-if dalam C++.) if (score >= 50.0) grade = 'E'; else if (score >=60.0) grade = 'D'; else if (score >= 70.0) grade = 'C'; else if (score >= 80.0) grade = 'B'; else if (score >= 90.0) grade = 'A'; elsegrade = 'F; grade = 'F'; Program Segment A (5 marks 2. Indah Parking Lot Company imposed parking charges based on the type of vehicle and number of hours. The rate is shown in Table 1. Program A is an interactive program to calculate a parking fee and print a payment receipt for each vehicle. Besides that, this program also calculates and print the total income the company obtained for a day. However, the program has a few logic errors. (Syarikat Indah Parking Lot mengenakan bayaran letak kenderaan berdasarkan jenis kenderaan dan jumlah jam. Kadarnya ditunjukkan dalam Table 1. Program A di bawah adalah program interaktif untuk mengira bayaran letak kenderaan dan mencetak resit pembayaran bagi setiap kenderaan. Selain iu, program ini juga mengira dan mencetak jumlah pendapatan yang diperolehi oleh syarikat ini dalam sehari. Walau bagaimanapun, program ini mempunyai beberapa kesalahan logik.) [See next page MTS3063: Principles of Programming 3 Table 1 : Rate Type of Vehicle Car Bus Lorry The first two hours RM3 RM4 RMS Every additional hour RM 1/hour RM 1.5/hour RM 2/hour #include void main() // variable declarations char ans; int type, hour; float pay, total_income: // beginning of loop do { cout > type; cout>hour; // calculation section if (type == 1) pay - 3+ hour*1.0; else if (type == 2) pay - 4+ hour*1.5; else if (type ==3) pay = 5+ hour*2.0; cout (a) // Function prototype void main() { float price, payment; int quantity; int type; // Input section cout>type; cout>quantity; // Process section payment=(b) //Function Calling // Output section cout 140km/hour 400 120km/hour140km/hour 300 Motorcycle speed>120km/hour 150 [7 marks) See nyt nene MTS3063: Principles of Programming 1. Write the function call for Program B. (Tuliskan panggilan fungsi bagi Program B.) [2 marks] c. Complete a program segment of function YourPayment. (Lengkapkan segmen atur cara bagi fungsi YourPayment.) [6 marks] 4. The amount of fees charged by the authorities for a speed trap summons on the highway depends on the type of vehicle and also the speed as shown in Table 3. Write a suitable selection statement for this problem. (Jumlah bayaran yang dikenakan oleh pihak berkuasa untuk saman perangkap laju di lebuhraya adalah bergantung kepada jenis kenderaan dan juga halaju seperti yang ditunjukkan di dalam Table 3. Tulis pernyataan pilihan yang bersesuaian untuk masalah ini.) Table 3 : Fees charged for a speed trap summons on the highway Type of Vehicle Speed Fees charged (RM) 120km/hour speed 140km/hour 400 120km/hour140km/hour 300 Motorcycle speed>120km/hour 150 [7 marks) See nyt nene MTS3063: Principles of Programming 7 SECTION B: (50 marks) Instruction: Answer all questions. (Arahan: Jawab semua soalan.) Question 1 The Myra Company sells five types of vehicles for the month of December 2020. Each vehicle is given a special discount as shown in Table 4. At the end of the month, the company should produce a report consists of vehicle prices after discount along with the discount given, gross profit earned by each type of vehicle, and finally the gross profit earned by the company. Example of input and output as shown in Figure 1. (Syarikat Myra menjual lima jenis kenderaan untuk bulan Disember 2020. Setiap kenderaan diberi diskaun seperti yang ditunjukkan dalam Table 4. Pada akhir bulan, syarikat perlu menghasilkan laporan yang terdiri daripada harga kenderaan setelah diskaun beserta diskaun yang diberikan, keuntungan kasar yang diperolehi oleh setiap jenis kenderaan dan akhirnya keuntungan kasar yang diperolehi oleh syarikat. Contoh input dan output adalah seperti yang ditunjukkan dalam Figure 1.) Table 4: Vehicles Price Cost Price Selling Price Vehicle Name Discount MyraA MyraB Myrac MyraD MyraE RM45,000 RM59,000 RM68,000 RM85,500 RM125,000 RM55,000 RM74.000 RM84,000 RM105,500 RM150,000 5% 5% 5% 10% 10% Enter sales of each type of vehicle: MyraA : 3 MyraB : 2 MyraC : 5 MyraD : 4 MyraE : 1 Myra Company Report for December 2020 MyraA's price after discount is RM52,250. Discount given is RM2,750. MyraB's price after discount is RM70,300. Discount given is RM3,700. MyraC's price after discount is RM79,800. Discount given is RM4,200. MyraD's price after discount is RM94,950. Discount given is RM10,550. MyraE's price after discount is RM135,000. Discount given is RM15,000. Gross profit earned by each type of vehicle MyraA = RM21,750 MyraB = RM22,600 MyRaC = RM59,000 MyraD = RM37,800 MyraE = RM10,000 Gross profit earned by Myra company is RM151,150. Figure 1: Example of input and output a) Analyze the given problem and identify what is the input, output and process. ( Analisis masalah yang diberi dan kenal pasti apakah input, output dan proses.) [10 marks] b) Write a complete C++ program that can compute and produce output as shown in Figure 1. You are also required to use at least 3 functions in your program. (Tulis atur cara C++ yang lengkap yang dapat menggira dan menghasilkan output seperti yang ditunjukkan dalam Figure 1. Anda juga dikehendaki menggunakan sekurang-kurangnya 3 fungsi dalam program ini.) [15 marks (See next page MTS3063: Principles of Programming 9 Question 2 In the Felisa Beauty competition, three candidates namely A, B, and C have entered the final competition. Ambassador Felisa Beauty, the champion of the competition, is based on the highest marks obtained from SMS votes. Voting is done by typing the word Felisa and followed by the name of the selected candidate which is either A, B or C. Suppose all votes received will be stored in an input file named UNDIAN.DAT as shown in Figure 2 where each vote represents 1 mark. The total marks for all candidates will be calculated in the main program and then these three marks will be sent to a function named Duta to determine the Ambassador Felisa and the results will be sent back to the main program for printing. Assume that the number of votes for each candidate is different from each other. (Di dalam pertandingan Felisa Beauty, tiga calon iaitu A, B dan C telah memasuki pertandingan akhir. Duta Felisa Beauty, johan pertandingan, adalah berdasarkan markah tertinggi yang diperolehi dari undian SMS. Undian dibuat dengan menaip perkataan Felisa dan diikuti dengan nama calon yang dipilih iaitu samada A, B atau C. Semua undian yang diterima akan disimpan di dalam fail input bernama UNDIAN.DAT seperti dalam Figure 2 di mana setiap undian mewakili 1 markah. Jumlah markah bagi semua calon akan dikira di dalam main program dan seterusnya ketiga-tiga markah ini akan dihantar ke fungsi bernama Duta untuk menentukan Duta Felisa dan hasil keputusannya akan dihantar semula ke main program untuk di cetak. Anggap jumlah undian bagi setiap calon adalah berbeza antara satu sama lain.) Felisa A Felisa B Felisa B Felisa A Felisa C Figure 2 : Content of input file [See next page MTS3063: Principles of Programming 10 a) Analyze the given problem and identify what is the input, output and process. Analisis masalah yang diberi dan kenal pasti apakah input, output dan proses.) 15 marks b) Write a complete C++ program that determines and prints a candidate who will be the Ambassador Felisa Beauty.) (Tulis atur cara C++ yang lengkap bagi menentukan dan mencetak calon yang akan menjadi Duta Felisa Beauty.) [20 marks END OF QUESTIONS (SOALAN TAMAT)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Sql++ For Sql Users A Tutorial

Authors: Don Chamberlin

1st Edition

0692184503, 978-0692184509

More Books

Students also viewed these Databases questions