0% found this document useful (0 votes)
27 views24 pages

C++ Programming Exam Questions Guide

Pyq oop 2018 to 2023
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views24 pages

C++ Programming Exam Questions Guide

Pyq oop 2018 to 2023
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

22316

23124
3 Hours / 70 Marks Seat No.

Instructions – (1) All Questions are Compulsory.

(2) Answer each next main Question on a new page.

(3) Illustrate your answer with neat sketches wherever


necessary.

(4) Figures to the right indicate full marks.

(5) Assume suitable data, if necessary.

(6) Mobile Phone, Pager and any other Electronic


Communication devices are not permissible in
Examination Hall.

Marks

1. Attempt any FIVE of the following: 10


a) Differentiate between C and C++. (Any two points)
b) Give the syntax of class.
c) Explain any four applications of OOP.
d) Give the syntax and use of fclose( ) function.
e) Explain inline member function.
f) Explain the input operator in C++.
g) Explain reference and dereference operators w.r.t. pointer.

P.T.O.
22316 [2]
Marks
2. Attempt any THREE of the following: 12
a) Explain the rules for naming variables in C++. (Any four points)
b) Explain the access specifiers in C++.
c) What is inheritance? Give different types of inheritance.
d) Write a C++ program to find out whether the given number
is even or odd (taking input from keyboard).

3. Attempt any THREE of the following: 12


a) Write a C++ program to find the area of rectangle using class
rectangle which has following details –
i) Accept length and breadth from the user.
ii) Calculate the area
iii) Display the result.
b) Explain multilevel inheritance with an example.
c) Write a C++ program to define structure student having data
members name, roll no., age. Accept and display data for one
student.
d) Write a C++ program for write into a file using file operations.

4. Attempt any THREE of the following: 12


a) Write a C++ program to copy data from one file to another.
b) Differentiate between compile time polymorphism and run time
polymorphism. (Any four points)
c) Explain the characteristics of Friend function.
d) Write a program to declare a class measure having data
members add1, add2 and add3. Initialize the data members using
constructor and store their addition in third data member using
function and display the addition.
e) Differentiate between constructor and destructor in C++.
(Any four points)
22316 [3]
Marks
5. Attempt any TWO of the following: 12
a) Write a C++ program to implement multiple inheritance as
shown in Figure No. 1. Accept and display data of test marks
and sport’s marks using object of class ‘result’.

Fig. No. 1
b) Describe ‘this’ pointer in C++ with an example.
c) Write a program to declare a class ‘employee’ containing data
members ‘emp-id’ and ‘salary’. Accept and display this data
for 10 employees.

6. Attempt any TWO of the following: 12


a) Explain the rules of virtual function.
b) Explain virtual base class with an example.
c) Write a program to declare a class ‘item’ containing data
members as ‘item_name’, ‘code’, ‘price’. Accept and display
the information for one object using pointer to that object.
22316
22223
3 Hours / 70 Marks Seat No.

Instructions – (1) All Questions are Compulsory.


(2) Answer each next main Question on a new page.
(3) Illustrate your answers with neat sketches wherever
necessary.
(4) Figures to the right indicate full marks.
(5) Assume suitable data, if necessary.
(6) Mobile Phone, Pager and any other Electronic
Communication devices are not permissible in
Examination Hall.
Marks

1. Attempt any FIVE of the following: 10


a) Demonstrate the static and dynamic initialization of variable.
b) Write the syntax for declaration of a class.
c) State the characteristics of static member function.
d) State different types of visibility mode in inheritance.
e) Give the syntax for constructor in derived classes.
f) Define polymorphism with it’s types.
g) Define file with it’s operations.

2. Attempt any THREE of the following: 12


a) State the features of object oriented programming.
b) Explain overloaded constructor with suitable example.
c) Write a program on single inheritance.
d) Illustrate this pointer with example.

