100% found this document useful (1 vote)
259 views

Lab Manual OOP

This document provides the syllabus and procedures for experiments in a Laboratory Manual of Programming in C++. It outlines 14 experiments covering key C++ concepts like classes, objects, inheritance, polymorphism, operator overloading, and memory management. The experiments are designed to help students understand and apply OOP principles to solve problems by decomposing them into object-oriented entities and building data and functions around those objects.

Uploaded by

Amit Bagrecha
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
259 views

Lab Manual OOP

This document provides the syllabus and procedures for experiments in a Laboratory Manual of Programming in C++. It outlines 14 experiments covering key C++ concepts like classes, objects, inheritance, polymorphism, operator overloading, and memory management. The experiments are designed to help students understand and apply OOP principles to solve problems by decomposing them into object-oriented entities and building data and functions around those objects.

Uploaded by

Amit Bagrecha
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 19

Laboratory Manual of Programming in c++ (3CS7) B.

Tech (CS) III Sem July 2012

GLOBAL INSTITUTE OF TECHNOLOGY, JAIPUR (Affiliated to Rajasthan Technical University, Kota)

Index 1. Syllabus
1. To write a simple program for understanding of C++ program structure without an CLASS declaration. Program may be based on simple input output, understanding of keyword using. 2. Write a C++ program to demonstrate concept of declaration of class with public & private member, constructors, object creation using constructors, access restrictions,defining member functions within and outside a class. Scope resolution operators,accessing an objects data members and functions through different type of objecthandle name of object, reference to object, pointer to object, assigning class objects to each other. 3. Program involving multiple classes (without inheritance) to accomplish a task.Demonstrate composition of class. 4. Demonstration Friend function friend classes and this pointer. 5. Demonstration dynamic memory management using new & delete & static classmembers. 6. Demonstration of restrictions an operator overloading, operator functions as member function and/ or friend function, overloading stream insertion and stream extraction, operators, overloading operators etc. 7. Demonstrator use of protected members, public & private protected classes, multilevel inheritance etc. 8. Demonstrating multiple inheritance, virtual functions, virtual base classes, abstract

2. Hardware/Software Requirement
Hardware requirement Processor: Pentium Ram: 512 MB Hard disk: 80 GB

Software requirement Language: c ++

3. Rational behind the lab


OOP allows decomposition of a problem into a number of entities called object and then builds data and functions around these objects. The organization of data and functions in object oriented programs. The data of an object can be accessed only by the functions associated with that object. Object oriented programming as an approach that provides a way of modularizing programs by creating portioned memory area for both data and functions that can be used as templates for creating copies of such modules on demand. BASIC CONCEPTS OF OBJECT ORIENTED PROGRAMMING Objects Classes Data abstraction and encapsulation Inheritance Polymorphism Dynamic binding Message passing

4. Practical conducted in the lab

EXPERIMENT-1 Object :- To initialize the member fields of a structure and display its contents

STANDARD PROCEDURES ALGORITHM: 1. Start the program. 2. Define the structure with the name student. 3. Define the variables name ,rollno , sex, height, weight with in the struct. 4. Declare the values of variables. 5. Print the value of members of structure. Analyzing the Problem Designing the Solution:

EXPERIMENT-2 Object:- To enter and display the record of a booking using all member function inside the class using public and private access specifier.

STANDARD PROCEDURES ALGORITHM: 1. Start the process. 2. Declare the class as name book . 3. Declare the variable book no. ,bname, auname,bprice in private access specifier and define function getdata(), display() in public access specifier. 4. Create the object obj . 5. Access the functions obj.getdata(), obj.display(). 6. Stop the process. Analyzing the Problem Designing the Solution:

EXPERIMENT-3 Object :- To write a c++ program for defining the constructor and destructor.

STANDARD PROCEDURES ALGORITHM: 1. Start the process Analyzing the Problem Designing the Solution:

2. Declare the class my class with variables a and b.

