W 2018 A - (Truexams - Com) - 1
W 2018 A - (Truexams - Com) - 1
W 2018 A - (Truexams - Com) - 1
com
22316
11819
3 Hours / 70 Marks Seat No.
Marks
P.T.O.
www.truexams.com
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.
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.
P.T.O.
www.truexams.com
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
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.
www.truexams.com
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 1 / 25
www.truexams.com
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 2 / 25
www.truexams.com
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 3 / 25
www.truexams.com
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 4 / 25
www.truexams.com
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 5 / 25
www.truexams.com
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 6 / 25
www.truexams.com
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Example:- Example
int a[5]={10,20,30,40,50},*ptr; 1M
ptr=a[4];
for(i=0;i<5;i++)
{
cout<<*ptr;
ptr- -;
}
Page 7 / 25
www.truexams.com
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Description:-
1. Include header files
In this section a programmer include all header files which are
require to execute given program. The most important file is
iostream.h header file. This file defines most of the C++statements Descript
like cout and cin. Without this file one cannot load C++ program. ion 2M
2. Class Declaration
In this section a programmer declares all classes which are necessary
for given program. The programmer uses general syntax of creating
class.
3. Member Functions Definition
This section allows programmer to design member functions of a
class. The programmer can have inside declaration of a function or
outside declaration of a function.
4. Main Function Program
In this section programmer creates objects and calls various functions
writer within various class.
Page 8 / 25
www.truexams.com
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Example
#include<iostream.h>
#include<conio.h>
class student
{
int rno;
Page 9 / 25
www.truexams.com
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 10 / 25
www.truexams.com
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Example:
#include<iostream.h> Relevant
#include<conio.h> example
class test 2M
{
Page 11 / 25
www.truexams.com
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Accept and display data of one teacher and one student using
object of class ‘Info’
Note: Any other correct logic of multiple inheritance in program
shall be considered.
Page 12 / 25
www.truexams.com
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
#include<iostream.h>
Ans #include<conio.h> Correct
class Teacher definitio
{ n of
protected: class -
char Name[20]; Teacher
int empid; 1M
};
class Student Correct
{ definitio
protected: n of
char sname[20]; class-
int rollno; Student
}; 1M
class Info:public Teacher,public Student
{ Correct
public: definitio
void acceptT() n of
{ class-
cout<<"\nEnter data for teacher:"; Info
cout<<"\nName:"; 1M
cin>>Name;
cout<<"\nEmployee id:";
cin>>empid;
}
void displayT()
{
cout<<"\nTeacher's data is:";
cout<<"\nName:"<<Name;
cout<<"\nEmployee id:"<<empid;
}
void acceptS()
{
cout<<"\nEnter student's data:";
cout<<"\nName:";
cin>>sname;
Page 13 / 25
www.truexams.com
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
c) Write a C++ program to swap two integer numbers and swap two 4M
float numbers using function overloading.
Page 14 / 25
www.truexams.com
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 15 / 25
www.truexams.com
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 16 / 25
www.truexams.com
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Ans #include<iostream.h>
#include<conio.h> Creating
#include<string.h> Class
class opov 2M
{
char str1[10];
public: Operato
void getdata() r
{ Functio
Page 17 / 25
www.truexams.com
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 18 / 25
www.truexams.com
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 19 / 25
www.truexams.com
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Ans (i) Write a C++ program to find whether the entered number is
even or odd.
Acceptin
#include<iostream.h> g
#include<conio.h> Number
void main() 1M
{
int num; Conditio
clrscr(); n to
cout<<"\nEnter a Number "; check
cin>>num; number
if(num%2==0) 1M
{
cout<<"\nEntered number is even"; Display
} result
else 1M
{
cout<<"\nEntered number is odd";
}
getch();
}
#include<iostream.h> Creating
#include<conio.h> structur
Page 20 / 25
www.truexams.com
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Accept and display data for one programmer and one manager.
Make display function virtual.
Ans. #include<iostream.h>
#include<conio.h>
class Employee
{
int empid,empcode;
public: Creating
void emp() all
{ classes
cout<<"\nEnter an employee id "; 3M
cin>>empid;
cout<<"\nEnter an employee code ";
cin>>empcode;
Page 21 / 25
www.truexams.com
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 22 / 25
www.truexams.com
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
getch();
}
Accept and display data for one car with all details.
Ans #include<iostream.h>
#include<conio.h>
class Carmanufacturer
{ Declarat
char Name[10];
Page 23 / 25
www.truexams.com
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
void putcarm()
{
cout<<"\nThe Car Name is "<<Name;
}
};
class Carmodel : public Carmanufacturer
{
char Modelname[10];
int Modelno;
public:
void getcarmodel()
{
cout<<"\nEnter Car Model Name and Model No. ";
cin>>Modelname>>Modelno;
}
void putcarmodel()
{
cout<<"\nEnter Car Model Name and Model No.
"<<Modelname<<" "<<Modelno;
}
};
class Car: public Carmodel
{
char colour[10], Carno[10];
public:
void getcar()
{
cout<<"\nEnter Car colour and car number";
cin>>colour>>Carno;
}
void putcar()
{
Page 24 / 25
www.truexams.com
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 25 / 25