NR 220504 Object Oriented Programming
NR 220504 Object Oriented Programming
3.a) Illustrate dynamic allocation with new operator Vs with malloc operator
b) Write a C program to find the prime numbers in the range 1..100.
c) Explain the significance and usage of the return statement illustrately.
4. Implement a circle class. Each object of this class will represent a circle, storing
its radius and the x and y coordinates of its center as float. Include a default
constructor, access functions (to accept and to print), an area( ) function, and a
circumference () function.
5.a) Develop an object oriented programming in C++ to prepare the mark sheet of an
university examination with the following items read from the keyboard:
Name of the student
Roll number
Subject name
Subject code
Internal marks
External marks
Design a base class consisting of the data members such as name of the student,
roll number and subject name. The derived class consists of the data member’s
viz., subject code, internal marks and external marks. The program must be able
to build a table, list a table, insert a new entry and deleting a new entry.
b) Explain about the ambiguity in inheritance with any specific program example.
Contd…2.
Code No.220504 -2- Set No.1
8.a) Write a class template to represent a generic vector. Include member functions to
perform the following tasks:
i) to create the vector
ii) to modify the value of a given element
iii) to multiply by a scalar value
iv) to display the vector in the form (10,20,30,……)
b) Explain the differences between Templates and Macros.
-x-
Set No.
4. Implement a square class. Each object of this class will represent a square, storing
its side as float. Include a default constructor, access functions (to accept and to
print), an area( ) function, and a perimeter( ) function.
Design a base class consisting of employee name, code and designation and
another base class consisting of the data member, such as account number and
date of joining. The derived class consists of the data member of basic pay plus
other earnings and deductions. The program must build a master table, list a
table, inset a new entry edit entry and search for a record that is to be printed.
Contd…2.
Code No.220504 -2- Set No.2
6. Explain function overloading in base and derived classes and illustrate it with a
program.
8.a) Identify which, if any, of the following template instantiations are valid. Explain
why?
template<int *ptr> class Ptr {…………………};
template< class Type, int size> class Fixed_Array {………};
template<int hi, int wid> class Screen {……………..};
i) const int size = 1024;
Ptr < &size > bp1;
ii) Ptr < 0 > bp2;
iii) int arr[10];
Ptr < arr >bp3;
iv) const double db = 3.1415;
Fixed_Array < double, db > fa1;
v) const int hi = 40;
const int wi = 80;
Screen < hi, wi+32 > sObj;
b) Write a program that demonstrates how certain exception types are not allowed to
be thrown?
-x-
Set No.
3.a) What is recursion? Give recursive definitions for GCD of two numbers and
for factorial of a number.
b) Compare recursion with iteration.
c) Write a C program that reads a character array and gives frequency count
of each character.
4. Implement a rectangle class. Each object of this class will represent a rectangle,
storing its sides as float. Include a default constructor, access functions (to accept
and to print), an area( ) function, and a perimeter( ) function.
5.a) Write a program to demonstrate how the destructor member function gets fired
from the derived class objects to the base class objects through pointers.
b) Write a program to explain how to define, declare and invoke the destructor
members functions under multiple inheritance.
c) Explain how public members of a class can be accessed by the following:
i) member function of the class
ii) non-member functions of the class
iii) member functions of the friend class.
Contd…2.
Code No.220504 -2- Set No.3
7.a) Why is the use of the << and >> operators called “formatted” I/O, and the use of
the functions put( ), get( ), read( ), write( ) etc., call “unformatted” I/O?
b) Why is the default constructor for the ios class declared private?
c) Why is the ios class made to be a virtual base class for the istream and ostream
classes?
8.a) Which, if any, of the following throw expressions are errors? Why? For the valid
throw expressions, indicate the type of the exception thrown?
i) class exceptionType { };
throw exceptionType( );
ii) int excpObj;
throw excpObj;
iii) enum mathErr {overflow, underflow, zeroDivide };
throw zeroDivide( );
iv) int *pi = excpObj;
throw pi;
b) Name the two template compilation models supported in C++. Explain how
programs with function template definitions are organized under each
compilation model.
-x-
Set No.
2.a) Write a C function which converts a string of digits into its numeric
equivalent.
b) Illustrate any four functions in the <stdlib.h> header file.
3.a) Contrast prefix usage of ++ operator with postfix usage of it. Similarly, contrast
the usage of -- operator. Illustrate.
b) Enumerate the bitwise operators in C with their use.
4. Implement a sphere class. Each object of this class will represent a sphere with
float data members for radius and the three-dimensional point center. Include a
default constructor, access functions (to accept and to print), a surface area( )
function, and a volume( ) function.
5.a) Write a program to show how to define and declare a class which consists of both
virtual members and virtual destructors under multiple inheritance.
b) Consider a bank maintains two kinds of accounts for customers, savings account
and current account. The savings account provides compound interest and
withdrawal facilities but no cheque facility. The current account provides cheque
book facility but no interest.
Create a class account that stores customer name, account number and type of
account. From this, derive the classes cur_acct and sav_acct to make them more
specific to their requirements. Include necessary member functions in order to
achieve the following tasks:
(a) Accept deposit from a customer and update the balance.
(b) Display the balance.
(c) Compute and deposit interest.
(d) Permit withdrawal and update the balance.
Contd…2.
Code No.220504 -2- Set No.4
6.a) Write a program for checking the type of a class with dynamic cast.
b) Write a program for changing pointer types with dynamic-cast.
i) template<class A, B>+
void fun(A, B) {………………..};
ii) template<class A>
void fun(A,A) {…………..};
i) template<class T, typename R>
T fun(T, R) {……………….};
ii) template<class A>
A fun(int *A) {……………….};
-x-