Sunteți pe pagina 1din 9

RAJA COLLEGE OF ENGINEERING AND TECHNOLOGY, MADURAI DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

SUBJECT CODE

CS2209

SUBJECT NAME

OBJECT ORIENTED PROGRAMMING LAB

CLASS

II YR III SEM

YEAR

2012-2013(ODD)

PREPARED BY

P. SARAVANAN M.PUDUMALAR

LAB MANUAL CS2209 - OBJECT ORIENTED PROGRAMMING LAB

1. Implementation of static class member Aim: To write a program for implementation of static class member Algorithm: 1. Create a class called item. In that class initialize the static member variable 2. Write the definition of the static data member 3. Static variable is initialized to zero when the objects are created 4 .Create two methods get data and get count to get the details inside the class 5. Create a object for the class item. Using that object to call the methods 6. Static variable is incremented, when the data is read into an object. 7. Diaplay the count. 2. Implementation of static member Function Aim: To write a program for implementation of static member function Algorithm: 1. Create a class called SMF. In that class initialize the static member variable 2. Write the definition of the static data member 3. Create two methods called incre and print. In incre increment the static variable. 4. In print Print the incremented value. 5. Create an object for the class SMF. Using that object, call the static member function 6. Static member function share the static data members.

3. Default Argument Function Aim: To write a program with a default argument function. Default argument for the emp function is name and salary Eg Emp(String Raja , float 5000.45) Algorithm: 1. Create a class for the employee details. 2. Define one function with default arguments as name and salary. 3. Pass the values for the arguments and if the values are not passed then the default values will be assigned. 4. Display the output. 4. Friend Function Aim: To write a program to add two numbers using Friend Function Algorithm: 1. Create a class alpha 2. Write a friend function declaration 3. Initialize and declare the variables inside the class 4. Create an object for alpha 5. Get the input through the object 6. Pass the object as argument to the function 7. Print the result. 5. Unary operator overloading Aim: To write a program to perform a Unary operator overloading Algorithm: 1. Create a class unary. Declare the necessary variables 2. Using public to create two functions get and show to getdata and display the data

3. Declare a input function operator - ().In this function the given variable is assigned to its negative using unary operator. 4. In main function create an object for class 5. Call the get and show function and finally print the output 6. Binary operator overloading Aim: To write a program to perform a binary operator overloading Algorithm: 1. 2. 3. 4. 5. 6. Get two complex numbers Pass the complex number Using binary + operator add the two numbers Using display function, show the result In main function, create the object for the class binary Call display function and print the output

7. Parameterized Constructor Aim: To write a program for parameterized constructor Algorithm: 1. Create a class called para 2. Declare the constructor inside the class. It initializes the data members of all the objects to zero 3. Define the appropriate constructor 4. Pass the initial values as arguments to the constructor function. 5 .In main function create a object for class, and call the constructor implicitly. 8. Copy Constructor Aim: Write a program for copy constructor Algorithm: 1. 2. 3. 4. Create a class called code Declare the constructor and copy constructor inside the class In class create a method called display to display the result In main function, define the constructor. Here the object is created and initialized

5. Call the constructor and display function to display the result 9. Implementation of Destructor Aim: To write a program for implementation of destructor Algorithm: 1. Create a class called gamma 2. Declare the constructor, destructor and include the count variable inside the class 3. The count variable is incremented when the constructor is called and the variable is decremented when the destructor is called 4. Create the objects for constructor 5. Here the objects are destroyed in the reverse order of creation 10. Overloading of new and delete operators AIM: To write a program for overloading of new and delete operators Algorithm: 1. Create a class called vector 2. Include the new and delete operator function inside the class. 3. New operator creates a vector object and returns a pointer to that object. This new operator allocates the resource for its internal data members. 4. Delete operator function used to release the memory that has been allocated by the new operator 5. Write the read function and sum function in that get the details 6. In main function call the new operator, read ,sum functions 7. Display the output using read function 8. Finally call the delete operator function 11. TEMPLATE USING LINKED LIST AIM: To implement templates using linked list Algorithm: 1. Start the program. 2. Define a class list with two data members data, link. 3. Define a function create() to create an empty node.

