c++ paper
c++ paper
c++ paper
Semester: V
1. Write your Roll No. on the top immediately on receipt of this question paper.
2. Section A is compulsory.
3. Attempt any four questions from Section B.
4. Parts of a question must be answered together.
Section A
i) int x; (2)
x+3=x;
cout<<x<<y;
e) When we should use an inline function? Explain with suitable example. (4)
f) Rewrite the following code with the while loop: (3)
int main()
{
char letter = 'a';
Q2. (a) What is copy constructor? Explain it with suitable example. (4)
(b) Rewrite the following code fragment using a switch statement: (3)
if(ch == 'C' II ch == 'c')
countC++;
elseif(ch =='A' II ch =='a')
countA++;
elseif(ch =='J' II ch == 'j')
countJ++;
else
cout << "Error- Not C, A, or J \n";
c) Create a base class Person, a derived class Employee, and a further derived class (8)
Manager. Show how each class inherits attributes and methods from its parent class.
Define main function to print all information about an object of class Manager.
Program should accept the number of lines n as the input from the user.
b) Write a C++ program to handling of multiple exception types. Use try and catch (6)
blocks to catch different types of exceptions, such as out_of_range and
invalid_argument. The program should handle these exceptions appropriately and
display an error message based on the exception type.
c) Write a function that tests the value of an integer num. If the num = 10 then square (4)
num. If num =9 , read a new value into num. if num=4 or num = 5, multiply num by
50 and print the result. Use if statement.
Q4. a) Write a function getData() that takes an integer, a float, and a string as arguments. (5)
Overload the function so that the program prints the correct data type (Integer, Float,
or String) with the value passed.
b) What is a Class Template in C++? Write a C++ program to implement a simple (5)
calculator that performs basic operations (addition, subtraction, multiplication, and
division) using a class template.
c) Write a C++ program to count the number of words in a file (5)
Q5. a) Create a base class Student with a virtual function getMarks(). Then, create two (8)
derived classes Faculty and Admin that override the getMarks() function. In the
main() function, Use runtime polymorphism by calling getMarks() through base
class pointers.
b) Write a function to show the difference between call by value and call by reference (3)
while swapping two numbers
Q6. a) Explain the difference between multiple inheritance and multilevel inheritance in (5)
C++. Provide examples to illustrate both concepts.
b) Create a class Complex that represents a complex number with two integer data (10)
members: real and imag. Implement the following:
• A default constructor that initializes the complex number to 0.
• A parameterized constructor that allows initialization of the complex
number with specific real and imag values.
• A function addComplex() to add two complex numbers and return the result
as a new complex number.
• A function display() to display the result of complex number.
Write a program to create a class by adding two complex numbers and displaying
the result.
Q7. a) Write a recursive function to get the nth Fibonacci number. (5)
b) Define a class Rectangle with two data members length and width, and a function (5)
setDimensions() that sets the values of these members. Use this pointer to refer to
the members.