0% found this document useful (0 votes)
24 views

Computer Programming

This document contains instructions for a final examination for a Computer Programming course. It has two sections - Section A contains 5 structured questions worth 50 marks total. Section B contains 1 essay question worth 50 marks. Students must answer all questions, take screenshots of outputs, and submit their answers in a single PDF file by email within 30 minutes of the exam ending.

Uploaded by

MACGAMINGG YT
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Computer Programming

This document contains instructions for a final examination for a Computer Programming course. It has two sections - Section A contains 5 structured questions worth 50 marks total. Section B contains 1 essay question worth 50 marks. Students must answer all questions, take screenshots of outputs, and submit their answers in a single PDF file by email within 30 minutes of the exam ending.

Uploaded by

MACGAMINGG YT
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

KOLEJ ANTARABANGSA TEKNOLOGI

SPEKTRUM

FINAL EXAMINATION

PROGRAMME: DIPLOMA IN RENEWABLE ENERGY MANAGEMENT


COURSE: COMPUTER PROGRAMMING
COURSE CODE: FDC1130
SESSION: MAY 2023 – SEPTEMBER 2023
DATE:
TIME:
DURATION: 3 HOURS

EXAMINATION INSTRUCTIONS TO STUDENTS:

1. This question paper consists of Section A, and Section B.


2. You are required to answer ALL QUESTIONS in all sections.
3. You shall take a screenshot of the expected output derived from the questions and
labeled accordingly in Microsoft Words to be sent via email.
4. Please name your file as follows: Course name_name_ID.
Example: Computer Programming_Noor Faizah_FDC1130
5. Submit your document in ONE SINGLE PDF FILE.
6. Email your answer scripts to [email protected] within 30 MINUTES after
the examination ends. Delayed submission will not be entertained.

MARKS DISTRIBUTION:

SECTION CONTENT MARKS


A STRUCTURED 50
QUESTIONS
B ESSAY QUESTIONS 50
TOTAL 100
FINAL EXAMINATION
FDC1130
MAY 2023-SEPT 2023

SECTION A: STRUCTURED QUESTIONS


SECTION MARKS: 50

QUESTION 1
Input from the user (N) and print all EVEN and ODD numbers between 1 to N is tested
using the C++ script shown below. Find errors in the program and determine the expected
output.

*/ C++ program to print all


