cs304 collection of old papers

33
http://vujannat.ning.com BEST SITE TO HELP STUDENTS FINALTERM EXAMINATION FALL 2006 CS304 - OBJECT ORIENTED PROGRAMMING (Session - 1 ) Marks: 50 Time: 120min StudentID/LoginID: ______________________________ Student Name: ______________________________ Center Name/Code: ______________________________ Exam Date: Friday, February 09, 2007 Please read the following instructions carefully before attempting any of the questions: 1. Attempt all questions. Marks are written adjacent to each question. 2. Do not ask any questions about the contents of this examination from anyone. a. If you think that there is something wrong with any of the questions, attempt it to the best of your understanding. b. If you believe that some essential piece of information is missing, make an appropriate assumption and use it to solve the problem. c. Write all steps, missing steps may lead to deduction of marks. d. All coding questions should be answered using the C ++ syntax. e. Choose the most appropriate choice (among the given), while answering MCQs. 3. You are not allowed to use IDE (Dev-C++ or any) in your paper. **WARNING: Please note that Virtual University takes serious note of unfair means. Anyone found involved in cheating will get an `F` grade in this course. For Teacher's use only Question 1 2 3 4 5 6 7 8 9 Total Marks Question No: 1 ( Marks: 2 ) - Please choose one

Upload: httpmajidvacom

Post on 04-Apr-2015

104 views

Category:

Documents


2 download

DESCRIPTION

CS304 Collection Of Old Papers

TRANSCRIPT

Page 1: CS304 Collection Of Old Papers

http://vujannat.ning.com BEST SITE TO HELP STUDENTS

FINALTERM EXAMINATION

FALL 2006

CS304 - OBJECT ORIENTED PROGRAMMING (Session - 1 )

Marks: 50

Time: 120min

StudentID/LoginID: ______________________________

Student Name: ______________________________

Center Name/Code: ______________________________

Exam Date: Friday, February 09, 2007

Please read the following instructions carefully before attempting any of the questions:

1. Attempt all questions. Marks are written adjacent to each question.

2. Do not ask any questions about the contents of this examination from anyone.

a. If you think that there is something wrong with any of the questions, attempt it to the best of your understanding.

b. If you believe that some essential piece of information is missing, make an appropriate assumption and use it to solve the problem.

c. Write all steps, missing steps may lead to deduction of marks.

d. All coding questions should be answered using the C ++ syntax.

e. Choose the most appropriate choice (among the given), while answering MCQs.

3. You are not allowed to use IDE (Dev-C++ or any) in your paper. **WARNING: Please note that Virtual University takes serious note of unfair means. Anyone found involved in cheating will get an `F` grade in this course.

For Teacher's use only Question 1 2 3 4 5 6 7 8 9 Total

Marks

Question No: 1 ( Marks: 2 ) - Please choose one

Page 2: CS304 Collection Of Old Papers

Which of the statements is true about destructor? ►

Destructors are used to initialize data members

Destructors return types are always void

Destructors are called in reverse order of constructor called in a class hierarchy

Destructors are used to display the data members of their respective class

Question No: 2 ( Marks: 2 ) - Please choose one Identify the type of variable that is part of a class, yet is not part of an object of that class. ►

instance

static

global

local

Question No: 3 ( Marks: 2 ) - Please choose one Which of the following operators can not be overloaded? ►

++

new

sizeof

=

Question No: 4 ( Marks: 2 ) - Please choose one

Page 3: CS304 Collection Of Old Papers

Target function for a call is selected at compile time in case of ►

Static binding

Polymorphism

Encapsulation

Dynamic binding

Question No: 5 ( Marks: 2 ) - Please choose one Suppose it is required to implement a single functionality with different data type, which of the following techniques should be used ►

Inheritance

Friend function

Templates

Encapsulation

Question No: 6 ( Marks: 5 ) Identify and correct the error(s) in the given code segment.

