0% found this document useful (0 votes)
37 views10 pages

Test 1 Csc415 Mac 2021 Skema

This document is a test paper for the course 'Fundamentals of Computer Problem Solving' at Universiti Teknologi Mara, dated May 27, 2021. It consists of three parts: multiple-choice questions, coding tasks, and a complete C++ program assignment. The test assesses students' understanding of programming concepts and their ability to write code in C++.

Uploaded by

anrdyana181
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
0% found this document useful (0 votes)
37 views10 pages

Test 1 Csc415 Mac 2021 Skema

This document is a test paper for the course 'Fundamentals of Computer Problem Solving' at Universiti Teknologi Mara, dated May 27, 2021. It consists of three parts: multiple-choice questions, coding tasks, and a complete C++ program assignment. The test assesses students' understanding of programming concepts and their ability to write code in C++.

Uploaded by

anrdyana181
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/ 10

CONFIDENTIAL MAC2021/CSC415

UNIVERSITI TEKNOLOGI MARA


TEST 1

COURSE : FUNDAMENTALS OF COMPUTER PROBLEM


SOLVING
COURSE CODE : CSC415
SEM : MAC – JUL 2021
DATE : 27 MAY 2021
TIME : 3 HOURS
STUDENT NAME : ……………………………………………………...
UiTM ID NO. : …………….............. GROUP : T5CS2641B
LECTURER : PUAN NORIZAN MOHAMAD

INSTRUCTIONS TO CANDIDATES

1. This question paper consists of two (3) parts PART A (10 Questions)
PART B ( 2 Questions)
PART C (1 Question)

2. Answer ALL questions in the section provided in this question paper.

© Hak Cipta Universiti Teknologi MARA 1 CONFIDENTIAL


CONFIDENTIAL MAC2021/CSC415

PART A (20 MARKS)

1. The correct sequence in writing a computer program is _________.

i. Identify the input, process, output of the program


ii. Compile and test the program
iii. Design the algorithm
iv. Write the coding using a high level language

A. i, ii, iii, iv
B. i, iii, ii, iv
C. i, iii, iv, ii
D. iii, iv, i, ii

2. Which of the following is a VALID identifier?

A. 1total
B. #salaryOfTheMonth
C. Total amount
D. thisIsTheLongVariable

3. The following program contains a ___________ error.

A. Logic error
B. Syntax error
C. Run time error
D. Debugging error

© Hak Cipta Universiti Teknologi MARA 2 CONFIDENTIAL


CONFIDENTIAL MAC2021/CSC415

4. The possible value for variable response is ‘Y’ or ‘N’. What is the data type that is suitable for
variable response?

A. int
B. string
C. char
D. bool

5. Which of the following statement is FALSE?

A. An input statement is used to input data from user.


B. An assignment statement is used to change the value of a variable.
C. Algorithm is another name for a computer program.
D. Programming is the process of writing a program.

6. Which of the following statements is TRUE ?

A. C++ compiler considers the variable Total as the same with TOTAL or total.
B. All variables must be declared before they can be used.
C. A comment will cause the system to print anything that is after the // symbol on the screen
during execution.
D. The operator % may be used with variable of type int and double.

7. Given that x=10, y=2, z=3 and m=4, what will be printed on the screen?

A. 2
B. 6
C. 122
D. y

© Hak Cipta Universiti Teknologi MARA 3 CONFIDENTIAL


CONFIDENTIAL MAC2021/CSC415

8. Given the following code fragment :

What is the output for the above fragment?

A. 0 1
Yes

B. 0 1
No

C. 20 30
True

D. 0 1 True

9. Given that people is 40, what is the updated value of price after the code segment is
executed?

A. 40
B. 50
C. 70
D. 80

10. Which of the following C++ conditions is used to test whether weight is in between 50 and 90
inclusive?

A. if (weight >= 50 && weight <= 90)


B. if (weight <= 50 && weight >= 90)
C. if (50 weight 90 )
D. if (weight <= 50 || weight >= 90)
© Hak Cipta Universiti Teknologi MARA 4 CONFIDENTIAL
CONFIDENTIAL MAC2021/CSC415

ANSWERS FOR PART A

NO ANSWERS NO ANSWERS

1 C 6 B

2 D 7 C

3 A 8 A

4 D 9 D

5 C 10 A

