0% found this document useful (0 votes)
11 views67 pages

OOP Paper Analysis

The document analyzes examination papers across three academic sessions (Winter-22, Summer-22, Summer-23) focusing on various topics in object-oriented programming, including principles, classes, inheritance, pointers, polymorphism, and file operations. It provides a breakdown of questions and marks allocated for each topic, highlighting changes in question structure and marking schemes over the sessions. The analysis includes specific questions from the papers, demonstrating the types of knowledge and skills being assessed.

Uploaded by

Vaishali Patil
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)
11 views67 pages

OOP Paper Analysis

The document analyzes examination papers across three academic sessions (Winter-22, Summer-22, Summer-23) focusing on various topics in object-oriented programming, including principles, classes, inheritance, pointers, polymorphism, and file operations. It provides a breakdown of questions and marks allocated for each topic, highlighting changes in question structure and marking schemes over the sessions. The analysis includes specific questions from the papers, demonstrating the types of knowledge and skills being assessed.

Uploaded by

Vaishali Patil
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
You are on page 1/ 67

Examination Paper Analysis

Topic Winter-22 Summer-22 Summer-23


Name of Topic
No.
Question Marks Question Mark Question Marks
1.(a) 2
1.(a)
1.(b) 2 1.(a) 2 2
2.(a)
1.(c) 2 1.(c) 2 4
3.(a)
2.(a) 4 2.(a) 4 4
Principal of object oriented 3.(d)
1 2.(c) 4 2.(d) 4 4
programming 4.(a)
3.(a) 4 4.(c) 4 4
5.(a)
4.(b) 4 4.(d) 4 6
4.(d) 4
Total: 26 Total: 20 Total: 24
1.(d) 2
1.(f) 2 1.(b) 2
2.(b) 4 1.(c) 2
1.(d) 2
2.(b) 4 2.(b) 4
3.(b) 4
3.(a) 4 3.(b) 4
2 Classes and objects 5.(a) 6
3.(c) 4 4.(b) 4
6.(a) 6
4.(e) 4 5.(b) 6
5.(c) 6 6.(a) 6
6.(a) 6
Total: 18 Total: 36 Total: 28
2.(b) 4 4.(a) 4 1.(d) 2
3.(c) 4 5.(b) 4 1.(e) 2
4.(a) 4 6.(c) 6 2.(c) 4
3 Extending classes using inheritance 5.(b) 6 4.(c) 4
6.(c) 6 5.(c) 6
6.(b) 6
Total: 24 Total: 14 Total: 24
1.(e) 2 1.(g) 2 1.(f) 2
3.(d) 4 3.(d) 4 2.(d) 4
4 Pointers and polymorphism in c++ 4.(c) 4 4.(b) 4 3.(c) 4
5.(c) 6 5.(a)(i) 3 4.(d) 4
6(b) 6 5.(b)(ii) 3 6.(c) 6
Examination Paper Analysis

6(b) 6

Total: 22 Total: 22 Total: 20


1.(f) 2 1.(b) 2 1.(g) 2
1.(g) 2 1.(e) 2 4.(e) 4
5 File operations 2.(d) 4 3.(b) 4
4.(e) 4
Total: 12 Total: 8 Total: 6
Examination Paper Analysis

Exam Unit No Question no as per MSBTE paper Marks


Year and Name

Summer- Unit 1 Q1 a) List two memory management operators available in C++. Also state its use 2
2022 Q1 c) Write any four applications of OOP 2
Q2 a) State and describe characteristics of object-oriented programming. 4
Q2 d) Describe concept of type casting using suitable example. 4
Q4 c) Write a C++ program to find and display the smallest number of an array. 4
Q4 d) Write a C++ program to declare a structure book with members as book id and name. Accept and display data 4
of five books using array of structure.
Winter- Unit 1 Q1 a) State any Four application of oop. 2
2022 Q1 b) Explain user defined datatype with example. 2
Q1 c) Describe use of scop resolution operator with example 2
Q2 a) Develop a c++ program to print Fibonacci series. 4
Q2 c) Develop a c++ program for accept data from user to calculate percentage for 5 subject and display grade 4
according to percentage.
Q3 a) Describe structure of c++ program. 4
Q4 d) Develop a c++ program to create structure student with data member Name, Roll No., percentage accept and 4
display data for 5 student using structure.
Q4 b) Develop a c++ program to print sum of 10 no. using array. 4

Summer- Unit 1 1.(a) Demonstrate the static and dynamic initialization of variable. 2
2023 2.(a) State the features of object oriented programming. 4
3.(a) Write a program to print first n natural numbers and their sum using for loop. 4
3.(d) Write a program for get and put functions. 4
4.(a) Explain the structure of C++ program. 4
5.(a) State the use of scope resolution operator and explain it with example. 6

Summer- Unit 2 Q1 d) Define constructor. List types of constructor 2


2022 Q 1 f) Write any two characteristics of friend function. 2
Q2 b) Write a C++ program to declare a class college with name and code. Derive a new class as student with members 4
as name. Accept and display details of one student along with college data.
Q2 c) Write a C++ program to declare a class student with data members as roll no and name. Declare a constructor 4
to initialize data members of class. Display the data.
Q3 a) Write a C++ program to declare a class mobile having data members as price and model number. Accept and 4
display the data for Ten objects.
Q3 c) Describe visibility modes and their effects used in inheritance. 4
Q4 e) Describe constructor with default arguments with an example. 4
6
Examination Paper Analysis
Q5 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
Q6 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
Winter- Unit 2 Q 1 d) Define constructors and it's type. 2
2022 Q 3 b) Explain with suitable example Friend Function. 4
Q 6 a) Develop a c++ program for constructor with default argument and use of destructor. 6
Summer- Unit 2 1.(b) Write the syntax for declaration of class. 2
2023 1.(c) State the characteristics of static member function. 2
2.(b) Explain overloaded constructor with suitable example. 4
3.(b) Compare static and non static data members. 4
4.(b) List any four properties of constructor function. 4
5.(b) Write a program to show object as function argument. 6
6.(a) State the difference between constructor and destructor (any six points) 6
Summer- Unit 3 Q4 a) Describe the concept of virtual base class with example. 4
2022 Q5 b) Write a C++ program to implement following inheritance: Refer Fig. No. 1 6

Accept and display total of one object of result.


Q6 c) Write a program to implement inheritance as shown in figure No. 2. Assume suitable member function 6

Accept and display data of one Teacher and one Officer.


Examination Paper Analysis
Winter Unit 3 Q 2 b) Develop a c++ program for multilevel inheritance. 4
2022 Q 3 c) Describe all visibility modes and effects with example. 4

Q 5 b) Develop a c++ program to implement virtual Base class. 6


Q 6 c) Develop c++ program to implement inheritance shown in fig. 6

Summer- Unit 3 1.(d) State different types of visibility mode in inheritance. 2


2023
Examination Paper Analysis
1.(e) Give the syntax for constructor in derived classes. 2
2.(c) Write a program on single inheritance. 4
4.(c) Illustrate the concept of virtual base class with suitable class. 4
5.(c) Write a program on hybrid inheritance. 6
6.(b) Explain abstract class with suitable example. 6
Summer- Unit 4 Q1 g) State the need of virtual function in C++. 2
2022 Q3 d) Differentiate between compile time and run time polymorphism. 4
Q4 b) Write a C++ program to overload add function to add two integer numbers and two float numbers. 4
Q5 a) i) Define pointer operator and address operator with example. 3
Q5 b) ii) Write a C++ program to declare a class train with members as train no and name. Accept and display data for 3
one object of train. Use pointer to object to call functions of class.
Q6 b) Write a C++ program to overload “+” operator so that it will perform concatenation of two strings. (Use class get 6
data function to accept two strings)
Winter Unit 4 Q 1 e) Explain concept of pointer with example. 2
2022 Q 4 c) Develop a c++ program to perform arithmetic operation using pointer. 4
Q 5 c) Explain rules of operator overloading and overload ‘+’ operator to concatenate two string. 6
Q 6 b) Describe Function overloading with suitable program. 6
Q 3 d) Differentiate between compile time polymorphism and Runtime polymorphism. 4
Q 5 a) Define class book with following Data member and member function for 10 book. 6
Data Member Member Function
1. B - name → getdata ( )
2. B - author → put data ( )
3. B - price
Summer Unit 4 1.(f) Define polymorphism with its types. 2
2023 2.(d) Illustrate this pointer with example. 4
3.(c) State any four rules for virtual functions. 4
4.(d) State the advantages of pointer. 4
6.(c) Write C++ program to overload binary operator ‘+’ to concatenate two strings. 6
Summer- Unit 5 Q1 b) List c++ stream classes along with their function. (any two classes). 2
2022 Q1 e) Explain ios :: app and ios :: in flags 2
Q3 b) Write a C++ program to copy the contents of a source file student 1.txt to a destination file student 2.txt using file 4
operations.
Winter Unit 5 Q 1 f) Explain file modes used to perform file operations. 2
2022 Q 1 g) List all stream classes used in stream operation. 2
Q.2 d)Develop c++ program to open and read content of file also write “object oriented” string in file and close it. 4
Q 4 e) Develop c++ program to check Detection of end of file. 4
Summer Unit 5 1.(g) Define file with it’s operations. 2
2023 4.(e) Write a program for closing a file. 4
Examination Paper Analysis