P.T.O.
22316 [2]
Marks
3. Attempt any THREE of the following: 12
a) Write a program to print first n natural numbers and their
sum using for loop.
b) Compare static and non-static data members. (any four points)
c) State any four rules for virtual functions.
d) Write a program for get and put functions.

4. Attempt any THREE of the following: 12


a) Explain the structure of C++ program.
b) List any four properties of constructor function.
c) Illustrate the concept of virtual base class with suitable example.
d) State the advantages of pointer.
e) Write a program for closing a file.

5. Attempt any TWO of the following: 12


a) State the use of scope resolution operator and explain it with
example.
b) Write a program to show object as function argument.
c) Write a program on hybrid inheritance.

6. Attempt any TWO of the following: 12


a) State the difference between constructor and destructor.
(any six points)
b) Explain abstract class with suitable example.
c) Write C++ program to overload binary operator ‘+’ to concatenate
two strings.
22316
21222R
3 Hours / 70 Marks Seat No.

Instructions – (1) All Questions are Compulsory.


(2) Answer each next main Question on a new page.
(3) Illustrate your answers with neat sketches wherever
necessary.
(4) Figures to the right indicate full marks.
(5) Assume suitable data, if necessary.
(6) Mobile Phone, Pager and any other Electronic
Communication devices are not permissible in
Examination Hall.

Marks

1. Attempt any FIVE of the following: 10


a) State any Four application of oop.
b) Explain user defined datatype with example.
c) Describe use of scop resolution operator with example.
d) Define constructors and it's type.
e) Explain concept of pointer with example.
f) Explain file modes used to perform file operations.
g) List all stream classes used in stream operation.

2. Attempt any THREE of the following: 12


a) Develop a c++ program to print Fibonacci series.
b) Develop a c++ program for multilevel inheritance.
c) Develop a c++ program for accept data from user to calculate
percentage for 5 subject and display grade according to percentage.
d) Develop c++ program to open and read content of file also
write “object oriented” string in file and close it. P.T.O.
22316 [2]
Marks
3. Attempt any THREE of the following: 12
a) Describe structure of c++ program.
b) Explain with suitable example Friend Function.
c) Describe all visibility modes and effects with example.
d) Differentiate between compile time polymorphism and Runtime
polymorphism.

4. Attempt any THREE of the following: 12


a) Develop a c++ program to implement inheritance shown in
following fig.

b) Develop a c++ program to print sum of 10 no. using array.


c) Develop a c++ program to perform arthmatic operation using
pointer.
d) Develop a c++ program to create structure student with data
member Name, Roll No., percentage accept and display data
for 5 student using structure.
e) Develop c++ program to check Detection of end of file.
22316 [3]
Marks
5. Attempt any TWO of the following: 12
a) Define class book with following Data member and member
function for 10 book.
Data Member Member Function
1. B - name
→ getdata ( )
2. B - author
→ put data ( )
3. B - price
b) Develop a c++ program to implement virtual Base class.
c) Explain rules of operator overloading and overload ‘+’ operator
to concatenate two string.

6. Attempt any TWO of the following: 12


a) Develop a c++ program for constructor with default argument
and use of destructor.
b) Describe Function overloading with suitable program.
c) Develop c++ program to implement inheritance shown in fig.
22316
21222
3 Hours / 70 Marks Seat No.
15 minutes extra for each hour

Instructions – (1) All Questions are Compulsory.


(2) Answer each next main Question on a new page.
(3) Illustrate your answers with neat sketches wherever
necessary.
(4) Figures to the right indicate full marks.
(5) Assume suitable data, if necessary.
(6) Mobile Phone, Pager and any other Electronic
Communication devices are not permissible in
Examination Hall.
Marks

1. Attempt any FIVE of the following. 10

a) List two memory management operators available in C++.


Also state its use.

b) List c++ stream classes along with their function. (any two
classes)

c) Write any four applications of OOP.