template< typename T > class Parent { // … }; template< > class Child< int > : public Parent { // … }; int main() { Parent< char > obj; Child< int > obj2; return 0; }

Page 4: CS304 Collection Of Old Papers

Question No: 7 ( Marks: 10 ) Given are two classes A and B. class B is inherited from class A. Write a code snippet(for main function) that polymorphically call the method of class B. Also what changes do you suggest in the given code segment that are required to call the class B method polymorphically. class A { public: void method() { cout<<"A's method \n"; } }; class B : public A { public: void method() { cout<<"B's method\n"; } };

Question No: 8 ( Marks: 10 ) Implement the given class hierarchy where there exist a relation ship of inheritance between Employee and Contract (for contract employee). The Display() function of Contract should display the data that includes ; Name, Num_hours, Per_hour_sal, Salary Monthly salary of contract employee is calculated as

Salary = Per_hour_sal*Num_hours

Page 5: CS304 Collection Of Old Papers

Question No: 9 ( Marks: 15 )

A Real world Problem:

This is a business rule of a bank that the Balance of customer must always be Positive, Further that it is also a business rule that a customer can not withdraw amount greater than his/her current balance.

Question statement

You are required to write a C++ program to solve this real world problem, using Exception Handling. Your program should consist of a class Customer and 4 instance variables. Cust_name, Cust_AC_No, Cust_balance, Amount_withdraw. Cust_name : Customer Name Cust_AC_No : Customer Account Number Cust_balance : Customer Balance Amount_withdraw : Amount that is to be withdraw The class should further consists of getter and setter function for each instance variable. The setter function of Cust_balance consists of a try and a catch block, if the user enters the balance less than zero (means negative, which is not possible) then this function should throw an exception, and its corresponding catch block should handle this exception by providing another opportunity to the user to enter the balance again. Similarly the setter of Amount_withdraw variable should also have a try and a catch blocks. If the user enters the withdraw amount greater than the current balance then this function should throw an exception, and its corresponding catch block should handle this exception. In main function just declare an object of Customer class and call all its setter and getter functions.

Page 6: CS304 Collection Of Old Papers

class Exception {

Question No. 1 Marks : 10 Total Marks: 55 Total Questions: 03

**WARNING: Please note that Virtual University takes serious note of unfair means. Anyone found involved in cheating will get an `F` grade in this course.

You are allowed to use the Dev-C++ compiler to write and test your code. If you do so please remember to copy and paste your code into the examination solution area. (Do NOT share your code; your colleague could get higher marks than you!!)

d. All coding questions should be answered using the C ++ syntax.

c. Write all steps, missing steps may lead to deduction of marks.

b. If you believe that some essential piece of information is missing, make an appropriate assumption and use it to solve the problem.

a. If you think that there is something wrong with any of the questions, attempt it to the best of your understanding.

2. Do not ask any questions about the contents of this examination from anyone.

1. Attempt all questions. Marks are written adjacent to each question.

Please read the following instructions carefully before attempting any of the questions:

Time Allowed: 150 Minutes

Final Term Examination – Spring 2005

CS304 Object Oriented Programming

www.vujannat.ning.com

Page 7: CS304 Collection Of Old Papers

catch(...){ } throw 10.1; { catch(int) } Function1(); B obj2; try{ cout << "I am Function2\n" << endl; void Function2() {

} } throw DE; { if(condition3) //condition three cout << "I am Function1" << endl; DerivedException DE; void Function1() { }; ~B(){ cout << "Destructor B\n";} } throw 1; if(condition2) //condition two B(){ cout << "Constructor B\n"; public: class B {

}; } throw Exception(); if(condition1) //condition one

cout << "Destructor A\n"; ~A(){ A(){ cout << "Constructor A\n";} public: class A {

}; DerivedException() {strcpy(message,"Derived exception");} public: class DerivedException : public Exception { }; char * what() { return message; } Exception() {strcpy(message,"Exception");} public: char message [30] ; protected:

Page 8: CS304 Collection Of Old Papers

if(condition3){ }

throw DerivedException(); … if(condition2){

} throw Exception(); … if(condition1){ void Function(){

the three types of exceptions mentioned in the body and no other exception. e. Make changes in the following code so that "Function" only throws 02 d. What will be the out put when all three conditions (1,2&3) are true? 02 c. What will be the output when only condition three is true? 02 b. What will be the output when only condition two is true? 02 a. What will be the output when only condition one is true? 02

}

return 0; cout << "End of Program\n"; } cout << "Exception: unknown\n"; catch(...){ } cout << "Exception: int"; catch(int i){ } cout << "Exception: " << e2.what() << endl; catch(Exception & e2){ } cout << "Exception: " << e1.what() << endl; catch(DerivedException & e1){ } Function3(); try{ int main() {

} Function2(); A obj; cout << "I am Function3\n"; void Function3(){ } } throw;

Page 9: CS304 Collection Of Old Papers

} return start; ++strat; while ( start != beyond && *start != x ) T find( T start, T beyond, const U& x ) { template< typename T, typename U >

type) (Note: typename T stands for iterator type and U for element

for a reverse iterator that works with the following function: the operator ++, and forwards for the operator --. Write code A reverse iterator is an iterator that traverses backwards for

}; int* next( int* ); int* last(); int* first(); … public: … class Vector {

b) Consider the following vector class: 20

} return 0; RBTree< int > intRBTree; Tree< char > chTree; int main() { }; // … class RBTree< int > : public Tree { template< > }; // … class Tree { template< typename T >

