Mid Semester Exams C++ September 2023
Mid Semester Exams C++ September 2023
(GCTU)
SEPTEMBER 2023
TOTAL MARKS = 50
1. The most efficient data type for a variable that stores the letter C is the _______ data type
a) Character
b) Double
c) Float
d) Long Integer
4. A class D can be derived from a class C, which is derived from a class B, which is
derived from a class A
a) True
b) False
5. To hide a data member from the program, you must declare the data member in the
_______ section of the class
a) Conceal
b) Confidential
c) Hidden
d) Private
1. A )Define and explain the use of constructors and destructors in C++. Provide an example of a
class with a constructor and a destructor. 10 marks
B) Write a C++ program to find the factorial of a non-negative integer using recursion 10
MARKS
B) Write a C++ program that uses a function to check if a given number is prime or not.
The program should ask the user to input a positive integer and then call the function to
check if it's a prime number or not. If the number is prime, the program should output
"The number is prime." If the number is not prime, the program should output "The
number is not prime."
3. A) Using functions create a c++ program that Prints Prime numbers between 1 to 100 (6
marks)
B) State 4 benefits of programming in the object oriented approach.(8 marks)
C) Demonstrate how friend functions are implemented(6marks)
4. A) Define compile time polymorphism, and provide a code fragment that implements
FUNCTION OVERLOADING as one of the types of this concept in C++. Explain the
implemented concept in detail(10 marks)
5. A) Discuss the concept of inheritance in C++. Provide an example of a base class and a
derived class with a clear explanation of how inheritance is achieved. Explain with example
codes, any 4 of the various types of inheritance supported in C ++. (20 marks)