Exam Unit No Question no as per MSBTE paper Marking


Year and Name Scheme

Summer Unit 1 Q1 a) List two memory management operators available in C++. Also state its use. 2
2022 Solution: (Any 2 )
new operator:
The new operator in C++ is used for dynamic storage allocation. This operator can be used to create object of
any type.
The general syntax of new operator in C++ is as follows:
Pointer-variable = new datatype;
In the above statement, new is a keyword and the pointer variable is a variable of type datatype.
For example:
int *a=new int;
delete operator:
The delete operator in C++ is used for releasing memory space when the object is no longer needed. Once a new
operator is used, it is efficient to use the corresponding delete operator for release of memory.
The general syntax of delete operator in C++ is as follows:
delete pointer-variable;
Q1 c) Write any four applications of OOP. 2
Solution: (Any 4 )
Development of editors, compilers.
• Developing data bases.
• Developing communication systems and complex real-time applications.
• Simulation and Modeling.
• AI and Expert system
Q2 a) State and describe characteristics of object oriented programming. 2
Solution: (Any 4 )
• Emphasis in data rather than procedures.
• Programs are divided into objects.
• Data structures are design such that they characterize object.
• Functions that operate on the data are tied together in the data structure called object.
• Data is hidden and cannot be accessed by external functions.
• Object may communicate with each other through functions.
• New data and functions can be easily added whenever necessary.
• It follows Bottom-Up approach.
Examination Paper Analysis
Q2 d) Describe concept of type casting using suitable example.
Solution: Type-casting* is the conversion of one data type into another.
There are two ways to perform type-casting in C++:
• Implicit Casting
• Explicit Casting

• Implicit Casting:
In implicit casting, the compiler will convert the values automatically. The conversion takes place in the order of
precedence, i.e., the data type is converted into a data type of higher precedence. It also ensures a minimum loss
of data. Below is the precedence order of the data types.
For example, if we take an expression where we are performing some operation on an int and float data type, the
int value will automatically be converted to a float data type due to its higher precedence.
Example:
#include <iostream.h>
using namespace std;
int main() {
int a = 18;
char b = 'S';
a = a * b;
float c = a / 5.0;
cout << "a = " << a << endl;
cout << "b = " << b << endl;
cout << "c = " << c << endl;
return 0;
}
• Explicit Casting:
In explicit casting, the user needs to physically convert one data type into another. The syntax for using this casting
is:
(data_type) variable_name;
Example:
#include <iostream>
using namespace std;
int main()
{
float x = 28.5;
float a = (int) x - 12;
cout << "a = " << a;
return 0;
}
Examination Paper Analysis
Q4 c) Write a C++ program to find and display the smallest number of an array. 4(correct logic
Solution: 4 marks)
#include<iostream.h>
#include <conio.h>
int main()
{
int a[100], count, i, min;
cout << "Enter Number of Elements in Array\n";
cin >> count;
cout << "Enter " << count << " numbers \n";
// Read array elements
for(i = 0; i < count; i++){
cin >> a[i];
}
min = a[0];
// search num in inputArray from index 0 to elementCount-1
for(i = 0; i < count; i++){
if(a[i] < min){
min = a[i];
}
}
cout << "Minimum Element\n" << min;
return 0;
}
Q4 d) Write a C++ program to declare a structure book with members as book id and name. Accept and display 4(correct logic
data of five books using array of structure. 4 marks)
Solution:
# include <iostream.h>
struct Book
{
char name[40];
int bookid;
};
void main()
{
Book b[5];
int i;
for ( i=0; i<5 ; i++)
{
cout << “Enter Book name “;
Examination Paper Analysis
cin >> b[i].name;
cout<< ”Enter Book ID”;
cin>> b[i].bookid;
}
cout << “DETAILS OF BOOK: “ <<endl;
for ( i=0; i<5 ; i++)
{ cout<< ”NAME : “ << b[i].name <<endl
cout<< ” BOOK ID : “<< b[i].bookid <<endl;
}
}
Winter- Unit 1 Q1 a) State any Four application of oop. 2
2022 Solution : Four Applications of OOP: (Any 4)
• Development of editors, compilers
• Developing data bases
• Developing communication systems and complex real-time applications.
• Simulation and modeling.
• AI and Expert system
Q1 b) Explain user defined datatype with example. 2
Solution : (1/2 marks
User-Defined DataTypes:The data types that are defined by the user are called the derived datatype or user- each)
defined derived data type.These types include:
• Class – A User-defined data type that holds data members and functions whose access can be specified
as private, public, or protected. It uses the ‘class’ keyword for defining the data structure.
• Structure – A structured data type is used to group data items of different types into a single type. For Eg.
Structure can be Address, in which it further contains information such as Flat number, Building name,
street, city, state, pin code, etc. It is defined by using the ‘struct’
• Union – Union is a type of data structure where all the members of that union share the same memory
location. If any changes made in the Union, it will be visible to others as well. The ‘union’ keyword is used
to define this type of User-defined data type.
• Enumeration – It helps assign names to integer constants in the program. The keyword ‘enum’ is used. It
is used to increase the readability of the code.
• Typedef – Typedef defines a new name for an existing data type. It does not create a new data class. It
makes code readability easy and gives more clarity to the user.
Q1 c) Describe use of scope resolution operator with example 2
Solution : (Use 1 m and
The scope resolution operator ( :: ) is used for several reasons. For example: If the global variable name is same correct
as local variable name, the scope resolution operator will be used to call the global variable. It is also used to example 1 m)
define a function outside the class and used to access the static variables of class.
#include <iostream>
using namespace std;
Examination Paper Analysis
char a = 'm';
static int b = 50;
int main() {
char a = 's';
cout << "The static variable : "<< ::b;
cout << "\nThe local variable : " << a;
cout << "\nThe global variable : " << ::a;
return 0;
}
Q2 a) Develop a c++ program to print Fibonacci series.
Solution :Fibonacci Series without recursion: 4(correct logic
#include <iostream> 4 marks)
using namespace std;
int main()
{
int n1=0,n2=1,n3,i,number;
cout<<"Enter the number of elements: ";
cin>>number;
cout<<n1<<" "<<n2<<" "; //printing 0 and 1
for(i=2;i<number;++i) //loop starts from 2 because 0 and 1 are already printed
{
n3=n1+n2;
cout<<n3<<" ";
n1=n2;
n2=n3;
}
return 0;
}
Fibonnaci series using recursion in C++
#include<iostream>
using namespace std;
void printFibonacci(int n){
static int n1=0, n2=1, n3;
if(n>0){
n3 = n1 + n2;
n1 = n2;
n2 = n3;
cout<<n3<<" ";
printFibonacci(n-1);
}
Examination Paper Analysis
}
int main(){
int n;
cout<<"Enter the number of elements: ";
cin>>n;
cout<<"Fibonacci Series: ";
cout<<"0 "<<"1 ";
printFibonacci(n-2); //n-2 because 2 numbers are already printed
return 0;
}
Q2 c) Develop a c++ program for accept data from user to calculate percentage for 5 subject and display grade 4
according to percentage. (Correct Logic
Solution : C++ 4 Marks)
#include<iostream>
using namespace std;
int main()
{
int phy,chem,bio,maths,comp;
int total;
float percent;
cout<<"Enter marks of computer";
cin>>phy;
cout<<"enter marks of English";
cin>>chem;
cout<<"enter marks of bio";
cin>>bio;
cout<<"enter marks of maths";
cin>>maths;
cout<<"enter marks of physics";
cin>>comp;
total= phy+chem+bio+maths+comp;
percent=total/5.0;
if(percent>=90)
{
cout<<"Grade=A";
}
else if(percent>=80)
{
cout<<"Grade=B";
}
else if(percent>=70)
Examination Paper Analysis
{
cout<<"Grade=C";
}
else if(percent>=60)
{
cout<<"Grade=D";
}
else if(percent>=40)
{
cout<<"Grade=E";
}
else
{
cout<<"Gread F";
}
}
Q3 a) Describe structure of c++ program. 4
Description: - (diagram 1 m
and
explanation
marks)