explain the cause, and correct it.

a) The following program causes a compile-time error. Identify the error, 10

Question No. 2 Marks : 30

} }

throw 1;

Page 10: CS304 Collection Of Old Papers

from derived class assignment operator? e) What are the two mechanism of calling base class assignment operator 03

specialization? Give an example of each. d) What is the difference between a partial and complete template 03

sure you do not declare any variables of that type? c) Why use abstract classes at all? Why not just declare a class and then make 02

of object-oriented paradigm. b) Describe the three essential characteristics of an object from the perspective 03

by giving an example of each. a) Briefly describe the two major issues in multiple inheritance? Illustrate 04

Question No. 3 Marks : 15

Page 11: CS304 Collection Of Old Papers

WWW.vujannat.ning.Com Connecting VU Students

a) Write parameterized constructors for both classes i.e. Customer and Account, to initialize tdata members. For Customer class initialize cusbalance

ii. AccBalance i.ate data members

i. cusName Private data memb

ite two classes Customer and Account. Declar

Question No. 3 Marks : 3

5. the obje4. the object that called the function 3. a temporary object created within the function 2. the address of an object 1. the objects passes as an argument to the functio

hin a member function, the expression *this always ref Question No. 2

5. operato4. 3. + 2. complex add1. addat is the name of th

Question No. 1

Final Term Examination – Spring 2006 Time Allowed: 150 Minutes

Marks : 1 Wh e function that overloads the + operator for the complex class?

operator +r

Marks : 3

Wit ers to

n

ct that will be returned from the function

Wr e Account as a friend class of Customer.

ers of Customer class are:

ii. cusAddress iii. cusbalance

Priv of Account class are:

AccTitle

heir

to zero.

CS304

Page 12: CS304 Collection Of Old Papers

2. rate

1

inguished bc

and a pay () member function.

1. salary

owing attribb

virtual member function called pay () that returns the salary of the Employee.

Th

1. name

Write a C+ Question No. 5

5. Return 4. The array creating syntax is incorrect

the statement will result in an err3. The constructor is declared private but

1. The class name is invalid The public members should be prov

you see any problem with the code above?

}

Question No. 4 GiClass You{ private: YourCl // other private metpu // public me} void main() { Y

CW

mer class. rite a member function for the Customer class, named displaytData ( ) to display the values of ustomer’s cusName, cusAddress and cusbalance.

Marks : 1

ven below is a code snippet: rClass

ass(); hods

blic: mbers

ourClass *Yclass; Yclass = new YourClass[3];

Do

2. ided above the private members in the class an array is being created in the function main, therefore,

or

type of main () is not int

Marks : 1

a) + program which creates a class Employee with the following attribute

is class should have a parameterized constructor and destructor, the getter/setter functions and a

) Create a class named as Salaried that inherits from class Employee. A Salaried object has the foll ute

This class should also have parameterized constructor and default destructor, setter/getter functions

) Similarly, develop a class named as Hourly that inherits from class Employee. An Hourly object is dist y the following attributes

. hours

b) Write a member function of Account class, named setBalance ( ) to assign AccBalance to cusbalance, which is a data member of Custo