3. Using the class name, constructor is constructed to initialize the variables a and b as 10 and 20 respectively. 4. A function show ( ) is defined to display the values of a and b.

5. Using the class name preceding a tilde (~) symbol, destructor is defined to allocate the memory space. 6. During the object declaration of the class mycalss, the constructor is called.

7. Using the object, the function show( ) is called.

8. Finally the destructor is automatically called.

9. Stop the process.

EXPERIMENT-4 Object :- To write a c++ program for parameterized constructor. STANDARD PROCEDURES Analyzing the Problem Designing the Solution

ALGORITHM:

1. Start the process 2. Declare the class con with variables c. 3. Using the class name con constructed the class as overloading with difference types 4. for con( ) constructor assign c=0; show the result c

for con (int x) as one argument constructor c= x*x and display c. for con (int x,int y ) as two argument constructor c= x*y*z and display c. for con (int x, int y, int z ) as two argument constructor c= x*y*z and display c. 5. Supply the values to the constructor function con( ) with different value 6. Stop

EXPERIMENT-5 Object :- W.A.P. to implement scope resolution operator.

STANDARD PROCEDURES ALGORITHM: 1. Start the process. 2. Initialize the global variable int m=123; 3. Initialize the local variable int m=311 ; 4. Print the variable m. 5. Print the variable m using ::m. 6. Stop the process Analyzing the Problem Designing the Solution:

EXPERIMENT-6 Object :- W.A.P. to implement reference to object.

STANDARD PROCEDURES ALGORITHM: 1. Start the process. 2. Declare the variable x in private access specifier. 3. Define the functions get(),show() and change() in public access specifier. 4. In the function change() declare the reference of objects as arguments. 5. Create the objects obj1,obj2. 6. Access the functions obj1.get(),obj2.get(),obj1.show(),obj2.show() 7. Access the function change() and pass the obj2 as argument. 8. Access the function show(). Obj1.show(),obj2.show(). 9. Stop the process Analyzing the Problem Designing the Solution:

EXPERIMENT-7 Object :- To write a c++ program for find the biggest of three numbers using inline functions.

STANDARD PROCEDURES Analyzing the Problem Designing the Solution

ALGORITHM:

1.Start the process 2. Read a, b, c values 3.Goto inline functions big with a, b, c as arguments. If a>c and a>b return a Else if b>c and b>a return b Else if c>a and c>b return c otherwise return 0 4. Store the return data in r and display it 5. stop the process EXPERIMENT-8 Object :- W.A.P. to implement to implement pointer to object.

STANDARD PROCEDURES ALGORITHM: 1. Start the process. 2. Declare the class as name empdata. 3. Declare the variables emp no. salary,age,sex in private . 4. Define the functions getdata(),putdata() in public. 5. Create the object obj. 6. Create the pointer object *ptr. 7. Assigning the address of obj into *ptr. 8. Access the function functions using pointer object using -> sign. Analyzing the Problem Designing the Solution:

9. Stop the process.

EXPERIMENT-9 Object :- To write a C++ program to count the number of objects created for a class using static member.

STANDARD PROCEDURES ALGORITHM: 1. Start the process 2. Declare the class mycalss with a static variable icount. 3. Define the constructor to increment the value of icount by 1. 4. Define the destructor to decrement the value of icount by 1. 5. Define the function showcount( ) to return the value of icount. 6. Declare array of objects using new operator, then call the function showcount( ) 7. Deallocate the objects created by delete operator. 8. Stop the process. Analyzing the Problem Designing the Solution

EXPERIMENT-10 Object :- To write a c++ program to find the volume of cube, rectangle and cylinder using function overloading

STANDARD PROCEDURES ALGORITHM: Analyzing the Problem Designing the Solution

1. Start the process 2. Define a class named shape 3. Declare the function volume with one argument, two arguments and three arguments as parameter 4. Create a objects s of type shape in main function 5. Get the value of r call member function s.volume(r) 6. Get the values of r, h call member function s.volume(r,h) 7. Get the values of r,b,h call member function s.volume (r,b,h) 8. Stop the process

