Вы находитесь на странице: 1из 6

ANNA UNIVERSITY: CHENNAI 600 025 M.C.

.A DEGREE EXAMINATIONS, MAY/JUNE 2012 Second Semester MC9227: OBJECT ORIENTED PROGRAMMING LAB (Regulations 2009) Time: 3 Hours 1. a. Develop a C++ program to perform the following: Define a class to represent a bank account. Include the following: Data members: Name of the depositor Account number Type of account Balance amount in the account Member functions: To assign initial values To deposit an amount To withdraw an amount after checking the balance To display account number, name and balance Maximum Marks: 100 40

b. Create two classes DM and DB which store the values of distances. DM stores distances in metres and centimeters and DB in feet and inches. Write a program that can read values for the class objects and add one object of DM with another object of DM. Use a friend function to carry out the addition operation. The object that stores the results may be a DM object or DB object, depending on the units in which the result are required. The display should be in the format

50

of feet and inches or metres and centimeters depending on the object on display c. Viva-Voce 10

2.

a. Develop a C++ program to implement a Stack ADT and illustrate with member functions PUSH and POP operations. Use Classes.

90

b. Viva-Voce

10

3.

a. Develop a C++ program to implement a Queue ADT and illustrate with member functions insertion and deletion operations. Use Classes.

90

b. Viva-Voce

10

4.

a. Develop a C++ program for the following application: A book shop maintains the inventory of books that are being sold at the shop. The list includes details such as author, title, price, publisher and stock position. Whenever a customer wants a book, the sales person input the title and author and the system searches the list and displays whether it is available or not. If it is not, an appropriate message is displayed. If it is, then the system displays the book details and requests for the number of copies required. If the requested copies are available, the total cost of the requested copies is displayed; otherwise the message Required copies not in stock is displayed. Define a class called books with suitable member function and constructors. Use new operator in constructors to allocate memory space required.

90

b. Viva-Voce

10

5.

a. Develop a C++ program to perform the following: Define a class named COMPLEX for representing complex numbers that contains necessary data members and member functions. A complex the general form a + ib, where a is the real part and b is the stands for imaginary). Overload all the four arithmetic

90

number has

imaginary part (i

operators so that they operate on the objects of COMPLEX.

b. Viva-Voce

10

6.

a. Develop a C++ program for the following application: A bank maintains two kinds of accounts for customers, one called as savings account and the other as current account. The savings account interest and withdrawal facilities but no cheque book

90

provides compound

facility. The current account provides cheques book facility but no interest. Current account holders should also maintain a minimum balance and if

the balance falls below this level, a service charge is imposed. 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 tasks: Accept deposit from a customer and update the balance. Display the balance. Compute and deposit interest. Permit withdrawal and update the balance. Check for the minimum balance, impose penalty, necessary, and update the balance. Do not use constructors. Use member function to initialize the class members.

b. Viva-Voce

10

7.

a. Develop a C++ program to implement the following: Create a base class called shape. Use this class to store two double type values that could be used to compute the area of shapes. Derive two specific classes called triangle and rectangle from the base shape. Add to the class, a member function get_data () to initialize base class data member and another member function display_area () to compute and display the area of a shape. Make display_area () as a virtual function and redefine this function in the derived classes to suit their requirements. Using these three classes, design a program that will accept dimensions of a triangle or a rectangle interactively, and display the area. Remember the two values given as input will be treated as lengths of two sides in the case of rectangles, and as base and height in the case of triangle, and used as follows: Area of Rectangle = X * Y Area of triangle = * X * Y b. Viva-Voce

90

10

8.

a. Develop a C++ program to implement the following: Write a class int_stack that will manage a stack of integers. The integers values will be stored in a dynamically allocated array. This class will propose the following member functions: int_stack (int n) constructor that will dynamically allocate n integers, int_stack ( ) constructor allocating 20 integers, ~ int_stack ( ) destructor, int empty ( ) the return value is 1 if the stack is empty, 0 otherwise, int full ( ) the return value is 1 if the stack is full, 0 otherwise, void operator < (int p) pushes (add) the p value on the stack, int operator >(int p) returns (and remove) the value on the top of the stack, plus a copy constructor and an assignment operator. b. Viva-Voce

90

10

9.

a. Develop a C++ program to implement the following: Define a class Array, when constructing an object of this class, mention the lower and upper bounds. Only positive values should be inserted. Provide the way to push and pop information in the array, and an operator to directly access to on element within the bounds. Exceptions should be thrown when trying to store a negative value, accessing, push or popping outside the bounds.

90

b. Viva-Voce

10

10.

a. Develop a C++ program to implement a stack data structure as a template class which can store any data type. Illustrate PUSH and POP operations. b. Viva-Voce

90

10

11.

a. Develop a C++ program to implement a queue data structure as a template class which can store any data type. Illustrate insertion and deletion operations. b. Viva-Voce

90

10

12.

a. Develop a C++ program to overload a unary operator in postfix form implemented as friend function. b. Viva-Voce

90

10

13.

a. Develop a C++ program to overload a unary operator in prefix form implemented as friend function. b. Viva-Voce

90

10

14.

a. Develop a C++ program to perform the following: Define an enumeration called Month for the months of the year and use it to define a function which takes a month as argument and returns it as a constant string. Test the function with a main program. b. Develop a C++ program to perform the following: Define a class named Sequence for storing sorted strings. Define a constructor, a destructor, and the following member functions for Sequence: Insert which inserts a new string into its sort position. Delete which deletes an existing string. Find which searches the sequence for a given string and returns true if it finds it, and false otherwise. Print which prints the sequence strings. C. Viva-Voce

40

50

10

15.

a. Develop a C++ program to sort N names alphabetically. Use Classes.

40

b. Develop a C++ program to perform binary search on an array of N numbers.

50

C. Viva-Voce

10

Вам также может понравиться