Page 13: CS304 Collection Of Old Papers

re i a class Studenstio No. 8

lso write setter and getter for the data member of the class rectangle. A in main (). Ta

return an integer number and vice versa.

If

Area() and perimeter() member functions should return the same type on which the data is manipulating. For example

Perimeter = 2 *(length + width)

rectangle is T

2: perimeter ();

Area = length * width by the following formulT

1: area ();

Your program should h data member of the class rectangle should be of type Template as well. T

2: width

1 Your rectangle class ha width entered by the user. Your code should include aW

Question No. 7 Marks : 1

ly symbolic; it is not actually executed 5. is mere

3. takes extra memory 2. is not generated by the compiler i1. is inserted into the pr co e for an inline function

Question No. 6 oY

our program should create objects of Salaried and Hourly classes and then invoke the pay () function f these classes polymorphicly (through Employee Object)

Marks : 1 The d

ogram in the place of each of function call tself, but by the processor

4. occurs only once in the program

rite a C++ program to determine the area and perimeter of rectangle according to the length and template <class T>.

s the following data member.

: length

he area and perimeter should be calculated for each int, float and double type data member. Hence the

ave following member functions of a template <class T>.

his member function will calculate the area of the rectangle. The area of a rectangle can be calculated a:

his member function will calculate the perimeter of the rectangle where the formula for perimeter of

the area is calculating for a rectangle of int type length and width, then this member function should

ke three instances of one of each type of data members’ int, float, and double for the class rectangle

Que n Marks : 1 The s t, Which one of the following is a valid destructor for this class

This class should also have a parameterized constructor, default destructor, setter/getter functions anda pay () member function.

Page 14: CS304 Collection Of Old Papers

Q Q Q Q Q Q Q Q Q Q Is Question No. 9

4. int~ Student(); 5. ~ Student(int);

Marks : 1

there any difference between abstract and base class? If yes, then what is it?

uestion No. 10 Marks : 3

uestion No. 11 Marks : 3

uestion No. 12 Marks : 10

uestion No. 13 Marks : 1

uestion No. 14 Marks : 1

uestion No. 15 Marks : 1

uestion No. 16 Marks : 1

uestion No. 17 Marks : 1

uestion No. 18 Marks : 10

uestion No. 19 Marks : 1

3. ~ Student(); 2. Student(int); 1. Student();

Page 15: CS304 Collection Of Old Papers

Q Q Q Q Q Q

Qu Q Q Q

Q

uestion No. 20 Marks : 1

uestion No. 21 Marks : 1

uestion No. 22 Marks : 1

uestion No. 23 Marks : 1

uestion No. 24 Marks : 1

estion No. 25 Marks : 3

uestion No. 26 Marks : 1

uestion No. 27 Marks : 1

uestion No. 28 Marks : 1

uestion No. 29 Marks : 1

uestion No. 30 Marks : 1

uestion No. 31 Marks :1

Q

Page 16: CS304 Collection Of Old Papers

uestion No. 32 Marks : 1

Q

Page 17: CS304 Collection Of Old Papers

www.vujannat.ning.com

CS304 Object Oriented Programming Mid Term Examination – Spring 2005

Time Allowed: 90 Minutes

Please read the following instructions carefully before attempting any of the questions: 1. Attempt all questions. Marks are written adjacent to each question. 2. Do not ask any questions about the contents of this examination from anyone. a. If you think that there is something wrong with any of the questions, attempt it to the best of your understanding. b. If you believe that some essential piece of information is missing, make an appropriate assumption and use it to solve the problem. c. Write all steps, missing steps may lead to deduction of marks. d. All coding questions should be answered using the C ++ syntax. You are allowed to use the Dev-C++ compiler to write and test your code. If you do so please remember to copy and paste your code into the examination solution area. (Do NOT share your code; your colleague could get higher marks than you!!) **WARNING: Please note that Virtual University takes serious note of unfair means. Anyone found involved in cheating will get an `F` grade in this course. Total Marks: 40 Total Questions: 3 Question No. 1 Marks : 30 Design and implement a String class that makes the following code work properly. The class should store the string in a dynamically allocated memory. int main() { String X, Y = "World!"; X = "Hello " + Y; cout<< X << endl; return 0; } Question No. 2 Marks : 05 a. Write the exact type of this pointer in a member function of a class XYZ. 02 b. Write three distinct situations in which copy constructor of a class is called. 03 Answer: a)