1. Include header files


In this section a programmer includes all header files which are required to execute a given program. The most
important file is iostream.h header file. This file defines most of the C++statements
like cout and cin. Without this file one cannot load the C++program.
2. Class Declaration
In this section a programmer declares all classes which are necessary for the given program. The programmer
uses general syntax of creating class.
3. Member Functions Definition
This section allows programmers to design member functions of a class. The programmer can have an inside
declaration of a function or outside declaration of a function.
4. Main Function Program
In this section programmers create objects and call various functions written within various classes.
Examination Paper Analysis
Q4 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. 4(correct logic
#include <iostream> 4 marks)
using namespace std;
struct student
{
char name[50];
int roll;
float marks;
};
int main()
{
student s[5];
int I;
for(i=0;i<5;i++)
{
cout << "Enter information," << endl;
cout << "Enter name: ";
cin >> s[i].name;
cout << "Enter roll number: ";
cin >> s[i].roll;
cout << "Enter marks: ";
cin >> s[i].marks;
}
for(i=0;i<5;i++)
{

cout << "\nDisplaying Information," << endl;


cout << "Name: " << s[i].name << endl;
cout << "Roll: " << s[i].roll << endl;
cout << "Marks: " << s[i].marks << endl;
return 0;
}
}
Q4 b) Develop a c++ program to print sum of 10 no. using array. 4(correct logic
Solution: 4 marks)
#include <iostream>
using namespace std;
int main()
{
int arr[10],;
Examination Paper Analysis
int sum=0;
for(int i=0; i<10; i++)
{
cout<<"Enter number-"<<i+1<<": ";
cin>>arr[i];
}
for(int i=0; i<10; i++)
{

sum =sum+ arr[i];


}
cout<<"Sum of 10 numbers is "<<sum;
}
Summer Unit 1 1.(a) Demonstrate the static and dynamic initialization of variable. 2M
2023 Ans.
Syntax Static
datatype variable_name=value; initialization -
Example - 1M,
int a=5;
Or dynamic
int a; a=5; initialization -
1M
Dynamic initialization
Syntax –
int a;
cout<<”Enter value of variable”;
cin>>variable_name;
Example
int a;
cout<<”Enter value of variable a”;
cin>>a;
Note: Syntax / Example shall be considered
2.(a) State the features of object-oriented programming. 4M
Ans.
Features of Object Oriented Programming are: Any four
features 1M
• Follows bottom-up approach in program design.
each
• Emphasis is on data rather than procedure.
• Programs are divided into what are known as objects.
• Data structures are designed such that they characterize the objects.
Examination Paper Analysis

• Functions that operate on the data of an object are tied together in the data structures.
• Data is hidden and cannot be accessed by external functions.
• Objects may communicate with each other through functions.
• New data and functions can be easily added whenever necessary.

3.(a) Write a program to print first n natural numbers and their sum using for loop. 4M
Ans.
#include<iostream.h>
#include<conio.h> Declaration
void main() 1M, Display of
{ natural
int n, sum = 0; numbers 1M,
clrscr(); Calculate and
cout<< "Enter a positive integer:"; display sum
cin>> n; 2M
cout<<"\nNatural numbers till "<<n<<" numbers are:";
for(inti = 1; i<= n; i++)
{
cout<<i<<" ";
}
cout<<"\n";
for (i = 1; i<= n; i++)
{
sum=sum+i;
}
cout<< "Sum of numbers is = " << sum;
getch();
}

3.(d) Write a program for get and put functions. 4M Correct


Ans. syntax of get():
#include <iostream.h> 2M,
int main() Correct syntax
{ of put(): 2M
int count = 0;
char c;
cout<< "INPUT TEXT\n";
cin.get(c);
Examination Paper Analysis
while (c != '\n')
{
cout.put(c);
count++;
cin.get(c);
}
cout<< "\nNumber of characters = " << count << "\n";
return 0;
}
Note: Any other relevant program shall be considered.
4.(a) Explain the structure of C++ program. 4M
Ans.
General C++ program has following structure:
Correct
diagram 2M
Correct
explanation
2M

Description: -
1. Include header files
In this section a programmer includes all header files which are required to execute a given program. The most
important file is iostream.h header file. This file defines most of the C++statements
like cout and cin. Without this file one cannot load the C++program.
2. Class Declaration
In this section a programmer declares all classes which are necessary for the given program. The programmer
uses general syntax of creating class.
3. Member Functions Definition
This section allows programmers to design member functions of a class. The programmer can have an inside
declaration of a function or outside declaration of a function.
4. Main Function Program
In this section programmers create objects and call various functions written within various classes.
5.(a) State the use of scope resolution operator and explain it with example. 6M
Ans. Explanation
Scope of a variable extends from the point of declaration to the end of the block. 3M Example
A variable declared inside a block is 'local' variable and a variable declared outside block is called as global 3M
variable.
When we want to use a global variable but also has a local variable with same name.
Examination Paper Analysis
To access the global version of the variable, C++ provides scope resolution operator.
Example:-
#include <iostream.h>
char a = 'm';
static int b = 50;
int main() {
char a = 's';
cout<< "The value static variable b is : "<< ::b;
cout<< "\nThe value of local variable a is : " << a;
cout<< "\nThe value of global variable a is : " << ::a;
return 0;
}
Summer Unit 2 Q1 d) Define constructor. List types of constructor . 2
22 Solution: (Definition 1
Definition:A constructor in C++ is a special 'MEMBER FUNCTION' having the same name as that of its class mark and
which is used to initialize some valid values to the data members of an object. It is executed automatically types 1 mark)
whenever an object of a class is created.
Types:
• Default Constructor
• Parameterized Constructor
• Copy Constructor
• Constructor with default value
Q 1 f) Write any two characteristics of friend function. 2
Solution: (Any 2
• A friend function is not in the scope of the class, in which it has been declared as friend. characterstics)
• It cannot be called using the object of that class.
• It can be invoked like a normal function without any object.
• Unlike member functions, it cannot use the member names directly.
• It can be declared in public or private part without affecting its meaning.
• Usually, it has objects as arguments.
Q2 b) Write a C++ program to declare a class college with name and code. Derive a new class as student with 4(correct logic
members as name. Accept and display details of one student along with college data. 4 marks)
Solution:
class college
{ char name[20];
int code;
public: void getdata()
{ cout<<”Enter the college name and code”;
cin>> name>>code;
}
Examination Paper Analysis
void putdata()
{ cout<<”College Name=”<<name;
cout<<”College Code=”<<code;
}
};
class student: public college
{ char name[20];
public:void getdata()
{ college::getdata();
cout<<”Enter student name ” ;
cin>>name;
}
void putdata()
{ college::putdata();
cout<<”Student Name=”<<name;
}
};
void main()
{ student s;
s.getdata();
s.putdata();
getch();
}
Q2 c) Write a C++ program to declare a class student with data members as roll no and name. Declare a 4(correct logic
constructor to initialize data members of class. Display the data. 4 marks)
Solution:
#include<iostream.h>
#include<conio.h>
class student
{
int rollno;
char name[20];
public: student(int r,char n[])
{ rollno =r;
strcpy (name,n);
}
void putdata()
{ cout<<”RollNo=”<<rollno;
cout<<”Name=”<<name;
}
};
Examination Paper Analysis
void main()
{
student s(12,”Sangeeta”);
s.putdata();
getch();
}
Q3 a) Write a C++ program to declare a class mobile having data members as price and model number. Accept 4
and display the data for Ten objects. (correct logic
Solution: 4M)
class mobile
{
float price:
int model_number;
public:
void getdata()
{ cout<< “Enter Mobile price and model number”;
cin>>price>>model_number;
}
void putdata()
{ cout<<”The price of mobile is :”<< price;
cout<<”Model Number of Mobile is :”<< model_number;
}
};
void main()
{ mobile m[10];
int i;
for(i=0;i<10;i++)
{ m[i].getdata();
}
for(i=0;i<10;i++)
{ m[i].putdata();
}
getch();
}
Q3 c) Describe visibility modes and their effects used in inheritance. 4
Solution: (Explanation
1. Public mode: 4M)
In the public mode of inheritance, when a child class is derived from the base or parent class, then the public
member of the base class or parent class will become public in the child class also, in the same way, the protected
member of the base class becomes protected in the child class, and private members of the base class are not
accessible in the derived class.
Examination Paper Analysis
2. Protected mode:
In protected mode, when a child class is derived from a base class or parent class, then both public and protected
members of the base class will become protected in the derived class, and private members of the base class are
again not accessible in the derived class. In contrast, protected members can be easily accessed in the derived
class.
3. Private mode:
In private mode, when a child class is derived from a base class, then both public and protected members of the
base class will become private in the derived class, and private members of the base class are again not
accessible in the derived class.

