BIT 123 C++ Questions 22-23

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

TAMALE TECHNICAL UNIVERSITY

FACULTY OF APPLIED SCIENCES AND TECHNOLOGY


DEPARTMENT OF COMPUTER SCIENCE
END OF SECOND SEMESTER EXAMINATIONS, 2022/2023 ACADEMIC YEAR
CLASS BTECH Information Technology I (Full Time & Part Time)
COURSE CODE & TITLE BIT 123 – Programming in C++
DATE DURATION 2 Hours, 30 Minutes
LECTURER Yakubu, Abdul-Wahab Nawusu (PhD)
GENERAL INSTRUCTIONS This paper comprises THREE(3) sections; A, B, and C. Please answer all
questions in sections A and B on the question paper. Answer section C in your
answer booklet. Enter your Matric No. & Booklet No. below.

STUDENT MATRIC NUMBER:


B T I T 2 2 BOOKLET NO.

SECTION A: 20 MARKS (½ MARK EACH)


Answer all questions in this section by circling IN INK and only ONCE your choice.

1) C++ is? 5) A ________is a graphical way of depicting an


A. A machine language algorithm.
B. An assembly language. A. Pseudocode
C. A high-level language B. Programming language
D. Both machine and high-level language. C. Defining diagram
2) The C++ language was developed by _________ D. Flowchart
A. Bjarne Stroustrup 6) Which of the following is/are valid C++
B. Dennis Ritch comments? SELECT all that are valid.
C. James Gosling A. // I am a comment
D. Guido van Rossum B. /* I am a comment */
3) Which of the following is not a key component of C. // I am a comment //
object-oriented programming? D. / I am a comment /
A. Inheritance 7) How are preprocessor directives declared in C++?
B. Encapsulation A. Using $
C. Polymorphism B. Using *
D. Concurrency C. Using #
4) In processing a C++ program, ____________is D. Using _
required to move executable file into main memory 8) Selection in C++ is done with all of the following
for execution? EXCEPT?
A. Preprocessor A. if statement
B. Compiler B. while statement
C. Linker C. if-else statement
D. Loader D. if-else-if statement
Page 1|6 2022/23, SEMESTER II
9) Given that 𝑎 = -3 and 𝑏 = 0, evaluate 𝑎%3>=𝑏. 16) _____________operators are used to combine
A. true Boolean expressions.
B. false A. Arithmetic
C. Both true and false B. Mathematical
D. Neither true nor false C. Relational
10) Translate the following statement in C++: If the D. Logical
17) Which of the following statements is true about
value of temperature is between 20.0 and 40.0,
the logical operator ||?
output “Very cold!”. A. It returns true if both of its operands are true
A. if(20.0 <= temperature <=40.0) B. It returns true if one of its operands is true
cout<<”Very cold!”;
C. It returns true if at least one of its operands
B. if(temperature <=20.0 &&
temperature<=40.0) cout<<”Very cold!”; is true
C. if(temperature >20.0 || temperature<40.0) D. It always returns true regardless of the value
cout<<”Very cold!”; of its operand.
D. if(temperature >=20.0 && 18) Using the Dev-C++ IDE, which is the command
temperature<40.0) cout<<”Very cold!”; to compile a C++ source code?
11) Which of the following loops will execute the A. ALT + F9
body of the loop even if the condition B. F9
controlling the loop is initially false? C. ALT + F10
A. for loop D. F10
B. while loop 19) What result is printed by this block of code?
C. do while loop int x = 7;
D. None of the above int y = 2.5;
12) In a program to compute the average temperate int z = x/y;
of a particular day, what data type will you use cout<<z-1;
to represent the average temperature?
A. int A. 2
B. float B. 2.8
C. char C. 3
D. bool D. 3.8
13) Which of the operators in the expression, 20) Which is true about variable initialization in
12 + 3 ∗ (5 + 100/2), will be evaluated first? C++?
A. + A. It communicates the name of the variable in
B. * the program.
C. / B. It indicates how the information will be
D. Any of the operators represented in memory.
14) What is the total memory allocation for the
C. It specifies the kind of information and set
array ‘a’ declared and initialized below?
of operations to be performed.
int a [] = {100, 50, 0, -50, -100};
D. It specifies a starting value to a variable
A. 5 bytes
B. 20 bytes
C. 40 bytes 21) In C++, the index of the first element in an
D. 10 bytes array is always ________.
15) Assigning values to variables in C++ is possible
in all of the following ways except? A. n
A. = B. -1
B. == C. 0
C. += D. 1
D. %=
Page 2|6 2022/23, SEMESTER II
22) __________is a C++ function that checks 25) What result is printed if the following C++
the length of a string. code is returned?
A. len()
B. sizeof() 1. #include <iostream>
C. length() 2. using namespace std;
D. count() 3. int main()
4. {
23) What result is printed by this block of code?
5. int x = 3;
1. int n= 21, a=3; 6. int y = x / -2;
2. if(n>16) 7. int z = x % -2;
3. { 8. cout << y << z;
4. if (n>32) 9. return 0;
5. cout<< (n+ 5); 10. }
6. else
7. cout<< (n/3);
8. } A. -1 1
9. else B. 1 -1
10. { C. Nothing is outputted
11. if (n<−10) D. It reports a syntax error
12. cout<< (a∗2);
13. else
26) What result is printed if the following C++
14. cout<< (a−3);
15. } code is returned?

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]

