Set No. Code No. 220504 II B.Tech.

II Semester Supplementary Examinations, November-2003 OBJECT ORIENTED PROGRAMMING (Common to Computer Science and Engineering, Computer Science and Information Technology, Computer Science and Systems Engineering and Electronics and Computer Engineering) Time: 3 hours Max. Marks:80 Answer any Five questions All questions carry equal marks --1. Explain about the concepts of object-oriented programming. 2.a) b) 3.a) b) c) 4. What is C preprocessor? Explain various preprocessor directives? Write a C program that reverses a string. Illustrate dynamic allocation with new operator Vs with malloc operator Write a C program to find the prime numbers in the range 1..100. Explain the significance and usage of the return statement illustrately. 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. 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. Explain about the ambiguity in inheritance with any specific program example.

1

5.a)

b)

Contd…2.

Code No.220504 6.

-2-

Set No.1

Write an example program to illustrate i) Virtual member function ii) Pure virtual member function Why do subscript operators usually come in pairs? Explain. What is the difference between the i) get( ) function and the getline( ) function. ii) get( ) function and the read( ) function. 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-

7.a) b)

8.a)

Set No. Code No. 220504 II B.Tech. II Semester Supplementary Examinations, November-2003 OBJECT ORIENTED PROGRAMMING (Common to Computer Science and Engineering, Computer Science and Information Technology, Computer Science and Systems Engineering and Electronics and Computer Engineering) Time: 3 hours Max. Marks:80 Answer any Five questions All questions carry equal marks --1. Explain about hybrid design methods and justify their use with suitable examples. 2.a) b) c) 3.a) b) c) 4. Write a C program to transpose a matrix. What is conditional inclusion of code during preprocessing? Illustrate four functions in the <ctype.h> header file. Write short notes on the scope of variables. Write a C program to test whether a number is prime or not Contrast static variable in C with static member variable in C++ 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. Explain the order of initialization of different classes constructors in multilevel inheritance with proper example program. Develop an object oriented program in C++ to create a pay roll system of an organization with the following information read from the keyboard: Employee name Employee code Designation Account number Date of joining Basic pay DA,HRA, and CCA Deduction like PPF,LIC etc. 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.

2

5.a) b)

Code No.220504 6. 7.a) b) c) 8.a)

-2-

Set No.2

Explain function overloading in base and derived classes and illustrate it with a program. How do the following two statements differ in operation? cin >> c; cin.get(c); Write a function to reverse a string in place (i.e without duplicating all the characters). Why is it necessary to include the file iostream in all our programs? 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; Write a program that demonstrates how certain exception types are not allowed to be thrown? -x-

b)

Set No. Code No. 220504 II B.Tech. II Semester Supplementary Examinations, November-2003 OBJECT ORIENTED PROGRAMMING (Common to Computer Science and Engineering, Computer Science and Information Technology, Computer Science and Systems Engineering and Electronics and Computer Engineering) Time: 3 hours Max. Marks:80 Answer any Five questions All questions carry equal marks --1. Explain Grady Booch approach for object oriented design with examples. 2.a) b) 3.a) b) c) 4. Illustrate any four functions in the <math.h> header file. Write a C function to convert upper case characters to lower case. What is recursion? Give recursive definitions for GCD of two numbers and for factorial of a number. Compare recursion with iteration. Write a C program that reads a character array and gives frequency count of each character. 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. Write a program to demonstrate how the destructor member function gets fired from the derived class objects to the base class objects through pointers. Write a program to explain how to define, declare and invoke the destructor members functions under multiple inheritance. 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. Illustrate the following with an example program for each. i) Virtual member function accessed with pointer ii) Virtual functions and the person class

3

5.a) b) c)

6.

Contd…2.

Code No.220504 7.a) b) c) 8.a)

-2-

Set No.3

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? Why is the default constructor for the ios class declared private? Why is the ios class made to be a virtual base class for the istream and ostream classes?

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. Code No. 220504 II B.Tech. II Semester Supplementary Examinations, November-2003 OBJECT ORIENTED PROGRAMMING (Common to Computer Science and Engineering, C omputer Science and Information Technology, Computer Science and Systems Engineering and Electronics and Computer Engineering) Time: 3 hours Max. Marks:80 Answer any Five questions All questions carry equal marks --1. Explain in detail about the responsibility-driven design. 2.a) b) 3.a) b) 4. Write a C function which converts a string of digits into its numeric equivalent. Illustrate any four functions in the <stdlib.h> header file. Contrast prefix usage of ++ operator with postfix usage of it. Similarly, contrast the usage of -- operator. Illustrate. Enumerate the bitwise operators in C with their use. 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. Write a program to show how to define and declare a class which consists of both virtual members and virtual destructors under multiple inheritance. 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. Use member functions to initialize the class members. Contd…2.

4

5.a) b)

Code No.220504 6.a) b) 7.a) b) 8.a) b)

-2-

Set No.4

Write a program for checking the type of a class with dynamic cast. Write a program for changing pointer types with dynamic-cast. How do the I/O facilities in C++ differ from that in C? Discuss the various forms of get( ) function supported by the input stream. How are they used? Write a program to demonstrate the concept of rethrowing an exception. Identify which of the following function template definitions are illegal. Why? i) ii) i) ii) template<class A, B>+ void fun(A, B) {………………..}; template<class A> void fun(A,A) {…………..}; template<class T, typename R> T fun(T, R) {……………….}; template<class A> A fun(int *A) {……………….}; -x-