CS304 Collection of Old Papers
CS304 Collection of Old Papers
CS304 Collection of Old Papers
com
BEST SITE TO HELP STUDENTS
FINALTERM EXAMINATION
FALL 2006 Marks: 50
CS304 - OBJECT ORIENTED PROGRAMMING Time: 120min
(Session - 1 )
StudentID/LoginID: ______________________________
► Destructors are used to display the data members of their respective class
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
► ++
► new
► sizeof
► =
► Static binding
► Polymorphism
► Encapsulation
► Dynamic binding
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
template< >
class Child< int > : public Parent {
// …
};
int main() {
Parent< char > obj;
Child< int > obj2;
return 0;
}
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"; }
};
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
Salary = Per_hour_sal*Num_hours
Question No: 9 ( Marks: 15 )
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.
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.
www.vujannat.ning.com
class Exception {
protected:
char message [30] ;
public:
Exception() {strcpy(message,"Exception");}
char * what() { return message; }
};
class A {
public:
A(){ cout << "Constructor A\n";}
~A(){
cout << "Destructor A\n";
if(condition1) //condition one
throw Exception();
}
};
class B {
public:
B(){ cout << "Constructor B\n";
if(condition2) //condition two
throw 1;
}
~B(){ cout << "Destructor B\n";}
};
void Function1() {
DerivedException DE;
cout << "I am Function1" << endl;
if(condition3) //condition three
{
throw DE;
}
}
void Function2() {
cout << "I am Function2\n" << endl;
try{
B obj2;
Function1();
}
catch(int)
{
throw 10.1;
}
catch(...){
throw;
}
}
void Function3(){
cout << "I am Function3\n";
A obj;
Function2();
}
int main() {
try{
Function3();
}
void Function(){
if(condition1){
…
throw Exception();
}
if(condition2){
…
throw DerivedException();
}
if(condition3){
throw 1;
}
}
template< >
class RBTree< int > : public Tree {
// …
};
int main() {
Tree< char > chTree;
RBTree< int > intRBTree;
return 0;
}
b) Consider the following vector class: 20
class Vector {
…
public:
…
int* first();
int* last();
int* next( int* );
};
CS304
Final Term Examination – Spring 2006
Time Allowed: 150 Minutes
What is the name of the function that overloads the + operator for the complex class?
1. add
2. complex add
3. +
4. operator +
5. operator
Write two classes Customer and Account. Declare Account as a friend class of Customer.
a) Write parameterized constructors for both classes i.e. Customer and Account, to initialize their
data members. For Customer class initialize cusbalance to zero.
b) Write a member function of Account class, named setBalance ( ) to assign AccBalance to
cusbalance, which is a data member of Customer class.
Write a member function for the Customer class, named displaytData ( ) to display the values of
Customer’s cusName, cusAddress and cusbalance.
a) Write a C++ program which creates a class Employee with the following attribute
1. name
This class should have a parameterized constructor and destructor, the getter/setter functions and a
virtual member function called pay () that returns the salary of the Employee.
b) Create a class named as Salaried that inherits from class Employee. A Salaried object has the
following attribute
1. salary
This class should also have parameterized constructor and default destructor, setter/getter functions
and a pay () member function.
c) Similarly, develop a class named as Hourly that inherits from class Employee. An Hourly object is
distinguished by the following attributes
1. hours
2. rate
This class should also have a parameterized constructor, default destructor, setter/getter functions and
a pay () member function.
Your program should create objects of Salaried and Hourly classes and then invoke the pay () function
of these classes polymorphicly (through Employee Object)
Write a C++ program to determine the area and perimeter of rectangle according to the length and
width entered by the user. Your code should include a template <class T>.
1: length
2: width
The area and perimeter should be calculated for each int, float and double type data member. Hence the
data member of the class rectangle should be of type Template as well.
Your program should have following member functions of a template <class T>.
1: area ();
This member function will calculate the area of the rectangle. The area of a rectangle can be calculated
by the following formula:
2: perimeter ();
This member function will calculate the perimeter of the rectangle where the formula for perimeter of
rectangle is
Area() and perimeter() member functions should return the same type on which the data is
manipulating. For example
If the area is calculating for a rectangle of int type length and width, then this member function should
return an integer number and vice versa.
Take three instances of one of each type of data members’ int, float, and double for the class rectangle
in main ().
Also write setter and getter for the data member of the class rectangle.
Is there any difference between abstract and base class? If yes, then what is it?
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
int main()
{
String X, Y = "World!";
X = "Hello " + Y;
cout<< X << endl;
return 0;
}
StudentID/LoginID: ______________________________
Exam Date:
a. There is no choice.
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.
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.
For Teacher's use only
Question 1 2 3 4 5 6 7 8 9 10 Total
Marks
• compilation
• linking
• execution
• loading
• free(a,5);
• delete(a,5);
• delete a;
• delete [] a;
Class Cat
{
int GetAge() const;
private:
int itsAge;
};
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
A system call
► CPU
► Compiler
► Hard disk
FINALTERM EXAMINATION
FALL 2006 Marks: 50
CS304 - OBJECT ORIENTED PROGRAMMING Time: 120min
(Session - 1 )
StudentID/LoginID: ______________________________
► Destructors are used to display the data members of their respective class
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
► ++
► new
► sizeof
► =
Question No: 4 ( Marks: 2 ) - Please choose one
► Static binding
► Polymorphism
► Encapsulation
► Dynamic binding
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
template< >
class Child< int > : public Parent {
// …
};
int main() {
Parent< char > obj;
Child< int > obj2;
return 0;
}
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"; }
};
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
Salary = Per_hour_sal*Num_hours
Question No: 9 ( Marks: 15 )
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.
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.
WWW.vujannat.ning.com
http://vujannat.ning.com
Largest Online Community of VU Students
MIDTERM EXAMINATION
SPRING 2007 Marks: 40
CS304 - OBJECT ORIENTED PROGRAMMING Time: 90min
(Session - 4 )
StudentID/LoginID: ______________________________
► To define an object
What is a class?
► A class is a section of the hard disk reserved for object oriented programs
Which of the following features of OOP is used to derive a class from another?
► Encapsulation
► Polymorphism
► Data hiding
► Inheritance
► 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
► Same class
Write the code for Deep copy constructor for the given class.
class MidTerm
{
private:
char* papername;
int Totalmarks;
};
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.
► 1
► 6
► 3
► none of these
class A
{
public:
virtual void MyVirtualMethod() = 0;
};
class B : public A
{
public:
void MyVirtualMethod()
{
//do something
}
};