d) Define constructor. List types of constructor

e) Explain ios :: app and ios :: in flags

f) Write any two characteristics of friend function.

g) State the need of virtual function in C++.

P.T.O.
22316 [2]
Marks
2. Attempt any THREE of the following. 12
a) State and describe characteristics of object oriented
programming.
b) Write a C++ program to declare a class college with name
and code. Derive a new class as student with members as
name. Accept and display details of one student along with
college data.
c) Write a C++ program to declare a class student with data
members as roll no and name. Declare a constructor to
initialize data members of class. Display the data.
d) Describe concept of type casting using suitable example.

3. Attempt any THREE of the following. 12


a) Write a C++ program to declare a class mobile having data
members as price and model number. Accept and display the
data for Ten objects.
b) Write a C++ program to copy the contents of a source file
student [Link] to a destination file student [Link] using file
operations.
c) Describe visibility modes and their effects used in inheritance.
d) Differentiate between compile time and run time polymorphism.

4. Attempt any THREE of the following. 12


a) Describe the concept of virtual base class with example.
b) Write a C++ program to overload add function to add two
integer numbers and two float numbers.
c) Write a C++ program to find and display the smallest
number of an array.
d) Write a C++ program to declare a structure book with
members as book id and name. Accept and display data
of five books using array of structure.
e) Describe constructor with default arguments with an example.
22316 [3]
Marks
5. Attempt any TWO of the following. 12
a) i) Define pointer operator and address operator with
example.
ii) Write a C++ program to declare a class train with
members as train no and name. Accept and display
data for one object of train. Use pointer to object to
call functions of class.
b) Write a C++ program to implement following inheritance:
Refer Fig. No. 1.
Science Maths
Phy. marks Alg. marks
Chy. marks Geo. marks

Result
Total
Fig. No. 1.
Accept and display total of one object of result.
c) (Hint : class 1 contains m1 and class 2 contains m2)
Write a C++ program to declare two classes with data
members as m1 and m2 respectively. Use friend function
to calculate average of two (m1, m2) marks and display it.

6. Attempt any TWO of the following. 12


a) Write any two characteristics of static data member. Write
C++ program to count number of objects created with the
help of static data member.
b) Write a C++ program to overload “+” operator so that it
will perform concatenation of two strings. (Use class get
data function to accept two strings)

P.T.O.
22316 [4]
Marks
c) Write a program to implement inheritance as shown in
figure No. 2. Assume suitable member function
Staff
Code

Teacher Officer
Subject Grade

Fig. No. 2.
Accept and display data of one Teacher and one Officer.
22316
11920
3 Hours / 70 Marks Seat No.

Instructions – (1) All Questions are Compulsory.


(2) Illustrate your answers with neat sketches wherever
necessary.
(3) Figures to the right indicate full marks.
(4) Assume suitable data, if necessary.
(5) Mobile Phone, Pager and any other Electronic
Communication devices are not permissible in
Examination Hall.
Marks

1. Attempt any FIVE of the following: 10


a) State the difference between OOP and POP.
b) What is a class? Give its example.
c) What is multilevel inheritance? Draw the diagram to show
multilevel inheritance. using classes with data member and
member function.
d) Explain use of scope resolution operator.
e) Write two properties of static member function.
f) Explain virtual base class with suitable example.
g) Give syntax and use of fclose  (  ) function.

P.T.O.
22316 [2]
Marks
2. Attempt any THREE of the following: 12
a) Describe memory allocation for objects.
b) Write a program to implement single inheritance from the
following Refer Figure No. 1.

Fig. No. 1

c) Write any four benefits of OOP.


d) Describe ‘this’ pointer with an example.

3. Attempt any THREE of the following: 12