/* Even and Odd numbers from 1 to N
#include <iostream>
using namespace std;
void evenNumbers(int n)
{
int i;
for (i = 1; i <= n; i++) {
//condition to check EVEN numbers
if (i % 2 == 0)
cout << i << " ";
}
cout << "/n";
}
void oddNumbers(int n)
{
int i;
for (i = 1; i <= n; i++) {
//condition to check ODD numbers
if (i % 2 != 0)
cout << i << " "
}
cout << "\n";
}
// main code
int main()
{
int N;
// input the value of N
cout << "Enter the value of N (limit): ";
cin >> n;
cout << "EVEN numbers are...\n";
evenNumbers(N);
cout << "ODD numbers are...\n";
oddNumbers(N);
return 0;
}

(CLO1, C4, 10 MARKS)

2
FINAL EXAMINATION
FDC1130
MAY 2023-SEPT 2023

QUESTION 2

Figure 1

Figure 1 shows the colour of a chess square board. The related script to process the task is
as shown below. Find errors in the program and determine the expected output.

#include<iostream>
#include<cctype>
using namespace std;
int main()
{
char string[10], x;
cout << "Enter the coordinates of the square, \
\nthe first coordinate A to H and second coordinate 1 to 8: ";
cin.getline(string, 10);
x = string[0];
x = tolower(x);
string[0] = x;
if (string[0] == 'a' || string[0] == 'c' || string[0] == 'e' || string[0] == 'g')
{
if (string[1] == '1' || string[1] == '3' || string[1] == '5' || string[1] == '7')
cout << "Black square";
else
cout << "White square";
}
else
{
if (string[1] == '1' || string[1] == '3' || string[1] == '5' || string[1] == '7')
cout << "white square";
else
cout << "Black square";
}

return 0;
}

(CLO1, C4, 10 MARKS)


QUESTION 3
Find errors in the program and construct the necessary script to solve the given problem.

3
FINAL EXAMINATION
FDC1130
MAY 2023-SEPT 2023

#include <iostream>
using namespace std;
int main()

int menu;
int areaR, length, width;
double areaT, base, height;
double areaC, radius;
const double PI=3.142;

do
{
cout<<"ntGeometry Calculator: n";
cout<"1: Calculate the area of rectanglen";
cout<<"2: Calculate the area of trianglen";
cout<<"3: Calculate the area of circlen";
cout<<"4: Quitn";
cout<<"Enter your choice: ";
cin>>menu

if (menu<1||menu>4);
cout<<"nPlease enter 1,2,3 or 4: ";
else if (menu==1)
{
cout<<"Enter length and width of rectangle: ";
cin>>length>>width;
areaR = length*width;
cout<<"nThe area of rectangle is: <<areaR<<endl;
}
else if(menu==2)
{
cout<<"Enter base and height of triangle: ";
cin>>base>>height;
areaT = 1.0/2.0*base*height;
cout<<"nThe area of triangle is: "<<area<<endl;
}
else if (menu==3)
{
cout<<"Enter radius of a circle: ";
cin>>radius;
areaC = PI*pow(radius,2);
cout<<"nThe area of circle is: "<<areaC<<end1;
}
while (menu!=4);
return 0;

(CLO1, C4, 10 MARKS)

QUESTION 4
Analyse and construct a flow chart based on the program below.

4
FINAL EXAMINATION
FDC1130
MAY 2023-SEPT 2023

#include <iostream>
int main()
{
double length, width, area;
std::cout << "Enter the length of the rectangle: ";
std::cin >> length;
std::cout << "Enter the width of the rectangle: ";
std::cin >> width;
area = length * width;
std::cout << "The area of the rectangle is: " << area << std::endl;
return 0;
}

(CLO1, C4, 10 MARKS)

5
FINAL EXAMINATION
FDC1130
MAY 2023-SEPT 2023

QUESTION 5
Analyse the flow chart and write a program for the sequential control structure below.

START

DECLARE char Name [50]; double Hours, Rate, Pay

INPUT Name, Hours, Rate

CALCULATE
Pay=Hours*Pay

DISPLAY Name, Pay

END

(CLO1, C4, 10 MARKS)

6
FINAL EXAMINATION
FDC1130
MAY 2023-SEPT 2023

SECTION B: ESSAY QUESTIONS


SECTION MARKS: 50

QUESTION 1
As a programmer, you are asked to develop a system to be used by Mommy Collection
store that sells women’s clothes. The following table shows the codes and the prices of
clothes available in the store according to the types of clothes.

Code Types of clothes Price (RM)


1 Baju Kurung Tradisional 250.00
2 Baju Kurung Moden 320.00
3 Kebaya 350.00
4 Jubah 220.00
Display message “The code is invalid” 0.00

Analyze the data given above and construct the necessary C++ program to perform each
of the following:

(a) Prompt the user to input the following information:


 Quantity of clothes
 Display an error message if the user enters an invalid code.

(b) Measure the total price to be paid.


(c) Display information as shown in the following example:

Example of output:
**********************************************************************
Welcome to the Mommy Collection store!
Enter the quantity of Baju Kurung Tradisional: 1
Enter the quantity of Baju Kurung Moden: 1
Enter the quantity of Kebaya: 2
Enter the quantity of Jubah: 3
-------------------------------------------------------------
Total Cost: RM 1930.00
Thank you for shopping with us! Have a nice day!
********************************************************************

(CLO1, C4, 25 MARKS)

7
FINAL EXAMINATION
FDC1130
MAY 2023-SEPT 2023

QUESTION 2
Analyze the data given and construct the C++ program that displays the following menu:

GEOMETRY CALCULATOR
1. Calculator the Volume of a Cone
2. Calculate the Volume of a Hemisphere
3. Calculator the Volume of a Cube
4. Quit

(a) If the user enters 1, the program should ask for the radius and height of the cone
and display the volume. Use the following formula.
Volume = (1/3) πr2h
(b) If the user enters 2, the program should ask for the radius of the hemisphere. Use
the following formula.
Volume = (2/3) πr3
(c) If the user enters 3, the program should ask for the side length of the cube and
display its volume. Use the following formula.
Volume = a3
Display an error message if the user enters a number outside the range of 1
through 4.
(CLO1, C4, 25 MARKS)

END OF QUESTION PAPER

You might also like