1. ___________________________words have special meaning in the C++ language.

2. The _______________________function is the entry point into any given C++ program.

3. A loop becomes infinite loop if a condition never becomes _____________________.

4. An ________________________is a collection data item all of which are of the same type.

5. A _________________________is a block of codes that perform a task when it is called.

PART II: Write the following as C++ statements: [1 MARKS EACH]

1. Declare a 10-element array called balance of type double………………………………………………


2. Output the content of a variable, height …………………………………………………………………

3. Assign the value 9.8 to the floating -point constant, acceleration…………………………………………

4. Check if the value of 𝒙 is the same as the value of 𝒚……………………………………………………..

5. Declare an integer variable, salary, with an initial value of 20.……………………………………………

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++). …………………….………

………………………………………………………………………………………………………………

8. Specify the University name as a comment in C++. ………………………………………………………

………………………………………………………………………………………………………………

9. Insert the header file to allow for keyboard input and output to the screen ……………………………..…

………………………………………………………………………………………………………………

10. Display the decimal value, 0.3453 with a precision of 2. …………………………………………………

………………………………………………………………………………………………………………

Page 5|6 2022/23, SEMESTER II


SECTION C: 20 MARKS (10 MARKS EACH)

INSTRUCTION: Answer ANY TWO (2) questions from this section in your Answer Booklet.

QUESTION ONE (1) [10 MARKS]


The volume of a cylinder is the amount of space there is inside a cylinder. In order to find the volume of a cylinder
you first need to find the area of the circular area of the cross section and multiply it by the height.
a) Your task is to write a C++ program that computes the volume (v) of a cylinder given the following
formula:
𝑉 = 𝜋𝑟 2 ℎ

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]

QUESTION TWO (2) [10 MARKS]


New Life College gives fee discount to students for the 2022/2023 academic year based on the table below:

Payment Week Discount %


Before the 4th week 50%
Between the 4th and 6th week 25%
After the 6th week Nil

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.

QUESTION THREE (3) [10 MARKS]


Develop a C++ program to calculate a student’s grade average for one semester. The letter grades should be
entered and the grade average printed out. An A is equivalent to 4 grade points, a B is 3 grade points; a C is 2
grade points, a D is 1 grade point, and an F is zero grade points. Assume that there are 6 courses in a semester.

Page 6|6 2022/23, SEMESTER II

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