BIT 123 C++ Questions 22-23
BIT 123 C++ Questions 22-23
BIT 123 C++ Questions 22-23
A. 26 1. #include <iostream>
B. 7 2.
C. 42 3. using namespace std;
4.
D. 18 5. int main() {
24) What result is printed if the following C++ 6. int i = 1;
code is returned? 7.
1. #include <iostream> 8. while (i <= 5) {
2. using namespace std; 9. cout << i << " ";
3. int main() 10. ++i;
4. { 11. }
12.
5. int x = -1;
13. return 0;
6. int y = 2; 14. }
7.
8. if(x > y)
A. 12345
9. {
B. 1 2 3 4 5
10. cout << "y is greater";
11. } C. 2345
12. else D. 2 3 4 5
13. { 27) Using the same code above, what happens if
14. cout << "x is greater"; line 10 is removed?
15. } A. It runs and produces the same results
16. } B. It runs and produces nothing
A. y is greater C. It runs infinitely
B. x is greater D. It will fail to compile
C. 12 is greater
D. -1 is greater
Page 3|6 2022/23, SEMESTER II
Consider the following C++ code and use it to 32) Which line defines an array initialization?
answer the questions that follows: A. Line 4
1. #include<iostream> B. Line 7
2. using namespace std; C. Line 15
3. D. Line 21
4. double getAverage(int arr[], int size); 33) Which header file will you use to read and write
5. to a file?
6. int main () {
A. #include<file>
7. int balance[5] = {1, 2, 3, 4, 5};
B. #include<readfile>
8. double avg;
C. #include<writefile>
9.
10. avg = getAverage(balance, 5 ) ; D. #include<fstream>
11. 34) To use mathematical function in C++, you need
12. cout<<"Average value is: “<< avg ; to use the _______________header file.
13. } A. #include<math>
14. B. #include<maths>
15. double getAverage(int arr[], int size) { C. #include<cmath>
16. int i; D. #include<cmaths>
17. double avg; 35) What is the type of the parameter of the abs
18. double sum = 0; function in C++?
19. A. int
20. for (i = 0; i < size; ++i) {
B. float
21. sum += arr[i];
C. double
22. }
D. string
23.
24. avg = sum / size;
25. Answer true of false for the questions 36) to 40)
26. return avg;
27. } 36) All C++ programs must have a function named
main.
28) How many functions are used in the program? A. True
A. 0 B. False
B. 1
C. 2 37) In general, a compiled program is slower to
D. None execute compared with interpreted program.
29) Balance[3] corresponds to which element? A. True
B. False
A. 1
B. 2 38) Recursive functions are ones which may call
C. 3 themselves over and over again.
D. 4 A. True
30) What is total memory allocation for the array B. False
‘balance”?
A. 5 bytes 39) A do while loop may not execute at all
B. 10 bytes depending on what test condition is stated.
C. 15 bytes A. True
D. 20 bytes B. False
31) What is the output of the program? 40) A C++ variable name may be a reserve word.
A. 3 A. True
B. 4
B. False
C. 5
D. Error message
Page 4|6 2022/23, SEMESTER II
SECTION B: 20 MARKS
PART I: Provide short responses to complete the following questions. [2 MARKS EACH]
2. The _______________________function is the entry point into any given C++ program.
4. An ________________________is a collection data item all of which are of the same type.
6. Prompt a user to enter a character value for the variable key from the keyboard.…………………………
………………………………………………………………………………………………………………
7. Output statement to print the course title (which is Programming in C++). …………………….………
………………………………………………………………………………………………………………
………………………………………………………………………………………………………………
9. Insert the header file to allow for keyboard input and output to the screen ……………………………..…
………………………………………………………………………………………………………………
………………………………………………………………………………………………………………
INSTRUCTION: Answer ANY TWO (2) questions from this section in your Answer Booklet.
The program should output the value of the volume of the cylinder alongside the SI unit (cm3).
[8 MARKS]
b) What will be the output of the program, for the volume of this cylinder with radius of the base 7cm and
the perpendicular height 10cm. [2 MARKS]
Develop a C++ program that takes the week a student pays fees and computes the discount due him or her. The
program should output the fee charged, the discount percent and the discount amount on separate lines with
appropriate descriptions. Assume the fee for the academic year is Ghc 4425.00.