Professional Documents
Culture Documents
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 1 / 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 2 / 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 3 / 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 4 / 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 5 / 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
d) Develop c++ program to open and read content of file also write 4M
"object oriented" string in fi1e and close it'
Ans. #include<iostream> Correct
logic 2M
#include<fstream>
using namespace std;
int main() Correct
{ syntax 2M
Page 6 / 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Description
2M
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
like cout and cin. Without this file one cannot load C++ program.
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
Page 7 / 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 8 / 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Example
1M each
Page 9 / 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Example:
class Result: public Student
{
float percentage;
};
Page 10 / 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Protected:
When a base class is inherited by derived class in protected visibility
mode, public and protected members of the base class become
protected members of the derived class.
Therefore the public and protected members of the base class can be
accessed by the member functions of derived class as well as the
member functions of immediate derived class of it but they cannot be
accessed by the objects of derived class.
Example:
class Result: protected Student
{
float percentage;
};
d) Differentiate between Compile time polymorphism and Runtime 4M
polymorphism
Ans. Sr. Compile time Runtime polymorphism Any four
No. polymorphism differences
1M each
1 The linking of function call The linking of function call
to function definition is done to function definition is done
at compile time. at run time.
2 Functions to be executed are Function to be executed is
known well before(at unknown until appropriate
compile time) selection is made at run time
3 This does not require use of This requires use of pointers
pointers to objects to object
4 Function calls execution are Function calls execution are
faster slower
5 It is implemented with It is implemented with
operator overloading or virtual function.
function overloading
Page 11 / 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Correct
definition of
class
Ans. #include <iostream> Employee
1M,
using namespace std;
class Employee Correct
{ definition of
protected: class
char Name[20]; Customer
1M,
int Id;
long contact_noE; Correct
}; definition of
class Customer class
{ Company
1M,
protected:
char Name[20]; Correct
char Address[50]; definition of
long contact_noC; main() 1M
};
class Company:publicEmployee,public Customer
{
char Name[20];
char location[20];
public:
void getE()
{
cout<<"\nEnter employee's data:";
cout<<"\nName:";
cin>>Name;
cout<<"\nId:";
cin>>Id;
cout<<"\nContact no:";
cin>>contact_noE;
cout<<"\nCompany name:";
cin>>Name;
Page 12 / 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 13 / 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 14 / 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
for(i=0;i<5;i++)
{
cout<<"Enter name of student "<<i+1;
cin>>s[i].Name;
cout<<"Enter Roll Number of student "<<i+1;
cin>>s[i].Roll_No;
cout<<"Enter percentage of student "<<i+1;
cin>>s[i].percentage;
}
cout<<"\nStudents data is: ";
for(i=0;i<5;i++)
{
Page 15 / 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
if(fin.eof())
cout<<"[EoFreached]\n";
else
cout<<"[error reading]\n";
return 0;
}
5. Attempt any TWO of the following: 12
a) Define class book with following data member and member 6M
functions for 10 book.
Page 16 / 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Declare
class with
data
members
Ans. #include <iostream.h> and member
class book functions-
{ 4M
char name[20],author[20];
int price;
public: Main
void getdata() function
{ with
cout<<"Enter name"; function
call in loop -
cin>>name; 2M
cout<<"Enter author";
cin>>author;
cout<<"Enter price";
cin>>price;
}
void putdata()
{
cout<<endl<<"Name = "<<name;
cout<<endl<<"Author = "<<author;
cout<<endl<<"Price = "<<price;
}
};
void main()
{
book b[10];
int i;
for(i=0;i<10;i++)
b[i].getdata();
for(i=0;i<10;i++)
b[i].putdata();
getch();
}
Page 17 / 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
public:
void getmarks()
{
cout<<"Enter Marks\n";
cout<<"Part1:";
cin>>part1; cout<<"Part2:";
cin>>part2;
}
void putmarks()
{
cout<<"\t Marks Obtained\n";
cout<<"\n\t Part1:"<<part1;
cout<<"\n\tPart2:"<<part2;
}
};
class sports: public virtual student
Page 18 / 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
public:
void getscore()
{
cout<<"Enter Sports Score:";
cin>>score;
}
void putscore()
{
cout<<"\n\t Sports Score is:"<<score;
}
};
class result: public test, public sports
{
int total;
public:
void display()
{
total=part1+part2+score;
putnumber();
putmarks();
putscore();
cout<<"\n\t Total Score:"<<total;
}
};
void main()
{
result obj;
clrscr();
obj.getnumber();
obj.getmarks();
obj.getscore();
obj.display();
getch();
}
Page 19 / 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Program:
#include<string.h>
class operatorplus
{
char str1[10];
public:
void getdata()
{
cout<<"\nEnter a string";
cin>>str1;
}
void operator + (operatorplus s)
Page 20 / 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 21 / 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
OR
~Test()
{
cout<<"\n No. of Object destroyed:\t"<<count;
--count;
}
};
void main()
{
Page 22 / 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 23 / 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Ans.
(Any other correct implementation shall be considered.) Each class
#include<iostream.h> implementat
#include<conio.h> ion-1M
class HOD
{
protected:
char name[10];
char deptName[20];
};
class Faculty:public HOD
{
char fname[10];
public:
void getfaculty()
{
cout<<"Enter department name:";
cin>>deptName;
cout<<"Enter HOD name:";
cin>>name;
Page 24 / 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 25 / 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Page 26 / 27
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
Faculty f;
Student s;
Technical t;
NonTechnical n;
clrscr();
f.getfaculty();
s.getstudent();
t.getlabT();
n.getlabN();
f.putfaculty();
s.putstudent();
t.putlabT();
n.putlabN();
getch();
}
Page 27 / 27