Page 18: CS304 Collection Of Old Papers

XYZ *this; b) 1. Assignment of private data members at the time of object creation. 2. When an object is passed by vale to a function. 3. When allocating memory dynamically we use copy constructor to avoid dangling pointer issue. Question No. 3 Marks : 05 class Complex { private: double x,y; static int z; public: Complex(double = 0.0); friend ostream& operator<<(ostream&, const Complex&); static int doSomething( ) { z = 2 * y; return z; } }; a. What is wrong in the definition of member function doSomething( ). 03 Answer: Static keyword because using static key word we are declaring a static member function doSomething(). Which can not use non static data members. b. What will be the effect of writing the friend function operator<<(…) in private part of the above class? 02 Answer: There will be no effect on friend function if we write it in private part. Friend function is a friend function and can use any private or public data member of the class. Where ever we declare it in class body.

Page 19: CS304 Collection Of Old Papers

www.vujannat.ning.com MIDTERM EXAMINATION

SPRING 2006

CS304 – object oriented programming (Session - 1 )

Marks:

Time: 120min

StudentID/LoginID: ______________________________

Student Name: ______________________________

Center Name/Code: ______________________________

Exam Date:

Please read the following instructions carefully before attempting any

question:

1. This examination is closed book, closed notes, closed neighbors.

2. Answer all questions.

a. There is no choice.

b. You will have to answer all questions correctly in this examination to get the maximum possible marks.

3. Do not ask any questions about the contents of this examination from anyone.

a. If you think that there is something wrong with any of the questions, attempt it to the best of your understanding.

b. If you believe that some essential piece of information is missing, make an appropriate assumption and use it to solve the problem.

4. Examination also consists of multiple-choice questions. Choose only one choice as your answer.

a. If you believe that two (or more) of the choices are the correct ones for a particular question, choose the best one.

b. On the other hand, if you believe that all of the choices provided for a particular question are the wrong ones, select the one that appears to you as being the least wrong.

**WARNING: Please note that Virtual University takes serious note of unfair means. Anyone found involved in cheating will get an `F` grade in this course.

Page 20: CS304 Collection Of Old Papers

For Teacher's use only Question 1 2 3 4 5 6 7 8 9 10 Total

Marks Question No: 1 ( Marks: 2 ) int *p=new int; In the code given above, memory is allocated during program:

• compilation • linking • execution • loading

Question No: 2 ( Marks: 2 ) The proper syntax to free the memory allocated to array a of five objects is

• free(a,5); • delete(a,5); • delete a; • delete [] a;

Question No: 3 ( Marks: 6 ) What methods would you add to make this class declaration very useful?

Class Cat { int GetAge() const; private: int itsAge; };

Question No: 4 ( Marks: 18 ) Write a class Coordinate that performs the mathematical operations (Addition and Multiplication) on its coordinates with the help of operator overloading. Class Coordinate should have the following Private data members

1. xCord 2. yCord

a) Write a parameterized constructor to initialize its coordinates/data members. b) Write member functions to Overload the following Operators and Display the Results after Operations.

1. + 2. *

Page 21: CS304 Collection Of Old Papers

Question No: 5 ( Marks: 17 ) Create a class named Employee, its data members are

i. empName ii. empDesignation iii. empSalary

a) Create the object of this class using parameterized constructor in order to initialize

all the three data members i.e. empName, empDesignation and empSalary b) Write a member function of this class named increment (), this function will

calculate the incremented salary of the employee. In increment function user will enter the increment amount in the current salary of the employee and displays the incremented salary after the addition of increment.

c) write the getter and setter functions for the data members of this class Question No: 6 ( Marks: 2 ) - Please choose one A system call ►

Is an entry point into the kernel code

Allows a program to request a kernel service

Is a technique to protect I/O devices and other system resources

All of the these

Question No: 7 ( Marks: 2 ) - Please choose one Logical address is generated by, ►

CPU

Compiler

Hard disk

► None of the these

