0% found this document useful (0 votes)
1K views10 pages

Test CSC415 - March-Aug 2023

The document outlines a test for a computer programming fundamentals course. It provides instructions, details three parts (A, B, C) containing multiple choice and code writing questions, and covers topics like variables, conditional statements, expressions and functions. It tests students on their understanding of basic C++ concepts and programming logic.

Uploaded by

Annur
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)
1K views10 pages

Test CSC415 - March-Aug 2023

The document outlines a test for a computer programming fundamentals course. It provides instructions, details three parts (A, B, C) containing multiple choice and code writing questions, and covers topics like variables, conditional statements, expressions and functions. It tests students on their understanding of basic C++ concepts and programming logic.

Uploaded by

Annur
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 CS/MAY 2023/CSC415/TEST 1

UNIVERSITI TEKNOLOGI MARA


TEST 1

COURSE : FUNDAMENTALS OF COMPUTER PROBLEM


SOLVING
COURSE CODE : CSC415
DATE : 22ND MAY 2023
TIME : 1 1/2 HOURS

INSTRUCTIONS TO CANDIDATES

1. This paper consists of THREE (3) parts: PART A (10 questions)


PART B (3 questions)
PART C (1 question)

2. Answer ALL questions from PART A, PART B, and PART C in answer paper.
Start each question on a new page.

Name/UiTM No.:

Program/Group.:

Lecturer Name.:

QUESTION FULL MARK MARK

Part A 10

Part B 25

Part C 15

TOTAL MARKS 50

DO NOT TURN THIS PAGE UNTIL YOU ARE TOLD TO DO SO


This examination paper consists of 10 printed pages
CONFIDENTIAL
CONFIDENTIAL 2 CS/MAY 2023/CSC415/TEST 1

PART A

Answer all the questions below.

1. The preprocessor directive tells the complier to insert another file into ______________.
A. object code
B. source file
C. program
D. object file

2. Missing a semicolon ' ; ' in a C++ program is an example of a ______________.


A. logic error
B. run-time error
C. syntax error
D. semantic error

3. Which of the following program development life cycle phase is CORRECT?


A. design -> coding -> testing -> evaluate -> maintenance
B. analyze -> design -> coding -> testing -> maintenance
C. design -> analyze -> testing -> evaluate -> maintenance
D. design -> coding -> maintenance -> evaluate -> testing

4. Which of the statements below are FALSE


i. Every variable must be declared before it can be used in a program.
ii. A compiler is a program that translates the source code into machine language.
iii. The purpose of default in a switch statement is to skip the switch statement
iv. The strcpy() function is in the iomanip.h

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

5. Given the following program fragment:

bool even = false;


if(even)
{
cout<<"It is even!";
}

Which of the following statements is TRUE?


A. The code displays It is even!
B. The code displays nothing.
C. The code is wrong. You should replace if(even) with if(even == true)
D. The code is wrong. You should replace if(even) with if(even = true)
CONFIDENTIAL 3 CS/MAY 2023/CSC415/TEST 1

6. What is the output of the following code fragment?

int a = 3;
int b = 20;
if(b > 10)
{
int a = 5;
b = b + a;
cout<<a<<" "<<b<<endl;
}
cout<<a<<" "<<b<<endl

A. 3 20
B. 3 25
3 25
C. 5 25
3 25
D. 5 25
3 20

7. Which of the following identifiers are VALID?


i. 10mins
ii. hisName&herName
iii. studAdd
v. NewSalaryInRM

A. i and ii
B. iii and iv
C. i, ii and iii
D. All of the above

8. By using the variable declarations below, which of the following Boolean expressions is
FALSE? int x=5, y=15, z=40, t=-20.

A. (x*10-y+10+t) < z
B. t<x && !(y>=z || z<=x)
C. (z>10 && y<10) || x>t
D. (y==z || z>x) && !(y>10)

9. What is the result after the execution of the following code if p is 7, q is 10 and r is 15?

if ((p > q) || (p <= r ))


{ p = p + 1;
q = p + 3;
}
else
r = r + 1;
CONFIDENTIAL 4 CS/MAY 2023/CSC415/TEST 1

A. p = 8,q = 11, r= 15
B. p = 7, q = 10, r= 16
C. p = 8, q = 10, r= 15
D. p = 7, q = 10, r= 15

10. Which of the following segment code will return "good" as the answer if the value of
p is 2?
A. if (p >1)
cout << "try again";
else
cout << "good";