❖ Member function of a class can access all type of data ( private , protected , public).
❖ Private members are only accessed by member function of a class.
❖ Object of a class can access only public member of a class. They cannot access private or protected
members of a class.
❖ Protected members are accessed only by member function of a class and member function of immediately
derived class.
Q4 e) Describe constructor with default arguments with an example. 4
Solution:A constructor with default arguments means passing default values to arguments. You can call a (correct logic
constructor without passing all its parameter but you have to specify default values when the constructor is 4M)
declared.
Example:
class student
{
int roll_no;
float std_marks;
public:
student(int a=10,float b=50)
Examination Paper Analysis
{
roll_no=a;
std_marks=b;
}
void display()
{
cout<<"Roll no: "<<roll_no<<endl;
cout<<"Marks: "<<std_marks<<endl;
}
};
void main()
{
student s1;
student s2(1,60);
clrscr();
cout<<"\n Output using default constructor arguments:\n";
s1.display();
cout<<"\n Output without using default constructor arguments:\n";
s2.display();
getch(); }

Q5 c) (Hint : class 1 contains m1 and class 2 contains m2) Write a C++ program to declare two classes with data 6
members as m1 and m2 respectively. Use friend function to calculate average of two (m1, m2) marks and display (correct logic
it. 6M)
Solution:

# include <iostream.h>
class test2; // prior declaration of class2
class test1
{
private: float m1;
public: void setdata (float a )
{
m1=a ;
}
friend void average ( test1 ,test2); // function average is a friend of test1
};
class test2
Examination Paper Analysis
{
private: float m2;
public: void setdata (float a)
{
m2=a ;
}
friend void average ( test1 ,test2); // function average is a friend of test1
};
void average ( test1 t1 , test2 t2)
{
float avg;
avg =( t1.m1 + t2.m2 )/2;
cout << avg;
}
void main ()
{
test t1;
test t2;
t1.setdata (34);
t2.setdata (40);
average ( t1 ,t2 ); // friend fun. is invoked like a normal c++ function without any object
}

Q6 a) Write any two characteristics of static data member. Write C++ program to count number of objects created 6
with the help of static data member. (Explanation
Solution: 2M and
Static data members are class members that are declared using static keywords. A static member has certain Program 4M)
special characteristics which are as follows:
• Only one copy of that member is created for the entire class and is shared by all the objects of that class,
no matter how many objects are created.
• It is initialized before any object of this class is created, even before the main starts.
• It is visible only within the class, but its lifetime is the entire program.
Syntax:
static data_type data_member_name;
#include<iostream>

using namespace std;