4. Define a function insert() to insert a node in the list. 5. Define a function append() to insert a node at the tail of the list. 6. Define a function delete() to delete a node in the list. 7. Define a function list() to display entire list. 8. Define a function find() to search for a particular element in the list. 9. In the main create an object for the class list. 10. Call the create() function. 11. Call the insert() function about 5 times. 12. Call the append() function. 13. Call the delete() function. 14. Call the list() function. 15. Call the find() function. 16. Stop the program. 11. Insertion sort using function template Aim: To write a program for Insertion sort using function Template Algorithm: 1. Create a class template 2. Then create the function template using class templat 3. Insertion sort consists of N-1 passes.where Nis the number of elements to be sorted 4. The ith pass of insertion sort will insert thw ith elementA[i] in to its rightful place among A[1],A[2]A[i-1] 5. After doing this insertion sort the records occupyingA[1]A[i] are in sorted order. 12. Bubble sort using class template Aim: To write a program for Bubble sort using Class Template Algorithm: 1. Create a class template 2. Then create the function template using class template 3. The function is declared with two arguments one is for the number of items in the array and the second for the entire array elements with template type. 4. With in the function declare the temporary variable for template type 5. With in the function array elements are compared with the remaining elements of the array 6. On each iteration ith elements is sorted 7. In the main function template function can be called for any data type.

13. Exception handling for Stack AIM: To write a program for exception handling of stack. ALGORITHM: 1. Create a class of name stack. 2. Define a constructor within which top and n is assigned as 0 and 3 respectively. 3. In main, create a variable cin. 4. Display the menu of operations that is performed in stack. 5. If ch=1, call for push by try and until the top is less than or equal to 3, accept the data else point as stack overflow. 6. Catch the value and display the value as invalid. 7. If ch=2, call for pop and if top=0, then display "stack is empty" else pop the value. 8. If ch=3, call for pop and display the output. 9. End of the program. 14. Exception handling for Queue AIM: To create a program for exception handling of queue. ALGORITHM: 1. Assign the variables will as 1, front and rear as 0. 2. Display the main menu of operations that can be performed in the Queue. 3. If ch=1, get value of num and call for add(). 4. If value<0, throw 1 value, if rear>0,print "queue is full", else assign the value of 10 of rear and then increment the value of rear. 5. Display the rear and front and then the catch value. 6. If ch=2, call for de(c), else if front=rear, display that "queue is empty", else delete the value. 7. If ch=3, display the output. 8. End of the program.

15. Multiple inheritance AIM: To write a program to implement the inheritance of member functions from multiple base classes.

ALGORITHM: 1. Create a class named in and define the data members and members functions in that class 2. Create another class named in1 and define the methods for them. 3. Create another class named in2, that inherits the member functions of the base classes in and in1 and also its own member function disp(). 4. Define the functions that are declared under the classes in, in1. 5. In main, create an object for the child class in2. 6. Using the object for the class in2, invoke the functions that are inherited from two base classes. 7. Using disp(), display the result of processing. 8. End of the program. 16. SPANNING TREE GRAPH AIM: To implement spanning tree. Algorithm : 1. Start the program. 2.Define a class graph with three variables g1, g2 and c. 3.Define a function read_values() to read the points. 4.Define a function calculate_cost() and inside the function put the code for calculating minimum cost. 5.Define a function display() to print the cost. 6.In the main create object for the class graph. 7.Call the function read_values(). 8.Call the function calculate_cost(). 9.Call the function display() to display the cost. 10.Stop the program. 17. implementation of RTTI using typeid for polymorphic objects AIM: To write a program to implement RTTI using typeid for polymorphic objects. ALGORITHM: 1. Create a base class 'shape' with a virtual function draw. 2. Create a derived class 'circle' that has function draw to display the call. 3. Create another derived class 'dot' with a function someother_function. 4. Create a class with function 'rectangle' with function someother_function. 5. Create objects for classes shape, circle, rectangle as someshape and & *ptrshape, ring and square respectively.

6. Call for draw function for each object and display the output. 7. Print the objects typeid polymorphism and display their corresponding classes. 8. End of the program. 18. Dynamic Polymorphism Aim: To write a program to calculate an area of rectangle, triangle, circle using dynamic polymorphism Algorithm: 1. Create a class called shape and include the necessary variable inside the class 2. Create a method called get data inside the class, which is used to get the details. 3. Define the pure virtual function inside the class. 4. Create a class rectangle that inherits the details from the shape class. And calculate the area of the rectangle, using display area function 5. Create a class triangle that inherits the details from the shape class. And calculate the area of the triangle, using display area function 6. Create a class circle that inherits the details from the shape class. And calculate the area of the circle using display area function 7. Write the definition of the member variable. 8. In main get the choice, and print the respected output. 19. File Creation AIM: To a C++ program to implement the randomly generates complex numbers and write them two per line in a file along with an operator. The numbers are written to file in the format(a+ib).Write another program to read one line at a time from this file, perform the corresponding operation on the two complex numbers read and write the result to another file. Algorithm 1. Start the Process. 2. Create two files. 3. One file is to read and another file to write. 4. Do the operations in one file and write the result in another file. 5. Display the result. 6. Stop the Process. Prepared By : Approved By: HOD/CSE

Mr. P. Saravanan Ms.M.Pudumalar

S-ar putea să vă placă și