EXPERIMENT-11 Object :- To write a c++ program to overload the insertion and extraction operator overloading. STANDARD PROCEDURES ALGORITHM: 1. Start the program 2. Declare the class complex with private: real, imag & public:complex ( ) 3. Declare the friend istream & operator >>(istream &in, complex &c1) and friend ostream & operator <<(ostream &out, complex &c1) and friend complex operator + (complex c1, complex c2) 4. in friend istream( ) read real value as in >> c1.real and imag as in >>c1.imag 5. out friend ostream( ) print real value as in << c1.real and imag as in >>c1.imag 6. in complex() create the object t & add t.real=c1.real + c2.real t.imag=c1.imag + c2.imag 7. in main() create object cm1, cm2, cm3 and read cm1, cm2 8. calculate cm3 = cm1 +cm2 9. print cm1, cm2, cm3 10. Stop the program Analyzing the Problem Designing the Solution

EXPERIMENT-12 Object :- To write a c++ program using single inheritance. STANDARD PROCEDURES ALGORITHM: 1.Start the process 2. Declare the base class with its data members 3.Derived the derived class and inherit base class as a public 4.Derived the read the values from base class function 5.Calculate the values, from derived class function Da=bs*0.12; Hra=bs*0.07; Pf=400; 6.Display the result from derived class fnction show name, dob,basic salary, da, hra,pf 7. Stop the process Analyzing the Problem Designing the Solution

EXPERIMENT-13 Object :- To write a c++ program using multilevel inheritance STANDARD PROCEDURES ALGORITHM: Analyzing the Problem Designing the Solution

1. start the process 2. Declare the class stu with is member function 3. Derived the class test as stu base class as public, with its data members 4. Derived the derived class test to result as public with it data member 5. Read the roll numbers from derived class list. 6. Read the marks from derived class list 7. Display to total, rollno, marks, form the derived class result 8. Stop the process

EXPERIMENT-14 Object :- To write a c ++ program for using hybrid inheritance

STANDARD PROCEDURES ALGORITHM: Analyzing the Problem Designing the Solution

1. Start the process 2. Create class member variables and its functions. 3. Derived class test as student base class as public with its data members. 4. Derived class result as student, sports base class as public with its data members. 5. Read the values for rno, part1, part2 values and calculate the sport wt, total score using this derived class 6. Display all the values 7. Stop the process

EXPERIMENT-15 Object :- To write a C++ program for using multiple inheritance. STANDARD PROCEDURES

ALGORITHM:

Analyzing the Problem Designing the Solution

1. Start the process 2. Declare the class member variables and its functions 3. Getting inputs from the one base class for cust

4. Getting inputs from another one base class for acc 5. To combine both of this class to create a derived class and with base class public member function. 6. Read the inputs for using this derived class variables 7. Display the values for using choices 1. Create 2. Transaction 3. Display 8. Stop

EXPERIMENT-16 Object :- To write a C++ program for friend function.

STANDARD PROCEDURES ALGORITHM: Analyzing the Problem Designing the Solution

1. Start the process 2. Declare class named myclass with the variables a and b 3. Define the default and parameterized constructors to initialize the variables a and b.

4. Define function show( ) to display the values of a and b. 5. Declare two friend functions using operator overloading 6. Define the friend functions outside the class to find out the sum and difference of the data members. 7. During the declaration of two objects initialize the data member variables 8. Call the operator overloading functions using these objects. 9. Finally display the values by calling the function show ( ) 10. Stop the process EXPERIMENT-17 Object :- W.A.P. to implement this pointer.

STANDARD PROCEDURES ALGORITHM: Analyzing the Problem Designing the Solution:

EXPERIMENT-18 Object :- To write a C++ program for virtual function. STANDARD PROCEDURES ALGORITHM: 1. Start the process. 2. Declare a base class named figure with the variables x and y. 3. Set values for the variables using the function called setdim( ). 4. Define a virtual function called showarea( ). 5. Derived a class triangle from figure and define the function showarea ( ) to display the area of Analyzing the Problem Designing the Solution

