Test 1 Csc415 Mac 2021 Skema
Test 1 Csc415 Mac 2021 Skema
INSTRUCTIONS TO CANDIDATES
1. This question paper consists of two (3) parts PART A (10 Questions)
PART B ( 2 Questions)
PART C (1 Question)
A. i, ii, iii, iv
B. i, iii, ii, iv
C. i, iii, iv, ii
D. iii, iv, i, ii
A. 1total
B. #salaryOfTheMonth
C. Total amount
D. thisIsTheLongVariable
A. Logic error
B. Syntax error
C. Run time error
D. Debugging error
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
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
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?
NO ANSWERS NO ANSWERS
1 C 6 B
2 D 7 C
3 A 8 A
4 D 9 D
5 C 10 A
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;
vi. Add the content of NUM1 with 100 and store the result into SUM
Answer: SUM = NUM1 + 100;
(6 marks)
Answer:
int main()
{ double balance, amt;
string name; 0.5
char 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;
}
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;
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