Computer Programming
Computer Programming
SPEKTRUM
FINAL EXAMINATION
MARKS DISTRIBUTION:
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.
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;
}
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;
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;
}
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
CALCULATE
Pay=Hours*Pay
END
6
FINAL EXAMINATION
FDC1130
MAY 2023-SEPT 2023
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.
Analyze the data given above and construct the necessary C++ program to perform each
of the following:
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!
********************************************************************
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)