How To Exam?

a knowledge trading engine...


Sardar Patel University 2007 B.E Computer Science CP312 – OBJECT ORIENTED PROGRAMMING(SECOND INTERNAL TEST) - Question Paper

Tuesday, 29 January 2013 10:50Web

SOLUTION

BVM/GCET/ADIT
SECOND INTERNAL TEST
CP312 – OBJECT ORIENTED PROGRAMMING

Date: 03 / 04 / 2007 Time: 12:00 P.M. to 1:00 P.M. Max Marks: 15
Note: Make suitable assumptions as and when needed.

Q-1 (A)
Explain the subsequent terms. (Any 3 with example) [3]
Abstract Class:- when a class contain at lowest 1 pure virtual function is known as abstract class. Means at lowest 1 function with no body. Protected:-whenever you want to keep a member of a base class private but still allow a derived class access to it we require to declare it as protected
seekg():- movesthe associated file’s current get pointer offcet number of bytes from the specified origin.
For this we have 3 position:
Ios:beg : seek from beginning.
Ios:cur : seek from current location.
Ios:end : seek from end. tellp() :- to obtain out current position of every file pointer.

Syntax:
Pos_type tellp();

(B) What is Compile time and run time polymorphism? provide the difference ranging from this 2 terms.
Ans:- which function we have to resolve 1st is decided at the time of compilation is compile time polymorphism.
which function we have to resolve 1st is decided at the run time is run time polymorphism.
Difference:-

Compile time : support operator overloadind, friend function nonvirtual function, early binding, efficient,lack of flexibility, more memory allocation .

run time : support virtual, pure virtual function, late binding, not efficient, slower, flexible, less memory allocation. [2]

(C) Can the assignment operator be overloaded by using a friend function? provide its significance.
Ans:-
the assignment operator can be overloaded by using only member operator function because friend function does not have a this pointer so have to pass both operand explicitly. [1]
OR
(C) Why constructor cannot be a virtual but destructor can?
Ans:-
For virtual function two condition is there 1st is no. of argument must be identical and 2nd is function must be of base class, but for constructor no of argument must be various thus constructor can not be a virtual and for destructor there is no argument, no return kind so it can be virtual. [1]

Q-2 (A) Declare a class called Manager having data members name and salary. It has 2 virtual functions set_data and display_data as function members. Derive 2 classes called finance and system from the base class Manager. Override set_data and display_data to initialize and display data respectively.
describe function main to show use of run time polymorphism.

#include
#include
#include
#include
class manager
{
char name[20];
int salary;
public:
virtual void set_data(char *s,int sal)
{
strcpy(name,s);
salary=sal;
}
virtual void display()
{
cout< cout< }
};
class finance:public manager
{
public:
char nm[30];
int sal1;
public:
void set_data(char *s,int sal)
{
strcpy(nm,s);
sal1=sal;
}
void display()
{
cout< cout< }
};
class system:public manager
{
char nm1[30];
int sal2;
public:
void set_data(char *s,int sal)
{
strcpy(nm1,s);
sal2=sal;
}
void display()
{
cout< cout< }
};
int main()
{
int s;
manager *m;
finance f1;
system s1;
manager m1;
cout<<"enter option 1.finance << 2.system";
cin>>s;
if(s==1)
m=&f1;
else if(s==2)
m=&s1;
else
m=&m1;
m->set_data("aaa",10000);
m->display();
getch();

}
[4]

(B) Find out the output of the subsequent.
#include
void function(int x)
{
cout << x;
}

void main()
{
float a = 20.0
int b = 20;
cout.setf(ios::left);
cout.width(5);
cout.fill(‘$’);
cout< cout< cout.setf(ios::hex | ios::uppercase);
cout.setf(ios::showbase | ios::showpos);
cout< function(b);
}



o/p= 20$$$
400
+20
0X14
[2]
(C) Write a program to make your own copy command, which display and write the reverse case of all letters in destination file.

#include
#include
Int main(int argc, char *argv[])
{
Char ch;
If(argc!=3)
Cout<<”wrong no of argument”;
Return 1;
Ifstream in(argv[1]);
Ofstream out(argv[2]);
While(!in.eof())
{
Ch= in.get();
If(!in.eof())
{
If(islower(ch))
Ch= toupper(ch);
Else
Ch= tolower(ch);
Out.put(ch);
}
}

In.close();
Out.close();
Return 0;
}
[3]




( 0 Votes )

Add comment


Security code
Refresh

Earning:   Approval pending.
You are here: PAPER Sardar Patel University 2007 B.E Computer Science CP312 – OBJECT ORIENTED PROGRAMMING(SECOND INTERNAL TEST) - Question Paper