eee 3rd year oops cat 3 ans

Post on 14-Dec-2014

959 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

Object Oriented programming

TRANSCRIPT

PERI INSTITUTE OF TECCHNOLOGY

MANNIVAKKAM, CHENNAI-48

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

CONTINUOUS ASSESMENT TEST-3

CS2311 - OBJECT-ORIENTED PROGRAMMING

Class: III / EEE Date:

Semester: V Duration: 180 Min.

Max. Marks: 100

PART A (10 X 2 = 20 )

1. Define class and object.

Ans: Class is a collection of similar object,

it’s an aggregation of data members and function member.

Ex: fruit mango

Objects are the basic runtime entities, ex: place, person

2. What is the function overloading? Give an example.

Ans: More than one functions with same name but with different set of arguments. This is known as function

overloading

Ex: add(int a, int b);

add(float b, float c);

3. Define copy constructor

Ans: When one object is copied to another using initialization they are copied by executing the copy

constructor.

Ex: integer(integer &i);

4. Define multiple inheritances.

Ans: The inheritance where the derived class is derived from more than one base class.

5. What are all types of type conversions?

Ans:

a. Implicit Type conversion,

b. Built-in Data type to an Object,

c. object to Built-in Data type,

d. Object to Object

6. What is the need for function templates? How are they created?

Function template is used create a family of function with different argument (generic function).

7. What is virtual base class? Give an example.

A class which is defined as virtual at the time of inheriting it. The complier takes a note of it and when it

is inherited further using multiple inheritance, it ensures that only one copy of the sub object of the

virtual inherited class exists in the derived class. class L { /* ... */ }; // indirect base class

class B1 : virtual public L { /* ... */ };

class B2 : virtual public L { /* ... */ };

class D : public B1, public B2 { /* ... */ }; // valid

8. How is an exception handled in C++?

9. Define a Namespaces.

Ans: An enclosure of logical nature which helps libraries to have separate existence and solves the name conflict

problem

Ex: using namespace std;

10. Define Java Virtual Machine (JVM).

Ans: Java virtual machine (JVM) is a virtual machine that can execute Java bytecode. It is the code execution

component of the Java software platform

PART B ( 5 X 16 = 80 )

11. (a) Explain the basic concepts of oops with suitable Examples (16)

Ans:

Object oriented programming concepts:

i) objects

ii) classes

iii) methods and messages

iv) abstraction and encapsulation

v) inheritance

vi) abstract classes

Polymorphism

Class:

When you define a class, you define a blueprint for an object. This doesn't actually define any data, but it

does define what the class name means, that is, what an object of the class will consist of and what

operations can be performed on such an object.

Method and Message:

Method is function, it is used for communicating between object, message is use to command the

functionality behavior of object.

Abstract class:

Class with no object is known as abstract class

Inheritance: One of the most useful aspects of object-oriented programming is code reusability. As the name

suggests Inheritance is the process of forming a new class from an existing class that is from the existing class

called as base class, new class is formed called as derived class. This is a very important concept of object oriented

programming since this feature helps to reduce the code size

Polymorphism: The ability to use an operator or function in different ways in other words giving different

meaning or functions to the operators or functions is called polymorphism. Poly refers many. That is a single

function or an operator functioning in many ways different upon the usage is called polymorphism.

Or

(b) .Write a C++ program to construct student mark list for three subjects.

Write the program to display name, rollno,marks,avg and total. Use class and objects (16)

12. (a) Write a program to create a class “EMPLOYEE” with data members emp_name ,emp_id,

emp_dept, basicpay, PF,gross_pay ,net_pay, store them in an array of objects. Input the total

number if employees and perform the following:

(i) Calculate the Gross pay and Net pay.

(ii) Display the employee’s details with salary. (16)

#include<iostream.h>

#include<string.h>

#include<conio.h>

class EMPLOYEE

{

int empid;

char name[10];

char dept[10];

int bp,hra;

float gp,np;

int pf;

public:

void input();

void show();

void pay(int bp,int pf,int hra);

};

void EMPLOYEE::input()

{

std::cout<<"\nEnter empid:";

std::cin>>empid;

cout<<"Enter employee name:";

cin>>name;

cout<<"Enter department:";

cin>>dept;

cout<<"Enter basic pay:";

cin>>bp;

cout<<"Enter hra:";

cin>>hra;

cout<<"Enter pf:";

cin>>pf;

}

void EMPLOYEE::show()

{

cout<<"\n\n";

cout<<"\nEmployee id is: "<<empid;

cout<<"\nEmployee name: "<<name;

cout<<"\nDepartment: "<<dept;

pay(bp,pf,hra);

}

void EMPLOYEE::pay(int bp,int pf,int hra)

{

gp=bp+hra;

np=gp-pf;

cout<<"\nGross Pay is: "<<gp;

cout<<"\nNet Pay is: "<<np;

}

void main()

{

EMPLOYEE emp[10];

int i,n;

clrscr();

cout<<"Enter the no.of employees:";

cin>>n;

for(i=1;i<=n;i++)

{

emp[i].input();

emp[i].show();

}

getch();

}

Or

(b) Explain the constructor concept with its types with example programs. (16)

12. (a) What is operator overloading? What are its types? Explain the types with Example

Programs.(16)

Or

(b) Explain in detail about type conversion and its three cases. (16)

Example:

14. (a) what is template ?. Explain type of template with suitable example (16)

Type of Template:

i) class template

ii) Function Template

Class Template:

Example:

Example:

Or

(b) What are the types of inheritance? Explain about Multiple inheritances with example. (16)

Example:

15. (a) Explain the Exception Handling mechanism available in C++ with suitable examples. (16)

Or

(b) (i) What is file handling? Explain with example program (8)

(ii) Explain following Formatted I/O function with Example.

1)width() 2) precision() 3) fill() 4)setf() 5) unsetf() (8)

i)

ii)

iii)

iv)

v) Unsetf()

Clear the flag specified by the arg1,arg2 of setf( ) function

top related