© Hak Cipta Universiti Teknologi MARA 5 CONFIDENTIAL


CONFIDENTIAL MAC2021/CSC415

PART B (30 MARKS)

QUESTION 1 (10 marks)

a) Write appropriate C++ statement for the following task:

i. Declare a variable price and initialize price to store the price of RM 30.00
Answer: float price = 30.00;

ii. Declare a variable age and initialize age to store an age value of 55 years old
Answer: int age = 55;

iii. Declare a variable rate and initialize rate to store the value 2.5%
Answer: float rate = 0.025;

iv. Store the value B to location grade


Answer: grade = ‘B’;

v. Display the value stored in location named TOTAL


Answer: cout<< “The value in TOTAL is ”<<TOTAL;

vi. Add the content of NUM1 with 100 and store the result into SUM
Answer: SUM = NUM1 + 100;

(6 marks)

© Hak Cipta Universiti Teknologi MARA 6 CONFIDENTIAL


CONFIDENTIAL MAC2021/CSC415

b) Given the following declaration statements

int no1 = 235, no2 = 2, no3 = 3, no5;


double no4= 3.75;

What is the output of the following statement?

i. cout << (no1 % 4 * sqrt (64) / no2);


(2 marks)
Answer: 12

ii. cout << ( 3/2 * no2 – pow (no3,4));


(2 marks)
Answer: -79

© Hak Cipta Universiti Teknologi MARA 7 CONFIDENTIAL


CONFIDENTIAL MAC2021/CSC415

QUESTION 2 (10 marks)

Write a complete C++ program based on the following flowchart.


(10 Marks)

© Hak Cipta Universiti Teknologi MARA 8 CONFIDENTIAL


CONFIDENTIAL MAC2021/CSC415

Answer:

int main()
{ double balance, amt;
string name; 0.5
char choice;

cout << "Enter name and balance ";


getline(cin, name);
cin>> balance; 1.5
cout <<" Enter choice A, B, C ";
cin >> choice;

switch (choice)
{ case 'a': case 'A': cout << name << " your balance is " <<balance;
1
break;
case 'b': case 'B': cout << "Enter amount ";
cin >>amt;
balance = balance + amt; 2
cout << name << " your new balance is " <<balance;
break;
case 'c': case 'C': cout << "Enter amount ";
cin >>amt;
if (amt < balance) Input amt – 0.5
1 { balance = balance - amt; If - 1
cout << name << " your new balance is " <<balance; If (true) – 1
} If (else) – 0.5
else Total - 3
{ cout <<"Amount is not sufficient.";
}
break;
default: cout <<" Invalid choice"; 1

} //switch
cout <<"\n End of program ";
return 0;
}

© Hak Cipta Universiti Teknologi MARA 9 CONFIDENTIAL


CONFIDENTIAL MAC2021/CSC415

PART C (10 MARKS)

Restaurant Makan-Makan Cepat provides the following menu to its customer:

Price for Children (per


Menu Price for Adult (per person)
person)
Western RM10.00 RM6.00
Kampung RM12.00 RM7.50

Write a complete C++ program, which will calculate the amount that a customer has to pay when they
eat at the restaurant. Assume a customer can choose one menu only. The program will input the
choice of menu, number of adult and number of children for each order. Then it displays the total
payment payable by the customer. A discount of 15% is given to the customer when the total payment
is above RM45.00. Display an error if invalid menu is chosen.

#include <iostream>
#include <string.h>
using namespace std;

int main()
{ double amtDue = 0;
int noA=0, noC=0; 0.5
int choice;

cout<< "Enter choice of menu 1/2 ";


cin >> choice; 1.5
cout << "Enter the number of adult and the number of children ";
cin >>noA >> noC;

if (choice == 1) -→ 1
amtDue = noA * 10.00 + noC * 6.00; -→ 1
else
{ if (choice == 2) -→ 1
amtDue = noA * 12.00 + noC * 7.5; -→ 1
else
cout <<"invalid choice"; -→ 1
}
if (amtDue > 45.00) -→ 1
amtDue = 0.85 * amtDue; -→ 1
cout <<"Total amount to be paid is " <<amtDue; -→ 1

cout <<"\n End of program ";


return 0;
}

Overall format + kemas – bonus 1 mark

END OF QUESTION PAPER

© Hak Cipta Universiti Teknologi MARA 10 CONFIDENTIAL

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy