OOPM Lab-Manual
OOPM Lab-Manual
Lab Manual
for
OOPS &
Methodology
Lab 2019-20
2nd Year
By
LIST OF EXPERIMENTS
S.No. EXPERIMENTS
Algorithm
1. Read the 3 nos a,b,c
2. Let larget = a
3. if b > largest then largest = b
4. if c > largest then largest = c.....
If you have to process more nos, read all of them in an array. Assume the first element be
largest, do comparison through all elements of the array....
Similar algorithm can be developed for finding the lowest also.
Aim: Write a program in C++ to implement the multiplication of [3*3] matrix using Array.
Algorithm
Input two matrixes.
1. Output Output matrix C.
2. Complexity O(n^3)
3.
4. Matrix-Multiply(A, B)
5. 1 if columns [A] ≠ rows [B]
6. 2 then error "incompatible dimensions"
7. 3 else
8. 4 for i =1 to rows [A]
9. 5 for j = 1 to columns [B]
10. 6 C[i, j] =0
11. 7 for k = 1 to columns [A]
12. 8 C[i, j]=C[i, j]+A[i, k]*B[k, j]
13. 9 return C
Aim: Write a program in C++ to implement quadratic equation using class & Object.
Algorithm:
1. Read the value of a , b , c
2. d = b*b - 4*a*c
3. if d < 0 then display The Roots are Imaginary.
else if d = 0
then dispaly Roots are Equal.
r = -b / 2*a
display r
4. Stop
Algorithm
STEP 2: Declare the class name as Copy with data members and member functions.
STEP 3: The constructor Copy() with argument to assign the value.
STEP 4: To cal the function calculate() do the following steps.
STEP 5: For i=1 to var do
STEP 6: Calculate fact*i to assign to fact.
STEP 7: Increment the value as 1.
STEP 8: Return the value fact.
STEP 9: Print the result.
STEP 10: Stop the program.
Algorithm
Step 1: Start the program.
Step 2: Declare the base class student.
Step 3: Declare and define the function get() to get the student details.
Step 4: Declare the other class sports.
Step 5: Declare and define the function getsm() to read the sports mark.
Step 6: Create the class statement derived from student and sports.
Step 7: Declare and define the function display() to find out the total and average.
Step 8: Declare the derived class object,call the functions get(),getsm() and display().
Step 9: Stop the program.
Algorithm
STEP 1: Start the program.
STEP 2: Declare the class name as fn with data members and member functions.
STEP 3: Read the choice from the user.
STEP 4: Choice=1 then go to the step 5.
STEP 5: The function area() to find area of circle with one integer argument.
STEP 6: Choice=2 then go to the step 7.
STEP 7: The function area() to find area of rectangle with two integer argument.
STEP 8: Choice=3 then go to the step 9.
STEP 9: The function area() to find area of triangle with three arguments, two as Integer and
one as float.
STEP 10: Choice=4 then stop the program.
Aim: Write a program in C++ to implement virtual class & virtual function.
Algorithm
Step 1: Start the program.
Step 2: Declare the variables a,b,c.
Step 3: Read the values a,b,c,.
Step 4: Inside the try block check the condition.
a. if(a-b!=0) then calculate the value of d and display.
b. otherwise throw the exception.
Step 5: Catch the exception and display the appropriate message.
Step 6: Stop the program.
Algorithm
STEP 1: Start the program.
STEP 2: Declare the template class.
STEP 3: Declare and define the functions to swap the values.
STEP 4: Declare and define the functions to get the values.
STEP 5: Read the values and call the corresponding functions.
STEP6: Display the results.
STEP 7: Stop the program
Aim: Write a program in C++ for writing file operation using file handling.
Algorithm
STEP 1: Start the program.
STEP 2: Declare the variables.
STEP 3: Read the file name.
STEP 4: open the file to write the contents.
STEP 5: writing the file contents up to reach a particular condition.
STEP 6: Stop the program.
EXPERIMENT-11
Algorithm
STEP 1: Start the program.
STEP 2: Declare the variables.
STEP 3: Read the file name.
STEP 4: open the file to write the contents.
STEP 5: writing the file contents up to reach a particular condition.
STEP 6: Stop the program.
EXPECTED VIVA VOICE QUESTIONS
1. What is C++?
C++ is created by Bjarne Stroustrup of AT&T Bell Labs as an extension of C, C++ is an object-oriented
computer language used in the development of enterprise and commercial applications. Microsoft’s
Visual C++ became the premier language of choice among developers and programmers.
Objects
Classes
Inheritance
Polymorphism
Dynamic Binding
Message passing
3. Define inheritance?
The mechanism of deriving a new class (derived) from an old class (base class) is called inheritance. It
allows the extension and reuse of existing code without having to rewrite the code from scratch.
Inheritance is the process by which objects of one class acquire properties of objects of another class.
4. Define polymorphism?
Polymorphism means one name, multiple forms. It allows us to have more than one function with the
same name in a program. It allows us to have overloading of operators so that an operation can exhibit
different behaviors in different instances.
All the features of C are similiar to C++ except some features, such as polymorphism, operator
overloading which are supported in C++ but not in C language. Both C and C++ language is similiar in
their functionality but C++ provides with more tools and options.
6. What is encapsulation?
The wrapping up of data and functions into a single unit (called class) is known as encapsulation.
Encapsulation containing and hiding information about an object, such as internal data structures and
code.
An object oriented program consists of a set of objects that communicate with each other. Message
passing involves specifying the name of the object, the name of the function and the information to be
sent.
The smallest individual units of a program is known as tokens. c++ has the following tokens :
Keywords
Identifiers
Constants
Strings
Operators
An enumerated data type is another user defined type which provides a way for attaching names to
numbers thereby increasing comprehensibility of the code. The enum keyword automatically
enumerates a list of words by assigning them values 0,1,2, and so on.
A constructor that accepts no parameters is called the default constructor. If no user-defined constructor
exists for a class A and one is needed, the compiler implicitly declares a default parameter less
constructor A::A(). This constructor is an inline public member of its class. The compiler will implicitly
define A::A() when the compiler uses this constructor to create an object of type A. The constructor will
have no constructor initialize and a null body.
A constructor is a member function with the same name as its class. The constructor is invoked
whenever an object of its associated class is created.It is called constructor because it constructs the
values of data members of the class.
C requires all the variables to be declared at the beginning of a scope but in c++ we can declare
variables anywhere in the scope. This makes the programmer easier to understand because the variables
are declared in the context of their use.
C++ ia an object oriented programming but C is a procedure oriented programming.C is super set of
C++. C can’t support inheritance, function overloading, method overloading etc. but c++ can do this. In
c program the main function could not return a value but in the c++ the main function shuld return
a value.
It offers an improved macro facility. By using the inline functions, the user can split a large function
with many nested modules of statement blocks into many small inline functions.
Copy constructor is a constructor function with the same name as the class and used to make deep copy
of objects.
A default constructor is a constructor that either has no parameters, or if it has parameters, all the
parameters have default values.
The scope resolution operator permits a program to reference an identifier in the global scope that has
been hidden by another identifier with the same name in the local scope.
An instance of a user-defined type is called an object. We can instantiate many objects from one class.
An object is an instance of a class.
Inline follows strict parameter type checking, macros do not. Macros are always expanded by
preprocessor, whereas compiler may or may not replace the inline definitions.
variables anywhere in the scope. This makes the programmer easier to understand because the variables
A class can inherit properties from more than one class which is known as multiple inheritance.
A virtual destructor in C++ is used primarily to prevent resource leaks by performing a clean-up of the
object.
A reference variable provides an alias to a previously defined variable.Data -type & reference-name =
variable name
Iterator class provides an access to the class which are inside the containers(it holds a group of objects in
an organized way). The containers include the data structure, class and abstract data type.
Smart pointers are almost similar to pointers with additional features such as automatic destruction of a
variable when it becomes out of scope and the throwing of exceptions that ensures the proper destruction
of the dynamically allocated objects.
Function template provides a means to write generic functions for different data types such as integer,
long, float or user defined objects.
Class template provides a means to write a generic class for different types so that a class can have
members based on generic types that do not need to be defined at the moment of creating the class or
whose members use these generic types.
The constructor can also be used to allocate memory while creating objects. Allocation of memory to
objects at the time of their construction is known as dynamic construction of objects.The memory is
allocated with the help of the new operator.
The main difference between an array and a list is how they internally store the data. whereas Array is
collection of homogeneous elements. List is collection of heterogeneous elements.
36. What is the difference between a template class and class template?
Template classA generic definition or a parameterized class not instantiated until the client provides the
needed information. It’s jargon for plain templates.Class templateA class template specifies how
individual classes can be constructed much like the way a class specifies how individual objects can be
constructed. It’s jargon for plain classes.
The function declaration should be preceded by the keyword friend. The function definitions does not
use either the keyword or the scope operator :: The functions that are declared with the keyword friend
as friend function. Thus, a friend function is an ordinary function or a member of another class.
A scope resolution operator (::), can be used to define the member functions of a class outside the class.
A pure virtual member function is a member function that the base class forces derived classes to
provide. Any class containing any pure virtual function cannot be used to create object of its own type.
A converting constructor is a single-parameter constructor that is declared without the function specifier
explicit.The compiler uses converting constructors to convert objects from the type of the first parameter
to the type of the converting constructor’s class.
Associative containers are designed to support direct access to elements using keys. They are not
sequential. There are four types of associatives containers : Set Multiset Map Multimap
Iterators are like pointers. They are used to access the elements of containers thus providing a link
between algorithms and containers. Iterators are defined for specific containers and used as arguments to
algorithms.
It is a pointer that points to the current object. This can be used to access the members of the current
object with the help of the arrow operator.
Encapsulation (or information hiding) is the process of combining data and functions into a single unit
called class.
The run time type identification comes at a cost of performance penalty. Compiler maintains the class.
New initializes the allocated memory by calling the constructor. Memory allocated with new should be
released with delete. Malloc allocates uninitialized memory.The allocated memory has to be released
with free.new automatically calls the constructor while malloc(dosen’t)