Page 22: CS304 Collection Of Old Papers
Page 23: CS304 Collection Of Old Papers

WWW.vujannat.ning.comhttp://vujannat.ning.com

Largest Online Community of VU Students FINALTERM EXAMINATION

FALL 2006

CS304 - OBJECT ORIENTED PROGRAMMING (Session - 1 )

Marks: 50

Time: 120min

StudentID/LoginID: ______________________________

Student Name: ______________________________

Center Name/Code: ______________________________

Exam Date: Friday, February 09, 2007

Please read the following instructions carefully before attempting any of the questions:

1. Attempt all questions. Marks are written adjacent to each question.

2. Do not ask any questions about the contents of this examination from anyone.

a. If you think that there is something wrong with any of the questions, attempt it to the best of your understanding.

b. If you believe that some essential piece of information is missing, make an appropriate assumption and use it to solve the problem.

c. Write all steps, missing steps may lead to deduction of marks.

d. All coding questions should be answered using the C ++ syntax.

e. Choose the most appropriate choice (among the given), while answering MCQs.

3. You are not allowed to use IDE (Dev-C++ or any) in your paper. **WARNING: Please note that Virtual University takes serious note of unfair means. Anyone found involved in cheating will get an `F` grade in this course.

For Teacher's use only Question 1 2 3 4 5 6 7 8 9 Total

Marks

Page 24: CS304 Collection Of Old Papers

Question No: 1 ( Marks: 2 ) - Please choose one Which of the statements is true about destructor? ►

Destructors are used to initialize data members

Destructors return types are always void

Destructors are called in reverse order of constructor called in a class hierarchy

Destructors are used to display the data members of their respective class

Question No: 2 ( Marks: 2 ) - Please choose one Identify the type of variable that is part of a class, yet is not part of an object of that class. ►

instance

static

global

local

Question No: 3 ( Marks: 2 ) - Please choose one Which of the following operators can not be overloaded? ►

++

new

sizeof

=

Page 25: CS304 Collection Of Old Papers

Question No: 4 ( Marks: 2 ) - Please choose one Target function for a call is selected at compile time in case of ►

Static binding

Polymorphism

Encapsulation

Dynamic binding

Question No: 5 ( Marks: 2 ) - Please choose one Suppose it is required to implement a single functionality with different data type, which of the following techniques should be used ►

Inheritance

Friend function

Templates

Encapsulation

Question No: 6 ( Marks: 5 ) Identify and correct the error(s) in the given code segment.

template< typename T > class Parent { // … }; template< > class Child< int > : public Parent { // … }; int main() { Parent< char > obj; Child< int > obj2; return 0;

Page 26: CS304 Collection Of Old Papers

} Question No: 7 ( Marks: 10 ) Given are two classes A and B. class B is inherited from class A. Write a code snippet(for main function) that polymorphically call the method of class B. Also what changes do you suggest in the given code segment that are required to call the class B method polymorphically. class A { public: void method() { cout<<"A's method \n"; } }; class B : public A { public: void method() { cout<<"B's method\n"; } }; Question No: 8 ( Marks: 10 ) Implement the given class hierarchy where there exist a relation ship of inheritance between Employee and Contract (for contract employee). The Display() function of Contract should display the data that includes ; Name, Num_hours, Per_hour_sal, Salary Monthly salary of contract employee is calculated as

Salary = Per_hour_sal*Num_hours

Page 27: CS304 Collection Of Old Papers

Question No: 9 ( Marks: 15 ) A Real world Problem: This is a business rule of a bank that the Balance of customer must always be Positive, Further that it is also a business rule that a customer can not withdraw amount greater than his/her current balance. Question statement You are required to write a C++ program to solve this real world problem, using Exception Handling. Your program should consist of a class Customer and 4 instance variables. Cust_name, Cust_AC_No, Cust_balance, Amount_withdraw. Cust_name : Customer Name Cust_AC_No : Customer Account Number Cust_balance : Customer Balance Amount_withdraw : Amount that is to be withdraw The class should further consists of getter and setter function for each instance variable. The setter function of Cust_balance consists of a try and a catch block, if the user enters the balance less than zero (means negative, which is not possible) then this function should throw an exception, and its corresponding catch block should handle this exception by providing another opportunity to the user to enter the balance again. Similarly the setter of Amount_withdraw variable should also have a try and a catch blocks. If the user enters the withdraw amount greater than the current balance then this function should throw an exception, and its corresponding catch block should handle this exception.