a) Write the applications of object oriented programming.
b) State the rules for writing destructor function.
c) What is inheritance? Give different types of inheritance.
d) What are the rules for virtual function?
22316 [3]
Marks
4. Attempt any THREE of the following: 12
a) What is parameterized constructor?
b) Write a program to sort an 1-d array in ascending order.
c) Explain the friend function with proper example.
d) Write a program to count the number of lines in file.

5. Attempt any TWO of the following: 12


a) Write a program to declare a class ‘student’ having data
members as ‘stud_name’ and ‘roll_no’. Accept and display
this data for 5 students.
b) State and explain the visibility modes used in inheritance.
c) Write a program to declare a class ‘book’ containing data
members as ‘title’, ‘author-name’, ‘publication’, ‘price’.
Accept and display the information for one object using
pointer to that object.

P.T.O.
22316 [4]
Marks

6. Attempt any TWO of the following: 12


a) Write a program that copies contents of one file into another
file.
b) Write a program to implement the following hierarchy using
suitable member functions. Refer Figure No. 2.

Fig. No. 2

c) Write a program to overload the ‘—’ unary operator to negate


the values.
22316
21819
3 Hours / 70 Marks Seat No.

Instructions – (1) All Questions are Compulsory.


(2) Illustrate your answers with neat sketches wherever
necessary.
(3) Figures to the right indicate full marks.
(4) Assume suitable data, if necessary.
(5) Mobile Phone, Pager and any other Electronic
Communication devices are not permissible in
Examination Hall.

Marks

1. Attempt any FIVE of the following: 10


a) State the use of cin and cout.
b) Describe derived class with example.
c) State use of scope resolution operator.
d) Define class and object.
e) Write the use of ios : : in and ios : : out.
f) Describe use of static data member.
g) Give meaning of following statements:
int   *  ptr, a  =  5;
  ptr   =  & a ;
cout <<   *  ptr ;
cout << ( * ptr) + 1;

P.T.O.
22316 [2]
Marks
2. Attempt any THREE of the following: 12
a) Write a ‘C++’ program to find factorial of given number using
loop.
b) Write a C++ program to declare a class COLLEGE with
members as college code. Derive a new class as STUDENT
with members as studid. Accept and display details of student
along with college for one object of student.
c) Write a C++ program to find smallest number from two numbers
using friend function. (Hint : use two classes).
d) Differentiate between run time and compile time polymorphism.

3. Attempt any THREE of the following: 12


a) Write a C++ program to create a class STUDENT
The data members of STUDENT class.
Roll_No
Name
Marks
b) Accept data for five students and display it. Write a C++
program to displya sum of array elements of array size n:
c) Describe with examples, passing parameters to base class
constructor and derived class constructor by creating object of
derived class.
d) Describe how memory is allocated to objects of class with
suitable diagram.
22316 [3]
Marks
4. Attempt any THREE of the following: 12
a) Write a program to implement multiple inheritance as shown
in following Figure No. 1:
Class : Subject 1 Class : Subject 2
data mem : m1 data mem : m2

Class : Result
data mem : Total

Fig. No. 1
Accept and display data for one object of class result.
b) Describe following terms: Inheritance, data abstraction, data
encapsulation, dynamic binding.
c) State and describe visibility modes and its effects used in
inheritance.
d) Write a C++ program to count number of spaces in text file.
e) Differentiate between contractor and destructor.

5. Attempt any TWO of the following: 12


a) (i) Write any three rules of operator overloading.
(ii)Write a program in C++ to overload unary ‘_’ operator
to negate values of data members of class.
b) Write a C++ program to append data from abc . txt to xyz . txt
file.
c) Write a C++ program to declare a class student with members
as roll no, name and department. Declare a parameterised
constructor with default value for department as ‘CO’ to initialize
members of object. Initialize and display data for two students.

P.T.O.
22316 [4]
Marks
6. Attempt any TWO of the following: 12
a) (i) Describe structure of C++ program with diagram.
(ii) Write a C++ program to add two 3  ×  3 matrices and
display addition.
b) Write a program to swap two integers using call by reference
method.
c) Write a C++ program to implement following in heritance.
Refer Figure No. 2.