class counter
Examination Paper Analysis
{ private: static int count;

public: counter()

{ count++;

void display()
{ cout<<"The number of objects created are: "<<count;
}
};
int counter::count=0;
int main()
{ counter c1;
counter c2;
counter c3;
c2.display();
}
Winter- Unit 2 Q 1 d) Define constructors and it's type. 2
2022 Constructors are special functions in C++ that are used to initialize objects. They are called automatically when (1M definition
an object is created, and they can be used to set the initial values of the object's data members. and Types 1M
Types of constructors are :
• Default Constructor.
• Parameterized Constructor.
• Copy Constructor.
• Overloaded constructor
• Constructors with default argument
Q 3 b) Explain with suitable example Friend Function. 4
• Private members of a class cannot be accessed from outside the class. However there could be a situation (Explanation
where more than one classes want to share a particular function. 2M and
• For example consider two classes ’manager’ and ‘scientist’. We can use a function incom_tax ( ) that will Example 2M)
operate on the objects of both these classes and calculate the total income tax. Here the function income_tax
() need to access private members of both the classes.
• This can be done with the help of friend function.
• “Friend function is a normal c++ function that can access private members of the class to whom it is declared
as friend.”
• To make a normal c++ function “friendly” to the class , precede the declaration of the function with keyword
‘friend’ inside the class.
Example
Examination Paper Analysis
Class fun
{
private:
int a, b;
public:
friend void xyz ( fun s); // function xyz is a friend of class fun
};
• The function is defined somewhere in the program (outside the class) like a normal c++ function.
• The function can be declared as to any number of classes.
• The friend function is not a member of a class, but it has full access rights to the private members of the
class.
/*Program to find the mean value of a given number using friend function.
#include<iostream.h> #include<conio.h>
class sample
{
int val1,val2;
public:
void get()
{
cout<<"Enter two values:";
cin>>val1>>val2;
}
friend float mean(Sample ob);
};
float mean(sample ob)
{
return float(ob.val1+ob.val2)/2;
}
void main()
{
clrscr();
sample obj;
obj.get();
cout<<"\n Mean value is : "<<mean(obj);
getch();
}
Output:
Enter two values: 10, 20
Mean Value is: 15
Q 6 a) Develop a c++ program for constructor with default argument and use of destructor.
Examination Paper Analysis
# include <iostream.h> 6
class employee
{ float basic , TA, DA , HRA; (correct logic
public: employee ( float b , float T , float H =3500 , float D = 5000) 6M)
{ basic = b;
TA =T;
HRA = h;
DA = D;
}
void display_salary (void)
{ float GS;
GS = basic + TA + DA + HRA;
cout << GS << endl;
}
}
void main ()
{
employee e1 ( 8000,2000);
cout << “ Gross Salary of e1 = “ ;
e1.display_salary();
employee e2 ( 8000 , 2000 , 5000 , 10000);
cout << “ Gross Salary of e2 = “ ;
e2. Display_salary();
}
OUTPUT:
cout << “ Gross Salary of e1 = 18500“ ;
cout << “ Gross Salary of e2 = 25000“ ;
Summer Unit 2 1.(b) Write the syntax for declaration of class. 2M
2023 Ans.
class class_name Correct syntax
{ 2M
private:
variable declarations;
function declarations;
public:
variable declarations;
function declarations;
};
1.(c) State the characteristics of static member function. 2M
Ans.
Examination Paper Analysis
A static function can have access to only other static member declared in the class. Any two
A static member function can be called using the class name instead of objects as follows: characteristics
class_name::function_name. 1M each
2.(b) Explain overloaded constructor with suitable example. 4
Ans. (Explanation
• Constructor overloading is a process of defining more than one constructor function in a class. 2M and
• A class can have more than one constructor function example 2M)
• Type of constructor: default constructor, parameterized constructor, constructor with default value and
copy constructor.
• An appropriate constructor function executes when number of parameters and its data type matches with
constructor function prototype.
Example:
class example
{
int a,b;
public:
example()
{
a=0;
b=0;
}
example(int x)
{
a=x;
}
example(int x,int y)
{
a=x;
b=y;
}
};
void main()
{
example I1;
example I2(10);
example I3(10,20);
}
In the above code, example is the name of the class.First constructor is a default constructor that receives no
arguments.When object I1 is created without values, first constructor executesand assigns 0 value to variables a
and b.Second constructor receives one argument. When object I2 is created with one value, second constructor
Examination Paper Analysis
executes and assigns value 10 to variable a.Third constructor receives two arguments. When object I3 is
createdwith two values, third constructor executes and assigns value 10 tovariable a and value 20 to variable b.
3.(b) Compare static and non static data members. 4M Any four
Ans. correct points
1M each

4.(b) List any four properties of constructor function. 4M Any four


Ans. properties 1M
each
Examination Paper Analysis

5.(b) Write a program to show object as function argument. 6M Correct


#include <iostream> logic 3M
class Decimal Correct syntax
{ 3M
private:
int a;
public:
void set(int x)
{
a = x;
}
void sum(Decimal ob1, Decimal ob2)
{
a = ob1.a + ob2.a;
}
void print()
{
cout<< "Value of A: " << a <<endl;
}
};
int main()
{
Examination Paper Analysis
Decimal d1;
Decimal d2;
Decimal d3;
d1.set(10);
d2.set(20);
d3.sum(d1, d2);
cout<<"First Decimal value\n";
d1.print();
cout<<"Second Decimal value\n";
d2.print();
cout<<"Sum of Decimal object1 and object2 =\n";
d3.print();
return 0;
}
6.(a) State the difference between constructor and destructor (any six points)
Ans. 6M
Any six points
1M each
Examination Paper Analysis

Summer Unit 3 Q4 a) Describe the concept of virtual base class with example. 4
2022
Examination Paper Analysis
Solution: (Explanation
4M)
VIRTUAL BASE Class:

The duplication of inherited members due to these multiple paths can be avoided by making the common
base class (ancestor class) as virtual base class while declaring the direct or intermediate base class.
Consider a situation where all three kinds of inheritance multiple, multilevel and hierarchical are involved :
· Here in the above diagram the child has two direct base classes ‘ parent1’ and ‘parent2’ which themselves have
a common base class ‘grandparent’.
· The ‘child’ class inherits the traits of ‘grandparent’ via two separate paths. All the public and protected members
of ‘grandparent’ are inherited twice via ‘parent1’ and again via ‘parent2’.
· This means ‘child’ class would have duplicate sets of members inherited from ‘grandparent’ this introduces
ambiguity& should be avoided.
· To avoid duplication of inherited members due to the multiple paths we use virtual base classes.
Syntax:

class A { };
class B: virtual public A
{ // statement 1};
class C: public virtual A
{ // statement 2};
class D: public B,public C
{ };
Q5 b) Write a C++ program to implement following inheritance: Refer Fig. No. 1 6
(correct logic
6M)
Examination Paper Analysis

Accept and display total of one object of result.


Solution:
class Science
{ float Phy_marks, Chy_marks;
public: void getdata()
{ cout<<”Enter the marks of Physics and Chemistry”;
cin>> Phy_marks>>Chy_marks;
}
void putdata()
{ cout<<”Physics Marks”<< Phy_marks;
cout<<”Chemistry Marks”<< Chy_marks;
}
};
class Maths
{ float Algo_marks, Geo_marks;
public: void getdata()
{ cout<<”Enter the marks of Algo_marks, Geo_marks”;
cin>> Algo_marks>>Geo_marks;
}
void putdata()
{ cout<<”Marks in maths”<< Algo_marks<<Geo_marks;
}
};
class Result: public Science, public Maths
{ float Total;
void calculate()
{ Science::getdata();
Maths::getdata();
Total= Phy_marks+Chy_marks +Algo_marks+Geo_marks;
Science::putdata();
Maths::putdata();
Examination Paper Analysis
}
};
void main()
{ Result r;
r.calculate();
getch();
}
Q6 c) Write a program to implement inheritance as shown in figure No. 2. Assume suitable member function 4

(correct logic
4M)

Accept and display data of one Teacher and one Officer.


Solution:
class Staff
{ int code;
public: void getdata()
{ cout<<”Enter Staff Code ”;
cin>>code;
}
void putdata()
{ cout << “Staff Code=”<<code;
}
};
class Teacher: public Staff
{ char subject[20];
public: void getdata()
{ Staff::getdata();
cout <<”Enter the Subject”<<endl;
cin >>subject;
}
void putdata()
{ Staff::putdata();
Examination Paper Analysis
cout<<”Subject=”<< subject;
}
};
class Officer: public Staff
{ char grade[20];
public: void getdata()
{ Staff::getdata();
cout <<”Enter the Grade”<<endl;
cin >>grade;
}
void putdata()
{ Staff::putdata();
cout<<”Grade=”<< grade;
}
};
void main()
{ Teacher t;
t.getdata();
t.putdata();
Officer o;
o.getdata();
o.putdata();
getch();
}
Winter- Unit 3 Q 2 b) Develop a c++ program for multilevel inheritance. 4
2022
(correct logic
Class : Student 4M)
Member variables: Name ,rollno

Class : test
Member variables: marks1 , marks2

Class : result
Mmeber variables :Toatal_marks
Examination Paper Analysis
# include <iostream.h>
class student
{
private : int rollno;
char name[30];
public: void getdata(void)
{
cout <<”Enter rollno: “ << endl;
cin>>rollno;
cout << “Enter name : “<<endl
cin >> name;
}
void showdata(void)
{
cout <<”Rollno= “ <<rollno << endl;
cout << “Name = “<< name << endl;
}
};
class test : public student
{
protected :
int marks1 , marks2; // merks1 and marks2 are protected members
public :
void getmarks ()
{
cout << “Enter marks of sub1 : “ ;
cin >> marks1;
cout << “Enter marks of sub2 : “ ;
cin >> marks2;
}
void showmarks (void)
{
cout << “Marks of sub1 = “ << marks1;
cout << “Marks of sub2 = “<< marks2;
}
};
class result : public test
{
private :
int total_marks;
public:
Examination Paper Analysis
void display_result()
{
total_marks = marks1 + marks2; // marks1 and marks2 are accessible
// here b’cos they are declared as // protected in base class test
student :: showdata();
test :: showmarks () ;
cout << “Total Marks = “<< total_marks;
}
};
void main()
{
result r1;
r1.getdata(); // get rollno and name
r1.getmarks(); // get marks1 and marks2
cout << “details of student: “ <<endl;
r1.display_result();
}
OUTPUT
Enter Rollno : 123
Enter Name : Deepali
Enter Marks of sub1: 45
Enter Marks of sub2 : 38
Details of student :
RollNo = 123
Name = Deepali
Marks of sub1 : 45
Marks of sub2: : 38
Total Marks : 83
Q 3 c) Describe all visibility modes and effects with example. 4
Access modifiers are also called as visibility mode: (Explanation
There are three types of visibility modes available in c++. 4M)
The members of the class can be,
1) private
2) protected
3) public
Private:
Private members can be accessed only by the member functions of a class. They are not accessible outside the
class.
Public:
Public members are accessible anywhere in the program.
Protected:
Examination Paper Analysis
A member declared as ‘protected’ is accessed by member functions of its own class as well as member functions
of the immediately derived class.
class A
{
private : // Default visibility –mode
//
visible to member function of its own class
protected :// visible to member functions of own class as well as member //functions of derived class
public : // visible to all functions in the program.
};
Visibility – Accessed from Accessed from Accessed from object of
mode member functions member fun of derived class
of own class Derived class
Public YES YES YES
Protected YES YES NO
Private YES NO NO
NOTE :
• Member function of a class can access all type of data ( private , protected , public)
• Private members are only accessed by member function of a class.
• Object of a class can access only public member of a class. They cannot access private or protected members
of a class.
• Protected members are accessed only by member function of a class and member function of immediately
derived class.

4
(correct logic
4M)
Examination Paper Analysis
# include <iostream.h>
class employee //
base class
{
private : int emp_id;

char emp_name [30];


long int mobile;
public: void getdata(void)
{ cout <<”Enter emp_id : “ <<endl;
cin >> emp_id;
cout <<”Enter emp_name : “<<endl;
cin >> emp_name ;
cout <<”Enter emp_mobile no : “<<endl;
cin >> mobile ;

}
void showdata(void)
{ cout <<”emp_id = “ <<emp_id <<endl;
cout <<”emp_name = “ << emp_name << endl;
cout <<”emp_mobile no = “ << mobile ;

}
};
class customer //
base class
{
private :
char name[40],add[100];
long int contact ;

public:
void getdata(void)
{
cout<<”\n Enter Customer Name”;
cin>>name;
cout<<”\n Enter Customer Address”;
cin>>add;
cout<<”\n Enter Customer Mobile No”;
cin>>contact;
Examination Paper Analysis
}
void showdata(void)
{
cout<<”\n Customer Name”<<name;
cout<<”\n Customer Address”<<add;
cout<<”\n Enter Customer Mobile No”<<contact;
}
};
class company : public employee , public customer // derived class
{
private :
char comp_name[40];
char location[50];
public: void getdata(void)
{ employee :: getdata();
customer :: getdata();
cout<<”\n Enter Company Name”;
cin>>comp_name;
cout<<”\n Enter Company Address”;
cin>>location;

}
void showdata(void)
{ employee :: showdata();
customer :: showdata();
cout<<”\n Company Name”<<comp_name;
cout<<”\n Company Address”<<location;
}

};
void main()
{
company c1;
c1.getdata();
cout << “Details of Employee”<<endl;
c1.showdata();
}
Examination Paper Analysis
Q 5 b) Develop a c++ program to implement virtual Base class.
Example: 6
#include <iostream> (correct logic
using namespace std; 6M)
class A {
public:
int a;
A(){
a = 10;
}

};
class B : public virtual A {
};
class C : public virtual A {
};
class D : public B, public C {
};
int main(){
//creating class D object
D object;
cout << "a = " << object.a << endl;
return 0;
}
Output
a=10
Q 6 c) Develop c++ program to implement inheritance shown in fig
6
(correct logic
6M)

#include <iostream>
using namespace std;
class HOD
{
Examination Paper Analysis
char name [30], dept [40];
public:
void getdata()
{
cout << "Enter name of HOD:";
cin >> name;
cout << "Enter department:";
cin>>dept;
}
void showdata()
{
cout << "Name:"<<name;
cout << "Department:"<< dept;
}
};
class faculty: public HOD
{
char name[30];
int salary;
public:
void showdata()
{
HOD :: getdata();
cout << "Enter name: ";
cin>> name;
cout << " Enter Salary :";
cin>>salary;
}
void showdata()
{
HOD::showdata();
cout << " Name: "<< name << endl;
cout << "Salary:"<< salary <<endl;
}
};
class lab_incharge: public HOD
{
char name[30];
int no_of_labs;
public:
void getdata()
Examination Paper Analysis
{
faculty::getdata();
cout<<"Enter name";
cin>>name;
cout<<"Enter the no of labs incharged:";
cin>> no_of_labs;
}
void showdata()
{
faculty :: showdata();
cout<<"Name:"<<name<<endl;
cout << "No of labs incharged:"<<no_of_labs<<endl;
}
};
class student:public HOD
{
int roll_no;
char name[30];
public:
void getdata()
{
cout<<"Enter roll no:";
cin>> roll_no;
cout<<" Enter name:";
cin>>name;
}
void showdata()
{
cout<<"Enter Roll No.:"<< roll_no << endl;
cout<<" Name:"<< name<<endl;
}
};
class technical: public lab_incharge
{
int lab_id;
char name[30];
public:
void getdata()
{
lab_incharge::getdata();
cout<<"Enter lab_id:";
Examination Paper Analysis
cin>> lab_id;
cout << " Enter name:";
cin>> name;
}
void showdata()
{
lab_incharge::showdata(); cout << "Lab id:"<<< lab_id; cout << " Name:"<< name;
}
};
class non_technical:public lab_incharge
{
int lab_id;
char name[30];
public:
void getdata()
{
technical :: getdata();
cout << " Enter lab id:";
cin>>lab_id;
cout << " Enter Name:";
cin>>name;
}
void showdata()
{
technical::showdata();
cout<<" Lab id :"<<lab_id;
cout <<"Name:"<<name;
}
};
int main()
{
non_technical a1;
student s1;
s1.getdata();
s1.showdata();
a1.getdata();
a1.showdata();
return 0;
}
Unit 3 1.(d) State different types of visibility mode in inheritance. 2M
Examination Paper Analysis
Summer Ans. Any two types
2023 1. Private 1M each
2. Public
3. protected
1.(e) Give the syntax for constructor in derived classes. 2M Correct
Derived_constructor (arglist1, arglist2,…, arglistN,): syntax 2M
base1(arglist2), . . . ,baseN(arglistN)
{
Body of derived class constructor
}
2.(c) Write a program on single inheritance. 4M Correct
#include<iostream.h> logic 2M
#include<conio.h> Correct syntax
class employee 2M
{
protected:
int emp_id;
char name[10];
};
class emp_info:public employee
{
int basic_salary;
public:
void getdata()
{
cout<<"Enter emp id";
cin>>emp_id;
cout<<"Enter name";
cin>>name;
cout<<"Enter basic salary";
cin>>basic_salary;
}
void putdata()
{
cout<<"\nEmp_id="<<emp_id;
cout<<"\nName="<<name;
cout<<"\nBasic Salary="<<basic_salary;
}
};
void main()
Examination Paper Analysis
{
emp_info e;
clrscr();
e.getdata();
e.putdata();
getch();
}
5.(c) Write a program on hybrid inheritance. 6M Correct
#include <iostream> logic 3M
class A Correct syntax
{ 3M
public:
int x;
};
class B : public A
{
public:
B() //constructor to initialize x in base class A
{
x = 10;
}
};
class C
{
public:
int y;
C() //constructor to initialize y
{
y = 4;
}
};
class D : public B, public C //D is derived from class B and class
C
{
public:
void sum()
{
cout<< "Sum= " << x + y;
}
};
Examination Paper Analysis
int main()
{
D obj1; //object of derived class D
obj1.sum();
return 0;
}
6.(b) Explain abstract class with suitable example 6M Correct
Ans explanation
By definition, a C++ abstract class must include at least one pure virtual function. 3M Correct
Alternatively, put a function without a definition. example 3M
Because the subclass would otherwise turn into an abstract class in and of itself, the abstract class's
descendants must specify the
pure virtual function.
Although the Abstract class type cannot be created from scratch,
it can have pointers and references made to it.
A pure virtual function can exist in an abstract class in addition
to regular functions and variables.
The main objective of abstract base class is to provide some
traits to the derived classes and to create a base pointer required
for achieving run time polymorphism
Example:
#include<iostream>
class Figure
{
public:
virtual int Area() = 0;
void setBreadth(int br)
{
breadth = br;
}
void setHeight(int ht)
{
height = ht;
}
protected:
int breadth;
int height;
};
class Rectangle: public Figure
{
public:
Examination Paper Analysis
int Area()
{
return (breadth * height);
}
};
class Triangle: public Figure
{
public:
int Area()
{
return (breadth * height)/2;
}
};
int main()
{
Rectangle R1;
Triangle T1;
R1.setBreadth(6);
R1.setHeight(12);
T1.setBreadth(40);
T1.setHeight(4);
cout<< "The area of the rectangle is: " << R1.Area() <<endl;
cout<< "The area of the triangle is: " << T1.Area() <<endl;
}
Summer Unit 4 Q1 g) State the need of virtual function in C++. 2
2022 (Explanation
• Virtual function is that which does not really exist but nevertheless appears real to some part of the program. 4M)
• We use virtual functions when we have number of objects of different classes and we want to put them
together on a list and perform a particular operation using a single function call.
• When we use a pointer to base class to refer to the derived class object, always base class function is invoked,
even if the pointer contains the address of derived class object. This is because; compiler ignores the contents
of pointer and chooses the member function that matches the type of a pointer.
• Using virtual function mechanism we can force the compiler to look at the contents of the pointer rather than
the type of the pointer at the time invoking the function.
• When the same function exist in both base and derived class, the base class function is made virtual using
keyword virtual.
• When a function in a base class is made virtual, C++ determines which function to invoke at run time based
on the type of object pointed by the base class pointer rather than the type of the pointer.
• Thus by making the base class pointer to point to different objects, we can execute different versions of the
virtual functions.
Examination Paper Analysis

• Runtime polymorphism is achieved only when a virtual function is accessed through a pointer to the base
class.
Q3 d) Differentiate between compile time and run time polymorphism. 4 (correct
Solution: points 4M)
Early Binding Late Binding
Linking of function call and the code to Linking of function call and the code to be executed in response
be executed in response to that call is to that call is done at Run time
done at compile time
Which function to be executed is Which function is to be executed is decided by looking at the
decided by matching the type and contents of the base class pointer at run time.
number of arguments passed to the
function
Operator overloading and function Virtual functions is the example of late binding
overloading are the examples of early
binding
It requires less execution time because Late binding requires some overhead at run time but provides
process of binding is done at compile increased power and flexibility
time i.e. prior to the execution of
program.
Also known as compile time Also known as rum time polymorphism or Dynamic binding
polymorphism or static binding
This does not require use of pointers to This requires use of pointers to object
objects
Function calls are faster Function calls execution are slower
Q4 b) Write a C++ program to overload add function to add two integer numbers and two float numbers. 4(correct logic
Solution: 4 marks)
#include<iostream>
int add(int,int);
double add(double, double);
int add(int a,int b)
{
return (a+b);
}
double add(double x, double y)
{
return (x+y);
}
int main()
{
Examination Paper Analysis
std::cout<<"Addition of Two Integer numbers"<<add(5,8);
std::cout<<"Addition of Two double numbers"<<add(10.00,8.42);
return 0; }

Q5 a) i) Define pointer operator and address operator with example. 2 (Definition


Solution: 1M and
There are two special pointer operators, Example 1M)
1. & is called address of operator :
This returns the address of(its operand.) a variable. Where address is the internal computer’s memory location
of variable.
cout << &a ; //prints address of variable a

2) * operator which is called “ value at address “ operator.


The “*” is the indirection operator and it is the complement of &. It is the unary operator that returns the value
of the variable located at the address specified by its operand.
Q5 b) ii) Write a C++ program to declare a class train with members as train no and name. Accept and display 4(correct logic
data for one object of train. Use pointer to object to call functions of class. 4 marks)
Solution:
#include<iostream.h>
#include<conio.h>
class Train
{ int train_no;
char name[20];
void getdata()
{ cout<<”Enter train_no and train name”;
cin>>train_no>>name;
}
void putdata()
{cout<<”Train No=”<<train_no;
cout<<”Train Name=”<<name;
}
};
void main()
{ Train t ,*ptr;
ptr=&t;
ptr->getdata();
ptr->putdata();
getch();
}
Examination Paper Analysis

Q 5 c) Explain rules of operator overloading and overload ‘+’ operator to concatenate two string. 6
#include<iostream> (correct logic
#include<conio.h> 6M)
using namespace std;
class String
{
char str[20]; //member variable for string input
public:
void input() //member function
{
cout<<"Enter your string: ";
cin.getline(str,20);
}
void display() //member function for output
{
cout<<"String: "<<str;
}
String operator+(String s) //overloading
{
String obj;
strcat(str,s.str);
strcpy(obj.str,str);
return obj;
}
};
void main()
{
String str1,str2,str3; //creating three object
str1.input();
str2.input();
str3=str1+str2;
str3.display(); //displaying
getch();
}
Q 1 e) Explain concept of pointer with example. 2
A pointer is a variable that stores the address of another variable. Unlike other variables that hold values of a (Definition 1M
certain type, pointer holds the address of a variable. For example, an integer variable holds (or you can say stores) and Example
an integer value, however an integer pointer holds the address of a integer variable. 1M)
#include <stdio.h>
Examination Paper Analysis
int main()
{
int num = 10;
printf("Value of variable num is: %d", num);
/* To print the address of a variable we use %p
* format specifier and ampersand (&) sign just
* before the variable name like &num.
*/
printf("\nAddress of variable num is: %p", &num);
return 0;
}
Output:
Value of variable num is: 10
Address of variable num is: 0x7fff5694dc58
Q 4 c) Develop a c++ program to perform arithmetic operation using pointer. 4
POINTER ARITHMETIC: (correct points
The following operation can be performed on a pointer. 4M)
1) Addition of a number to a pointer.
int a =7;
int * p = & a;
p = p+2;
cout<<p;
2) Subtraction of a number from a pointer
int a =7;
int * p = & a;
p = p - 2;
cout<<p;
3) Subtraction of two pointers.
int a [4] = { 1,2,3,4};
int * p = & a [0]; // p points to the first element of array
int *q = & a [3]; // q points to the last element of array
cout << q –p;

