Test CSC415 - March-Aug 2023
Test CSC415 - March-Aug 2023
INSTRUCTIONS TO CANDIDATES
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.:
Part A 10
Part B 25
Part C 15
TOTAL MARKS 50
PART A
1. The preprocessor directive tells the complier to insert another file into ______________.
A. object code
B. source file
C. program
D. object file
A. i, ii
B. ii, iii
C. i, iii
D. iii, iv
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
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?
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
i) Declare two variables as integer. Assign the value of 5 into a first variable.
______________________________________________________________________
(0.5 mark)
______________________________________________________________________
(0.5 mark)
iii) Combine the content of string variable firstname and string variable lastname.
______________________________________________________________________
(1 mark)
________________________________________________________________
________________________________________________________________
________________________________________________________________
CONFIDENTIAL 6 CS/MAY 2023/CSC415/TEST 1
iv. cout<< "num2 % num1 = " << num2 % num1 << endl;
________________________________________________________________
(4 marks)
i. z = -b + [b2 – 4ac]
2a
___________________________________
ii. a = ( k2 + m ) (n )
(k-x)m
___________________________________
iii. y = 2xy + ¼ - 3a
b
__________________________________
(6 marks)
QUESTION 2
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
#include<iostream.h>
void main ()
{
char grade;
if (grade == 'A')
cout<<"Excellent!"<<endl;
else
cout<<"Invalid grade"<<endl;
}
CONFIDENTIAL 8 CS/MAY 2023/CSC415/TEST 1
(5 marks)
PART C
QUESTION 1
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.
(15 marks)
CONFIDENTIAL 10 CS/MAY 2023/CSC415/TEST 1