Class : College Student


student id
Data mem : College_code

Class : test Class : sports


data mem : percentage data mem : grade

Class : Result

Fig. No. 2
Accept and display data for one object of class result (Hint :
use virtual base class).
22316
11819
3 Hours / 70 Marks Seat No.

Instructions – (1) All Questions are Compulsory.


(2) Answer each next main Question on a new page.
(3) Illustrate your answers with neat sketches wherever
necessary.
(4) Figures to the right indicate full marks.
(5) Assume suitable data, if necessary.
(6) Use of Non-programmable Electronic Pocket
Calculator is permissible.
(7) Mobile Phone, Pager and any other Electronic
Communication devices are not permissible in
Examination Hall.

Marks

1. Attempt any FIVE of the following: 10


a) State any four object oriented languages.
b) Describe use of protected access specifier used in the class.
c) Differentiate between OOP and POP.
d) Write any two characteristics of destructor.
e) Describe meaning of following:
(i) ios : : in
(ii) ios : : out

P.T.O.
22316 [2]
Marks
f) Give output for following code:
class student
{
int roll no;
char name [14];
} s[6];
void main( )
{
cout <<sizeof(s);
}
g) Write syntax to define a derived class.

2. Attempt any THREE of the following: 12


a) Write a C++ program to accept array of five elements, find
and display smallest number from an array.
b) Write a C++ program to declare a class ‘College’ with data
members as name and college code. Derive a new class
‘student’ from the class college with data members as sname
and roll no. Accept and display details of one student with
college data.
c) Write a C++ program to declare a class ‘circle’ with data
members as radius and area. Declare a function getdata to
accept radius and putdata to calculate and display area of circle.
d) With suitable example, describe effect of ++ and – – operators
used with pointer in pointer arithmetic.

3. Attempt any THREE of the following: 12


a) Write a C++ program to declare a class addition with data
members as x and y. Initialize value of x and y with
constructor. Calculate addition and display it using function
‘display.’
b) With suitable diagram describe structure of C++ program.
c) Describe the concept of virtual base class with suitable example.
d) Describe use of static data member in C++ with example.
22316 [3]
Marks
4. Attempt any THREE of the following: 12
a) Write a C++ program to implement inheritance shown in
following figure:
Class : Teacher Class : Student
datamember : Name datamember : sname
empid rollno.

Class : Info

Accept and display data of one teacher and one student using
object of class ‘Info’.
b) Write a C++ program to print multiplication table of 7.
(example: 7 × 1 = 7 ..... 7 × 10 = 70)
c) Write a C++ program to swap two integer numbers and swap
two float numbers using function overloading.
(Hint : overload swap function)
d) Write a C++ program to count number of spaces present in
contents of file.
e) Write a C++ program to find greatest number among two
numbers from two different classes using friend function.

5. Attempt any TWO of the following: 12


a) Write a C++ program to overload binary operator ‘+’ to
concatenate two strings.
b) Write a C++ program to write ‘Welcome to poly’ in a file.
Then read the data from file and display it on screen.
c) Write a C++ program to declare a class ‘Account’ with data
members as accno, name and bal. Accept data for eight
accounts and display details of accounts having balance
less than 10,000.

P.T.O.
22316 [4]
Marks
6. a) Attempt any TWO of the following: 12
(i) Write a C++ program to find whether the entered number
is even or odd.
(ii) Write a C++ program to declare a structure employee
with members as empid and empname. Accept and
display data for one employee using structure variable.
b) Write a C++ program to implement following inheritance.

Class : Employee
Data : empid
Member : empcode

Class : Programmer Class : Manager


Datamember : Skill Datamember : department

Accept and display data for one programmer and one manager.
Make display function virtual.
c) Write C++ program for following multilevel inheritance.
Class : Carmanufacturer
datamember : Name