Do not attempt the following operations on pointer.


1) Addition of two pointers.
2) Multiplying a pointer with a number.
3) Dividing a pointer by a number.
Q 5 c) Explain rules of operator overloading and overload ‘+’ operator to concatenate two string. 6
#include<iostream> (correct logic
#include<conio.h> 6M)
using namespace std;
Examination Paper Analysis
class String
{
char str[20]; //member variable for string input
public:
void input() //member function
{
cout<<"Enter your string: ";
cin.getline(str,20);
}
void display() //member function for output
{
cout<<"String: "<<str;
}
String operator+(String s) //overloading
{
String obj;
strcat(str,s.str);
strcpy(obj.str,str);
return obj;
}
};
void main()
{
String str1,str2,str3; //creating three object
str1.input();
str2.input();
str3=str1+str2;
str3.display(); //displaying
getch();
}
Q 5 a) Define class book with following Data member and member function for 10 book. 6(correct logic
Data Member Member Function 6M)
1. B - name → getdata ( )
2. B - author → put data ( )
3. B - price
#include<iostream.h>
#include<conio.h>
class book
{
char name[40],author[30];
float p;
Examination Paper Analysis
public:
void getdata()
{

cout<<”\n Enter Book Name”;


cin>>name;
cout<<”\n Enter Author of the book”;
cin>>author;
cout<<”\n Enter Book price”;
cin>>p;

}
void putdata()
{
cout<<”\n Book Name”<<name;
cout<<”\n Author of the book”<<author;
cout<<”\n Book price”<<p;
}
};
void main()
{

Book b[10],*b1;
B1=&b[0];
Int I;
for(i=0;i<10;i++)
{
B1->getdata();
B1++;
}
for(i=0;i<10;i++)
{
B1->putdata();
B1++;
}
Q 6 b) Describe Function overloading with suitable program 6
Function overloading is a feature of c++ that allows a function to behave in more than one way depending (Explanation
upon the number and / or type of arguments passed to it. 3M and
There can be more than one function -definitions with the same name but with the different number of Example 3M)
arguments or different data types in a program.
Examination Paper Analysis
The compiler determines which function code is be executed in response to the function call, just by matching
the number and /or type of arguments passed to it. Since the compiler knows this information at compile time,
it is called as compile time polymorphism or early binding.
Thus, more than one the functions with the same name but with the different no. of arguments or different
data types can exist in program.Thus, more than one the functions with the same name but with the different
no. of arguments or different data types can exist in program.
Example: consider the following function prototypes.
1) int ad (int ,int); // function prototype to add two integers
2) double add ( double ,double); // function prototype to add two doubles
3) int add (int ,int ,int); // function prototype to add three integers
Therefore when a function is called as add ( 10,20) ; the first definition will be called.
For function call add(12.3 ,56.8); the second definition will be called.
And for function call add ( 5,6,7); the third definition will be called.
NOTE : when functions are overloaded , compiler does not check for return data type. It only matches the no.
and the type of arguments passed to it.
Thus following function definitions will lead to an error.
int f (int );
void f (int );
Ex:
#include<iostream.h>
int volume(int);
double volume(double, int);
int volume(int s)
{
return (s*s*s);
}
double volume(double r, int h)
{
return (3.14*r*r*h);
}
void main()
{
cout<<”volume of cube is”<<volume(5);
cout<<”volume of cylinder is”<<volume(10.5,8);
getch();
}

