100% found this document useful (2 votes)
975 views

Answer Scheme Quiz CSC126 - Okt2021

The document provides instructions for a 90 minute assessment with 30 total marks. It details that students may only use computers to read the question paper and must submit handwritten answers as a single PDF within 15 minutes of completion. The assessment contains 4 sections with questions testing knowledge of algorithms, the program development life cycle, program characteristics, variable values, coding expressions, tracing code, and writing a program to calculate lawn care wages.

Uploaded by

Haziq Genji
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
975 views

Answer Scheme Quiz CSC126 - Okt2021

The document provides instructions for a 90 minute assessment with 30 total marks. It details that students may only use computers to read the question paper and must submit handwritten answers as a single PDF within 15 minutes of completion. The assessment contains 4 sections with questions testing knowledge of algorithms, the program development life cycle, program characteristics, variable values, coding expressions, tracing code, and writing a program to calculate lawn care wages.

Uploaded by

Haziq Genji
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

CSC126: Assessment 1 – Answer Scheme 11/11/2021

Total Marks: 30

Time: 90 minutes (4:10 – 5:40 pm)

Delivery time: Ends at 5:55 pm

Instructions to Students:

• you are NOT ALLOWED to use the computer during the assessment, except for
reading the question paper
• you are required to answer all questions in handwriting (typing is NOT allowed).
• after you have finished, take photos of your answer and convert to ONE PDF file.
• share your PDF File to Google Classroom.
• answers must be sent within 15 minutes upon completion of the answering
session. The answer document will not be accepted if it is sent late. Inform
your lecturer if you have network problems
• you are reminded to be honest and to NOT share your answers with other
students.

Section A (4 marks)

1. The main difference between an algorithm and a program is

a. algorithms are written for humans but programs are written for a
computer.
b. the language that is used to write algorithms are usually informal
languages, but programs are written in programming languages
c. algorithms only have one instruction, but programs can have many
instructions
d. mathematical calculations cannot be done in an algorithm, like a
computer program

2. In the Program Development Life Cycle, writing a program in the C++


language is done during the

a. analysis phase
b. design phase
c. implementation phase
d. testing phase

1|Page
3. These are good characteristics of computer programs, EXCEPT

a. giving instructions to the user when asking for input data


b. giving variables names that are suitable to their data
c. having good spacing and indentation
d. writing comments for every line of code

4. What is the value of variable num after the assignment statement is


executed?

int num = 10;


int x = 12;

num = x / num * 5;

a. 0.24
b. 7.2
c. 7
d. 5

Section B (26 marks)

Question 1

Given the following formula, show the equivalent C++ expression:

𝐴𝐵 + 𝐶
𝐷 √𝐸 − 𝐹

Answer:
(pow(A,B) + C) / (D * sqrt(E – F))

red part – 1 mark


green part – 1.5 marks

2.5 marks

2|Page
Question 2

Write a complete C++ program based on this flowchart, to calculate the


commission earned by a salesperson in selling a type of item.

BEGIN

input price,
quantity,
commission rate

calculate
commission = price x
quantity x commission rate

output
commission

END

5 marks

3|Page
#include <iostream> 0.5 marks
using namespace std;

int main()
{
double price, commRate, commission; 1 mark
int quantity;

cout<<”Enter price of item: “; 1.5 marks


cin>>price;

cout<<”Enter quantity sold: “;


cin>>quantity;

cout<<”Enter commission rate: “;


cin>>commRate;

commission = price * quantity * commRate; 1 mark

cout<<”The commission is RM” << commission; 1 mark

4|Page
Question 3

Trace the following program segment and show its output:

data1 = 95;
data2 = 120;
cout<<”First data: “<< data1 <<” second data: “<< data2<<endl;
data1 = data1 + data2;
data2 = data1 * 2;
cout<<”First data: “<< data1 <<” second data: “<< data2<<endl;
data2++;
data1 = data2 % 5;
cout<<”Second data: “<< data2 <<” first data: “<< data1<<endl;
5.5 marks

Answer

First data: 95 second data: 120 1 mark


First data: 215 second data: 430 2 marks
Second data: 431 first data: 1 2.5 marks

Question 4

Tokwan wants to hire a lawn care worker to cut the grass in his yard. The pay rate
is RM2.50 per square meter. The lawn area is the shaded area in this diagram:

You are to help Tokwan by writing a program to calculate the total wages that is
payable to the lawn care worker. The program will the size (area) of the lawn (in
squares metre) and the total wages. (Note: The size of the curved area on the
left side of the house is half of a circle)

5|Page
a. Identify the input data for this problem
2 marks

Answer

Input data:
1. the width and length of the house (s1, s2) 1 mark
2. the width and length of the land 1 mark

b. Draw a design of the expected output screen.


2 marks

Answer

Enter the width and length of the land: aaa bbb


Enter the width and length of the house: ccc ddd

The size of the lawn is xxx metre square


The total wages is RM ????

6|Page
c. Write a main function to solve this problem
9 marks

Answer:

int main()
{
const double PAYRATE = 2.5; 0.5 marks
const double PI = 3.14;

double width, length, s1, s2; 1.5 marks


double houseArea, landArea, lawnArea, totalWages;

cout<<” Enter the width and length of the land: “; 1.5 marks
cin>>width>>length;

cout<<” Enter the width and length of the house: “; 1 mark


cin>>s1>>s2;

houseArea = width*length + 0.5 * PI * s1 * s1; 2 marks


landArea = width * length;
lawnArea = landArea – houseArea;

totalWages = lawnArea * PAYRATE; 1 mark

Output: 1.5 marks

cout<<” The size of the lawn is “<< lawnArea<<” metre square”<<endl;


cout<<” The total wages is RM “<< totalWages<<endl;

7|Page

You might also like