Object Oriented programming with C++ - B.C.A 18-21 Sem2
SAINTGITS
COLLEGE OF APPLIED SCIENCES
First Internal Assessment Examination, FEB 2019
Department of BCA, Semester II
Object
Oriented programming in C++
Time : 2
hours Total:50 Marks
Section
A
Answer
any 5 questions. Each question carries 2 marks.
1.
Define class?
A class is a way to bind the data and its associated functions
together.A class can have both variables and functions.
2.
Write a program to
find the area of a square using class?
#include<iostream.h>
class
area
{
int
side,A;
public:
void getdata();
void
calculate();
};
void
area::getdata()
{
cout<<”enter
the side”;
cin>>side;
}
void
area::calaculate()
{
a=side*side;
cout<<”area
of square is”<<a;
}
void
main()
{
area obj;
obj.getdata();
obj.calaculate();
getch();
}
3.
Define friend
functions?
A function declared as friend is known as
friend function. It is not in the scope of the class to which it has been
declared as friend. It has full access to the private members of the class.
Declaration and definition syntax.
4.
Explain inline
function?
When a function is
declared inline the compiler replaces the function call with the respective
function code. Normally a small size function is made as inline.
5.
Explain for loop?
Entry controlled loop.
Syntax and example.
6.Explain memory
allocation for objects?
The
member functions are created and placed in the memory space only once when they
are defined. Space for member variables is allocated separately for each
object.
(5 X 2 = 10 marks)
Section B
Short
essay questions
Answer any 5 questions. Each question
carries 5 marks.
7. Explain static variables and
functions?
A data member of a class can be declared as a static and is normally
used to maintain values common to the entire class.
The static member variables must be
defined outside the class.
Example programs and figure.
Characteristics of static data and
functions.
8.
Write an example program using classes and objects?
Any program using class and object.
#include<iostream.h>
class area
{
int side,A;
public:
void getdata();
void calculate();
};
void area::getdata()
{
cout<<”enter the side”;
cin>>side;
}
void area::calaculate()
{
a=side*side;
cout<<”area of square
is”<<a;
}
void main()
{
area obj;
obj.getdata();
obj.calaculate();
getch();
}
9.
Explain Arrays of objects with example?
The array of type class contains the
objects of the class as its individual elements. Thus, an array of a class type
is also known as an array of objects. An array of objects is declared in the
same way as an array of any built-in data type.
class books
{
char tit1e [30];
float price ;
public:
void getdata ();
void putdata ();
} ;
void books :: getdata ()
{
cout<<"Title:”;
Cin>>title;
cout<<"Price:”;
cin>>price;
}
void books :: putdata ()
{
cout<<"Title:"<<title<<
"\n";
cout<<"Price:"<<price<<
"\n”;
const int size=3 ;
int main ()
{
books book[size] ;
for(int i=0;i<size;i++)
{
cout<<"Enter details o£
book "<<(i+1)<<"\n";
book[i].getdata();
}
for(int i=0;i<size;i++)
{
cout<<"\nBook
"<<(i+l)<<"\n";
book[i].putdata() ;
}
return 0;
}
10. Explain function overloading?
Function
overloading is a feature in C++ where two or more functions can have the same
name but different parameters.
Function
overloading can be considered as an example of polymorphism feature in C++.
Any
example program.
#include
<iostream>
using
namespace std;
void print(int i)
{
cout << " Here is int "
<< i << endl;
}
void
print(double f)
{
cout << " Here is float "
<< f << endl;
}
void
print(char const *c)
{
cout << " Here is char* "
<< c << endl;
}
int
main() {
print(10);
print(10.10);
print("ten");
return 0;
}
11. Explain program structure of C++?
Include Files
|
Class Declaration
|
Member Function definitions
|
Main Function Program
|
Explain
each one with Example statements.
12.
Differentiate POP and OOP?
Divided Into
In POP,
program is divided into small parts called functions.
In OOP,
program is divided into parts called objects.
Importance
In
POP,Importance is not given to data but to functions as well as sequence of
actions to be done.
In OOP,
Importance is given to the data rather than procedures or functions because it
works as a real world.
Approach
POP
follows Top Down approach.
OOP
follows Bottom Up approach.
Access Specifiers
POP does
not have any access specifier.
OOP has
access specifiers named Public, Private, Protected, etc.
Data Moving
In POP, Data can move freely from
function to function in the system.
In OOP,
objects can move and communicate with each other through member functions.
Expansion
To add
new data and function in POP is not so easy.
OOP
provides an easy way to add new data and function.
Data Access
In POP,
Most function uses Global data for sharing that can be accessed freely from
function to function in the system.
In OOP,
data can not move easily from function to function,it can be kept public or
private so we can control the access of data.
Data Hiding
POP does not have any proper way for
hiding data so it is less secure.
OOP provides Data Hiding so provides
more security
Overloading
In POP,
Overloading is not possible.
In OOP,
overloading is possible in the form of Function Overloading and Operator
Overloading.
Examples
Example
of POP are : C, VB, FORTRAN, Pascal. Example
of OOP are : C++, JAVA, VB.NET, C#.NET.
.
(5 X 5 = 25 marks)
Section C
Long essay questions
Answer any 1question. It carries 15marks.
13.
Explain OOPs Concepts?
Explain class
and objects, abstraction, encapsulation, polymorphism, inheritance etc. with
figure and examples.
14.
Explain constructors in C++?
Explain constructors and
characteristics.
Explain default, parameterized and copy
constructors with example.
(1 X 15 = 15 marks)
_____________________
Comments
Post a Comment