Q 3 d) Differentiate between compile time polymorphism and Runtime polymorphism 4


Early Binding Late Binding (Any 4 points
4M)
Examination Paper Analysis

Linking of function call and the code to Linking of function call and the code to be executed in response
be executed in response to that call is to that call is done at Run time
done at compile time
Which function to be executed is Which function is to be executed is decided by looking at the
decided by matching the type and contents of the base class pointer at run time.
number of arguments passed to the
function
Operator overloading and function Virtual functions is the example of late binding
overloading are the examples of early
binding
It requires less execution time because Late binding requires some overhead at run time but provides
process of binding is done at compile increased power and flexibility
time i.e. prior to the execution of
program.
Also known as compile time Also known as rum time polymorphism or Dynamic binding
polymorphism or static binding
This does not require use of pointers to This requires use of pointers to object
objects
Function calls are faster Function calls execution are slower
Summer Unit 4 1.(f) Define polymorphism with its types. 2M
2023 Polymorphism is the ability to take more than one form. (Definition 1M
Types: and Types 1M)
1. Compile time polymorphism
2. Run time polymorphism

2.(d) Illustrate this pointer with example. 4M


Ans.
• C++ uses a unique keyword called ‘this’ to represent an object that invokes a member function. Explanation
• ‘this’ unique pointer is automatically passed to a member function when it is invoked. 2M Example
• ‘this’ is a pointer that always point to the object for which the member function is called. 2M
• For example, the function call A.max ( ) will set the pointer ‘this’ to the address of the object A. Then
suppose we call B.max ( ), the pointer ‘this’ will store address of object B.
Example:
#include<iostream.h>
class sample
{
int a;
public:
void setdata(int x)
Examination Paper Analysis
{
this ->a=x;
}
void putdata()
{
cout<<this ->a;
}
};
void main()
{
sample s;
s.setdata(100);
s.putdata( );
}
In the above example, this pointer is used to represent object s when
setdata() and putdata ( ) functions are called.