Page 28: CS304 Collection Of Old Papers

In main function just declare an object of Customer class and call all its setter and getter functions.

Page 29: CS304 Collection Of Old Papers

WWW.vujannat.ning.comhttp://vujannat.ning.com

Largest Online Community of VU Students MIDTERM EXAMINATION

SPRING 2007

CS304 - OBJECT ORIENTED PROGRAMMING (Session - 4 )

Marks: 40

Time: 90min

StudentID/LoginID: ______________________________

Student Name: ______________________________

Center Name/Code: ______________________________

Exam Date: Thursday, May 03, 2007

Please read the following instructions carefully before attempting any of the questions:

1. Attempt all questions. Marks are written adjacent to each question.

2. Do not ask any questions about the contents of this examination from anyone.

a. If you think that there is something wrong with any of the questions, attempt it to the best of your understanding.

b. If you believe that some essential piece of information is missing, make an appropriate assumption and use it to solve the problem.

c. Write all steps, missing steps may lead to deduction of marks.

d. All coding questions should be answered using the C ++ syntax.

3. You are not allowed to use IDE (Dev-C++ or any) in your paper.

4. This paper is closed handouts. **WARNING: Please note that Virtual University takes serious note of unfair means. Anyone found involved in cheating will get an `F` grade in this course.

Page 30: CS304 Collection Of Old Papers

For Teacher's use only Question 1 2 3 4 5 6 7 8 9 10 Total

Marks Question No: 1 ( Marks: 1 ) - Please choose one The main function of scope resolution operator (::) is, ►

To define an object

To define a data member

To link the definition of an identifier to its declaration

All of the given

Question No: 2 ( Marks: 1 ) - Please choose one What is a class? ►

A class is a section of computer memory containing objects.

A class is a section of the hard disk reserved for object oriented programs

A class is the part of an object that contains the variables.

A class is a description of a kind of object.

Question No: 3 ( Marks: 1 ) - Please choose one Which of the following features of OOP is used to derive a class from another? ►

Encapsulation

Polymorphism

► Data hiding

Page 31: CS304 Collection Of Old Papers

Inheritance

Question No: 4 ( Marks: 1 ) - Please choose one Which of the following is an advantage of OOP? ►

OOP makes it easy to re-use the code

It provides an ability to create one user defined data type by extending the other

It provides the facility of defining Abstract data types through which real world entities can be defined better

All of the given options

Question No: 5 ( Marks: 1 ) - Please choose one Objects having identical characteristics belong to ►

Same class

Two different classes

Any number of different classes

Objects can not have identical characteristics

Question No: 6 ( Marks: 5 ) Write any two advantage(s) of declaring a member function as const? Question No: 7 ( Marks: 10 ) Write the code for Deep copy constructor for the given class. class MidTerm {

Page 32: CS304 Collection Of Old Papers

private: char* papername; int Totalmarks; // Code for Deep copy constructor }; Question No: 8 ( Marks: 18 ) Write a program which consists of a class named Zakat and consists of two data members OwnerName and Totalamount, the class should also consists of three constructors i.e. Default constructor , one argument constructor and two argument constructor. The class should further consists of a member function named Cal_zakat () which calculate the zakat. It should be keep in mind that the zakat will be calculated only if the Totalamount is greater than or equal to 20,000. In main, define three object of this class for respective constructors and also display the zakat for each object. Note: The zakat will be calculated by the formula (Totalamount * 2.5)/100; Question No: 9 ( Marks: 1 ) - Please choose one At the most, how many instances of certain class can be created? ►

1

6

3

none of these

Question No: 10 ( Marks: 1 ) - Please choose one class A { public: virtual void MyVirtualMethod() = 0; };

Page 33: CS304 Collection Of Old Papers

class B : public A { public: void MyVirtualMethod() { //do something } };

Considering the given code, which of the following statements is correct? ►

Class B is a an abstract class

Class A is a concrete class

Object of class A can not be instantiated

Class B is a child class of class A