triangle 6. Derived a class rectangle from figure and define the function showarea ( ) to display the area of rectangle. 7. Declare a base class pointer variable and objects for the class rectangle and triangle. 8. Using the pointer variable assign the address of triangle and find the area of rectangle using the virtual function showarea( ). 9. Using the pointer variable assign the address of rectangle and find the area of rectangle using the virtual function showarea( ). 10. Stop the process.

EXPERIMENT-19 Object :- To write a C++ program for exception handling. STANDARD PROCEDURES ALGORITHM: 1. Start the process. 2. Get the values of the dividend a and divisor b. 3. Check whether the divisor b is zero, if it is true then throw an exception to the catch block. 4. Otherwise divide a by b and print the result. 5. Stop the process Analyzing the Problem Designing the Solution

EXPERIMENT-20 Object :- To write a C++ program for sorting the values using template function

STANDARD PROCEDURES ALGORITHM: Analyzing the Problem Designing the Solution

1. Start the process 2. Define the template with type1, type2 as class 3. Read the n values 4. Read n float values as d 5. Read n character as c 6. Read n integer values as a 7. Sort the elements using the sort function with type1, type2 8. Display the sorted elements. 9 . Stop the process

4. References
E Balagurusamy : Object oriented programming,Tata McGraw-Hill Publishing Company Limited.

K.R.Venugopal : Mastering of c++, Tata McGraw-Hill Publishing Company Limited.

D Ravichndran,Programming with c++ ,Tanenbaum, Tata McGraw-Hill Publishing Company Limited.

Let us c++ by Yashvant kanitakar.

5. New ideas besides University Syllabus


EXPERIMENT-1 Object :marks.dat. STANDARD PROCEDURES ALGORITHM: Analyzing the Problem Designing the Solution Get roll number andmarks of the studentsofaclass and store these details into a file called

1. Start the process 2. Stream decided and declared. 3. File linked fileout.open(); 4. Declare the variable. 5. Scan and print the variable using while loop 6. Delink the file. 7. Stop the process.

6. Important Questions
1. How to define member function inside and outside in a class? 2. What is difference between constructor and destructor? 3. What is the use of inline function? 4. What is friend function ? why we use it? 5. How to allocate memory dynamic? 6. What is operator overloading ?Explain unary and binary operator overloading? 7. What is inheritance? Explain types of inheritance? 8. Why virtual keyword use in multipath inheritance? 9. What is dynamic binding? 10. Explain difference between function template and template function? 11. Explain types of errors? What is role of try ,catch, throw keyword? 12. What do you mean by dynamic binding? 13. What are virtual function? What are requirement of virtual function? 14. What is inheritance? what is the need of inheritance? 15. Explain the types of inheritance? Explain with diagram? 16. Explain the rules for virtual function? 17. What is pure virtual function and why we use it? 18. What is abstract class? How do you create an abstract class? 19. What is the use of virtual keyword in multipath inheritance? 20. When would you use virtual destructor? 21. Explain with suitable example pointer to object? 22. Write a short note on structure in c?

23. Write a short note on assign values to the members of a structure? 24. Define a structure type ,struct personal, that would contain person name ,date of joining and salary. Using this structure write a program to read this information for person from the keyboard and print on the screen? 25. Write a program to illustrate the method of sending an entire structure as a parameter to a function? 26. Write a program to illustrate the use of structure pointers? 27. What is difference between object oriented programming and procedure oriented programming? 28. Describe the feature of object oriented programming? 29. What is class and object? Explain with sutable example? 30. What is polymorphism? Explain types of polymorphism? 31. Explain the concepts of late and early binding? 32. Describe the advantage and disadvantage of oop's? 33. What is structure? Justify their need with example? 34. How does a structure differ from array? 35. What are the user defined data types? Explain with suitable examples? 36. Explain the programming paradigm?

You might also like