B. if (p > 0)
{
if (p == 2)
cout << "good";
}
else
cout << "try again";

C. if (p < 2)
cout << "good";
else
cout << "try again";

D. if( p == 0)
cout << "good";
else
if (p <= 1)
cout << "good" ;
else
cout << "try again";

Answers :

1. 6.
2. 7.
3. 8.
4. 9.
5. 10.
CONFIDENTIAL 5 CS/MAY 2023/CSC415/TEST 1

PART B

QUESTION 1

a) Write C++ statement(s) to perform the following tasks.

i) Declare two variables as integer. Assign the value of 5 into a first variable.

______________________________________________________________________
(0.5 mark)

ii) Declare a variable named address , its length of variables is 50.

______________________________________________________________________
(0.5 mark)

iii) Combine the content of string variable firstname and string variable lastname.

______________________________________________________________________
(1 mark)

b) Given the following declarations :

const double pi = 3.142;


int num1 = 5, num2 = 11;
double num3 = 5.5;

Evaluate each of the following C++ expression :

i. cout << 55 % num1 + 10 * 2 / num3 << endl;

________________________________________________________________

ii. cout << int (num2 * 3 - 13 % 2 + pi ) << endl;

________________________________________________________________

iii. cout << num1 + (num2 - pi) * 3 / num3 <<endl;

________________________________________________________________
CONFIDENTIAL 6 CS/MAY 2023/CSC415/TEST 1

iv. cout<< "num2 % num1 = " << num2 % num1 << endl;

________________________________________________________________
(4 marks)

c) Write C++ expressions for the following mathematic expressions.

i. z = -b + [b2 – 4ac]
2a

___________________________________

ii. a = ( k2 + m ) (n )
(k-x)m

___________________________________

iii. y = 2xy + ¼ - 3a
b

__________________________________
(6 marks)

QUESTION 2

Write a C++ program segment to accomplish each of the following tasks:

a) Prompt a user to enter a number between 0 and 100 and store the value into variable
score. Display an error message if user input is invalid number. (4 marks)
CONFIDENTIAL 7 CS/MAY 2023/CSC415/TEST 1

b) Prompt a user to enter two whole numbers into two variables of type int and then
outputs both the whole number part and the remainder when the first number is divided
by the second. Use operators / and %. (4 marks)

QUESTION 3

Convert the following if..else statement to switch statement :

#include<iostream.h>

void main ()
{
char grade;

cout<<"Grade A = 80-100 "<<endl;


cout<<"Grade B = 60-79 "<<endl;
cout<<"Grade C = 50-59 "<<endl;
cout<<"Grade F = 0-49 "<<endl;
cout<<"Enter your grade : ";
cin>>grade;

if (grade == 'A')
cout<<"Excellent!"<<endl;

else if (grade == 'B')


cout<<"Well done"<<endl;

else if (grade == 'C')


cout<<"You are passed"<<endl;

else if (grade == 'F')


cout<<"Better try harder"<<endl;

else
cout<<"Invalid grade"<<endl;

cout<<"Your grade is "<<grade<<endl;

}
CONFIDENTIAL 8 CS/MAY 2023/CSC415/TEST 1

(5 marks)

PART C

QUESTION 1

Ahmad is a lecturer who teaches in Computer Science program. He receives a bundle of


books from a distributor. The distributor gives him some commission for selling the books
based on books’ title. The following below is the information of the books:

Book Title Price per book Commission


C++ Programming RM75.50 1.5%
Introduction to Object Oriented RM69.90 1.8%
Programming
System Analysis and Design RM77.00 2%

In order to ease in managing the business, he wants to develop a program. Based on the
above details, write a complete program using C++ language of the program. The program
must consist:

a) Prompt the input to get number of books sold for each books’ title.

b) Calculate the total price of all of books sold depends on the price per book and the numbers
of book have sold.

c) Calculate the total commission will be received by Ahmad.


CONFIDENTIAL 9 CS/MAY 2023/CSC415/TEST 1

d) Display the information at the end of code as following below:

My Selling Book Information System

The Number of Book Sold:

C++ Programming : xxx


Introduction to Object Oriented Programming: xxx
System Analysis and Design: xxx

Total Payment RM: xxxx.xx


My Commission RM: xxx.xx

(15 marks)
CONFIDENTIAL 10 CS/MAY 2023/CSC415/TEST 1

END OF QUESTION PAPER

You might also like