3.(c) State any four rules for virtual functions. 4M


Ans.
Any four
correct rules
1M each
Examination Paper Analysis

4.(d) State the advantages of pointer. 4M

Any four
correct
advantages
1M each
Examination Paper Analysis

6.(c) Write C++ program to overload binary operator ‘+’ to concatenate two strings. 6M
#include<iostream> Correct logic
#include<string.h> 3M
class String Correct syntax
{ 3M
public:
char str[20];
public:
void accept_string()
{
cout<<"\n Enter String : ";
cin>>str;
}
Examination Paper Analysis
void display_string()
{
cout<<str;
}
String operator+(String x) //Concatenating String
{
String s;
strcat(str,x.str);
strcpy(s.str,str);
return s;
}
};
int main()
{
String str1, str2, str3;
str1.accept_string();
str2.accept_string();
str3=str1+str2;
cout<<"\n\n Concatenated String is : ";
str3.display_string();
return 0;
}

Summer Unit 5 Q1 b) List c++ stream classes along with their function. (any two classes). 2
2022
Solution: ios class is topmost class in the stream classes hierarchy. It is the base class for istream, ostream, and (Any 1 :one
streambuf class. mark)

1. The ios class: The ios class is responsible for providing all input and output facilities to all other stream
classes.
2. The istream class: This class is responsible for handling input stream. It provides number of function for
handling chars, strings and objects such as get, getline, read etc.
3. The ostream class: This class is responsible for handling output stream. It provides number of function
for handling chars, strings and objects such as write, put etc..
4. The iostream: This class is responsible for handling both input and output stream as both istream class
and ostream class is inherited into it. It provides function of both istream class and ostream class for
handling chars, strings and objects such as get, getline, read, ignore, putback, put, write etc..
5. istream_withassign class: This class is variant of istream that allows object assignment. The predefined
object cin is an object of this class and thus may be reassigned at run time to a different istream object.
Examination Paper Analysis
6. ostream_withassign class: This class is variant of ostream that allows object assignment. The
predefined objects cout, cerr, clog are objects of this class and thus may be reassigned at run time to a
different ostream object.
Q1 e) Explain ios :: app and ios :: in flags. 2
• Solution: ios::app: This flag means that you want to open a file and append to it. (explanation 2
• ios::in: Include this flag if you want to read from a file. marks)
Q3 b) Write a C++ program to copy the contents of a source file student 1.txt to a destination file student 2.txt 4(correct logic
using file operations. 4 marks)
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<stdlib.h>
void main()
{
clrscr();
ifstream fs;
ofstream ft;
char ch, fname1[20], fname2[20];
cout<<"Enter source file name with extension (student1.txt) : ";
gets(fname1);
fs.open(fname1);
if(!fs)
{
cout<<"Error in opening source file..!!";
getch();
exit(1);
}
cout<<"Enter target file name with extension (student2.txt) : ";
gets(fname2);
ft.open(fname2);
if(!ft)
{
cout<<"Error in opening target file..!!";
fs.close();
getch();
exit(2);
}
while(fs.eof()==0)
{
fs>>ch;
Examination Paper Analysis
ft<<ch;
}
cout<<"File copied successfully..!!";
fs.close();
ft.close();
getch();
}
Winter Unit 5 Q 4 e) Develop c++ program to check Detection of end of file.
2022 4(correct logic
4 marks)

Q 1 f) Explain file modes used to perform file operations. 2


In C++, for every file operation, exists a specific file mode. (Any 2)
These file modes allow us to create, read, write, append or modify a file.
The file modes are defined in the class ios.
A File stream act as an interface between the program and the files.
Examination Paper Analysis

Q 1 g) List all stream classes used in stream operation. 2


(list any 4 )

Class Functions
Examination Paper Analysis

ios •Contains basic facilities that are used by all other input and output classes.
•Also contains a pointer to a buffer object.
•Declares constants and functions that are necessary for handling formatted input and
output functions.
istream • Inherits the properties of ios.
• Contains overloaded extraction operator >>
ostream • Inherits the properties of ios.
• Contains overloaded insertion operator <<
Q 4 e) Develop c++ program to check Detection of end of file. 4(correct logic
#include <iostream> 4 marks)
#include <fstream>
using namespace std;

class student
{
int rollno;
char name[20];
char branch[3];
float marks;
char grade;

public:
void getdata()
{
cout << "Roll Number: ";
cin >> rollno;
cout << "Name: ";
cin >> name;
cout << "Course: ";
cin >> branch;
cout << "Mark: ";
cin >> marks;

if (marks >= 75)


grade = 'A';
else if (marks >= 60)
grade = 'B';
else if (marks >= 50)
grade = 'C';
else if (marks >= 40)
Examination Paper Analysis
grade = 'D';
else
grade = 'F';
}

void putdata()
{
cout << name << ", roll number " << rollno << " received " << marks << "% marks and ";
cout << grade << " grade." << "\n";
}

int getrno()
{
return rollno;
}
} stud1;

int main()
{
ofstream fout("marks.dat", ios::out);

char ans = 'y';


while (ans == 'y' || ans == 'Y')
{
stud1.getdata();
fout.write((char *)&stud1, sizeof(stud1));
cout << "A new record has been added to the file.\n";
cout << "\nWant to enter more? (y/n): ";
cin >> ans;
}
fout.close();

int rno;
char found;
ifstream fin("marks.dat", ios::in);
if (!fin)
{
cout << "Error opening the file!\n";
return 0;
}
Examination Paper Analysis
ans = 'y';
while (ans == 'y' || ans == 'Y')
{
found = 'n';
cout << "Enter the roll number to be searched for: ";
cin >> rno;

while (!fin.eof()) // end-of-file used here


{
fin.read((char *)&stud1, sizeof(stud1));
if (stud1.getrno() == rno)
{
stud1.putdata();
found = 'y';
break;
}
}
if (found == 'n')
{
cout << "\nThe entered roll number does not exist in the file.\n";
return 0;
}
cout << "\nWant to search more? (y/n):";
cin >> ans;
}
fin.close();

return 0;
}

Summer Unit 5 1.(g) Define file with it’s operations.A file is a collection of related data stored in a particular area on the disk. 2M Definition
23 File Operations: 1M Any two
• Open file operations 1M
• Close file
• Read file
• Write file
• Update file
4.(e) Write a program for closing a file.
Examination Paper Analysis
#include <iostream> 4(correct logic
#include <fstream> 4 marks)
int main()
{
fstreamFileName;
FileName.open("FileName.txt", ios::in);
if (!FileName)
{
cout<<"File doesn’t exist";
}
else
{
cout<<"File opened successfully";
}
FileName.close();
return 0;
}

You might also like