Class : Carmodel
datamember : Model name,
Model no.

Class : Car
datamember : Car no., colour

Accept and display data for one car with all details.

Common questions

Powered by AI

C++ uses three primary access specifiers: public, protected, and private. Public members are accessible from outside the class, protected members are accessible within the class and by derived class instances, and private members are only accessible within the class itself. These specifiers enforce encapsulation by controlling how class data and functions can be accessed or modified. They also influence inheritance, as the visibility of base class members is affected by the inheritance specifier (public, protected, or private) chosen for the derived class .

C++ is an object-oriented programming language, which means it supports the concept of classes and objects, while C is a procedural programming language which does not support these concepts. Additionally, C++ supports function overloading and operator overloading, whereas C does not .

Virtual functions in C++ allow for polymorphic behavior by enabling the correct function to be called in the presence of inheritance. For a function to be virtual, it must be declared in the base class using the keyword 'virtual'. Derived classes can override this function, and when called via a base class pointer or reference, the overridden function for the object’s actual type (rather than the type of the pointer/reference) is executed. The necessity of virtual functions arises in scenarios requiring dynamic (runtime) polymorphism, such as implementing interfaces or abstract classes .

Compile-time polymorphism in C++, also known as static polymorphism, is achieved through method overloading and operator overloading. The decision of which method/operator to invoke is made at compile time. Runtime polymorphism, or dynamic polymorphism, is achieved using virtual functions and inheritance, allowing the decision to depend on the runtime type of the object. The significant difference lies in that static polymorphism is faster as it does not involve overhead associated with virtual table lookups, whereas dynamic polymorphism provides more flexibility and extensibility at the cost of performance due to the necessary indirection and dynamic type checking .

Polymorphism allows C++ to present a unified interface for different data types and operations, achieved through function overloading and operator overloading at compile-time, and through virtual functions for dynamic polymorphism at runtime. This enhances the object-oriented nature of C++ by supporting code reuse and the extension of existing systems without modifying them. By allowing objects to be processed differently based on their type, polymorphism increases flexibility and maintainability of the code .

In C++, a pointer is a variable that holds the memory address of another variable, allowing for direct access or modification of the variable. References, however, are aliases for variables. Unlike pointers, once a reference is initialized to a variable, it cannot be changed to refer to another variable. Pointers can be reassigned and can perform arithmetic operations, whereas references cannot. The dereference operator (*) is used to access the value at the address stored in a pointer .

Friend functions in C++ have the capability to access private and protected members of a class. They are not members of the class they are declared in and can be declared by using the keyword 'friend' within the class. Although friend functions provide certain benefits like enabling operator overloading for binary operators, they break the encapsulation of the class by accessing its non-public data directly .

Inline functions in C++ are advantageous as they reduce function call overhead by replacing the function call with the function code during compile time. This optimization can improve performance in time-critical applications. However, they increase executable size if overused, especially with large functions, as the function body is duplicated each time it is called. The compiler may also ignore inline requests under certain conditions, such as when recursion is involved, limiting their applicability .

Multilevel inheritance in C++ involves a class being derived from another derived class, creating a chain of inheritance. For example, a class ‘Carmodel’ can derive from class ‘Carmanufacturer’, and another class 'Car' can derive from ‘Carmodel’. This allows for a hierarchical structure, where functionality is incrementally built up across layers. This type of inheritance is important as it mimics real-world scenarios and promotes code reuse. However, it increases complexity and can lead to issues like the diamond problem if not handled carefully with concepts like virtual inheritance .

The 'this' pointer in C++ non-static member functions is an implicit, constant pointer that holds the address of the object invoking the function. It disambiguates instance variables from local variables or parameters with identical names within functions and allows for method chaining by returning the object itself. In addition, 'this' is used to return references to the calling object for certain methods, useful in operator overloading and method chaining designs .

You might also like