0% found this document useful (0 votes)
121 views

CS6461-Oops Lab Manual

The document provides an index and list of experiments for an Object Oriented Programming lab manual. The index includes C++ and Java programs covering topics like classes and objects, inheritance, polymorphism, operator overloading, file handling, threads, and exceptions. Example experiments listed implement functions with default arguments in C++, classes with data members in C++, static member functions in C++, and calculate student total marks using inheritance and virtual base classes.

Uploaded by

Y Rohit
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
121 views

CS6461-Oops Lab Manual

The document provides an index and list of experiments for an Object Oriented Programming lab manual. The index includes C++ and Java programs covering topics like classes and objects, inheritance, polymorphism, operator overloading, file handling, threads, and exceptions. Example experiments listed implement functions with default arguments in C++, classes with data members in C++, static member functions in C++, and calculate student total marks using inheritance and virtual base classes.

Uploaded by

Y Rohit
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 27

Object Oriented Programming Lab Manual CS6461

EASWARI ENGINEERING COLLEGE


DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
OBSEVATION NOTE BOOK
2015 – 16 / Even Semester

CS6461

OBJECT ORIENTED PROGRAMMING


LABORATORY

Student Name:
Registration
Number:
Year/Sec:

INCHARGE SIGNATURE
PAGE
EXP.NO TITLE DATE SIGN
NO

.
Object Oriented Programming Lab Manual CS6461

INDEX

LIST OF LABORATORY EXPERIMENTS

C++ Programs
1. A. Functions with default arguments
1. B. Call by value, call by reference and call by address
2. A. Classes and objects

.
Object Oriented Programming Lab Manual CS6461

2. B. Static member function


2. C. Pointer Member Function
2. D. Constant Member Function
2. E. Static Member Function
3. A. Operator overloading
3. B. Function overloading
4. A. Inheritance and virtual base class
4. B. Virtual functions
4. C. Function template
5. A. File handling: sequential file access
5. B. File handling: random file access

Java Programs
6. A. Class and object in java
6. B. Strings in java
7. Packages in java
8. Interfaces in java
9. A. Threads in java
9. B. Multithreading
10. A. Exception handling
10. B. User defined exception

CS 6461- OBJECT ORIENTED PROGRAMMING LAB EXPERIMENTS


Sl. No Name of the Experiment

C ++ PROGRAMS
1 To Write a C++ program using functions to
a) Implement function overloading and default arguments.
b) Implement call by value, call by address and call by reference.
2 To write a C++ program to implement simple classes for understanding objects,
member functions & constructors.
a) classes with primitive data members
b) classes with arrays as data members
c) classes with pointers as data members
d) classes with constant data members
.
Object Oriented Programming Lab Manual CS6461

e) classes with static member functions


To write a C++ program to implement compile time polymorphism using
3 a) Operator overloading
b) Function overloading
To write a C++ program to implement run time polymorphism by using
a) Inheritance and virtual base classes
4 b) Virtual functions
c) Templates

To write a C++ program to implement file handling


a) Sequential Access
5
b) Random Access

JAVA PROGRAMS
To write a Simple Java application program for
6 a) Understanding references to an instant of a class.
b) Handling strings in Java.
To write a java program to
7 a) Create simple package creation.

To write a java program to implement interfaces for


8
a) Developing user defined interfaces.
To write a java program for the
9 a) Creation of threading in java applications.
b) Multi threading.
To write a java program to implement the concept of exception handling mechanism.
10 a) handling predefined exceptions
b) handling user defined exceptions

CONTENT BEYOND SYLLABI

Sl. No Name of the Experiment


1 To write a C++ program to do console operations.

2 To write a C++ program to read the contents of a file.

3 To develop a java program to read and sort the contents of the file.

.
Object Oriented Programming Lab Manual CS6461

EX NO: 1 A FUNCTION OVERLOADING AND DEFAULT ARGUMENTS IN C++

Aim:
To write a C++ program to implement function overloading and use default arguments.

Algorithm:

Function Overloading

1. Start the program.


2. Create functions with same name but different arguments
3. In each function perform different operations and return the RESULT
4. Call the function by passing different arguments.
5. Print the RESULT.

.
Object Oriented Programming Lab Manual CS6461

6. Stop the program

Default Arguments

1. Start the program.


2. Create a function in which one or many arguments can be defined in default.
3. Call the function without specifying one or many arguments.
4. Print the RESULT
5. Stop the program

EX NO: I B IMPLEMENTATION OF CALL BY VALUE, CALL BY ADDRESS AND


CALL BY REFERENCE

Aim:

To write a C++ program using functions to implement call by value, call by address
and call by reference

Algorithm:

1. Start the program


2. Declare and define a function swapval using call by value
3. Declare and define a function swapref using call by reference
4. Declare and define a function swapadr using call by address

.
Object Oriented Programming Lab Manual CS6461

5. Pass necessary arguments to these functions


6. Display the output
7. Stop the program

EX NO: 2 A SIMPLE CLASSES AND OBJECTS

Aim:
To write a C++ program to implement classes and objects.

Algorithm:

1. Start the program.


2. Create a class Create a class student which contains primitive data members and constant
data members.
3. Define a constructor to initialize the data members.
4. Define the methods get and display to get and display the data members.
5. Create object for the class to access the member function.
6. Display the RESULT.

.
Object Oriented Programming Lab Manual CS6461

7. Stop the program

EX NO: 2 B STATIC MEMBER FUCTION

Aim:

To write a C++ program to implement static member function

Algorithm:
1. Start the program.
2. Declare the class name as Stat with data member s and member functions.
3. The constructor Stat() which is used to increment the value of count as 1 to to assign
the variable code.
4. The function showcode() to display the code value.
5. The function showcount() to display the count value.

.
Object Oriented Programming Lab Manual CS6461

6. Stop the program.

EX NO: 3A IMPLEMENTATION OF OPERATOR OVERLOADING

Aim:

To write a C++ program to implement operator overloading

Algorithm:

1. Operator Overloading
2. Start the Program.
3. Declare a class as complex with real and imaginary part as data members
4. Define constructor overloading to assign different value for complex data member
5. Define member function getdata () to get the value of complex no

.
Object Oriented Programming Lab Manual CS6461

6. Define operator function + () to perform complex addition.


7. Define member function Display () to display complex number.
8. In main function create object, invoke constructor, member function and operator
function through object
9. Stop the program

EX.NO 3 B FUNCTION OVERLOADING

Aim:

To write a C++ program to implement the concept of Operator Overloading

Algorithm:
1. Start the program.
2. Declare the prototypes for volume function to find volume of cube, cylinder, and rectangle.
3. Get the input values such as side, length, breadth, height, and radius.
4. Invoke volume function of cylinder by passing radius and height to find volume of cylinder.
5. Invoke volume function of cube by passing side of cube to find volume of cube.
6. Invoke volume function of Rectangle by passing length, breadth and height to find volume
. of rectangle.
7. Print the volume of cube, cylinder and rectangle
.
Object Oriented Programming Lab Manual CS6461

8. Stop the program.

EX NO: 4 A INHERITANCE AND VIRTUAL BASE CLASS

AIM:

To calculate the total mark of a student using the concept of inheritance and virtual
base class.

ALGORITHM:

1. Start the program.


2. Declare the base class student.
3. Declare and define the functions getnumber () and putnumber ().
4. Create the derived class test virtually derived from the base class student.
5. Declare and define the function getmarks () and putmarks ().
6. Create the derived class sports virtually derived from the base class student.
.
Object Oriented Programming Lab Manual CS6461

7. Declare and define the function getscore () and putscore ().


8. Create the derived class RESULT derived from the class test and
sports.
9. Declare and define the function display () to calculate the total.
10. Create the derived class object obj.
11. Call the function get number (), getmarks (), getscore () and
display().
12. Stop the program

EX NO: 4 B VIRTUAL FUNCTIONS

Aim:

To write a C++ program to implement run time polymorphism through virtual function.

Algorithm:
1. Start the program
2. Declare a base and define display () member function to display base class content.
define show() member function to show base class content.
3. Declare a derived class inherit from base and define display () member function to
display derived class content. Define show () member function to derived class content.
4. In main function create object for base and derived class.
5. Assign base ptr to base class object.
6. Invoke display function of base class using base pointer variable

.
Object Oriented Programming Lab Manual CS6461

7. Invoke show function of base class using base pointer variable


8. Assign base ptr to derived class object.
9. Invoke display function of base class using base pointer variable
10. Invoke show function of derived class using base pointer variable
11. Stop the program

EX NO: 4C TEMPLATE DESIGN IN C++

Aim:

To design a class template using C++ programming language.

Algorithm:
1. Start the program.
2. Create a class template. Template <class T >
3. Create a class with data member and functions.
4. Create object and call the template class by defining data types.

.
Object Oriented Programming Lab Manual CS6461

5. Print the RESULT.


6. Stop the program

EX.NO: 5A FILE HANDLING: SEQUENTIAL FILE ACCESS

Aim:

To write a C++ program for creating student data using sequential file access.

Algorithm:
1. Start the program
2. Define student class and create the function get and show.
3. Use ofstream and ifstream get and display the file information.
4. Invoke function using sequential file access.
5. Display the output
6. Stop the program

.
Object Oriented Programming Lab Manual CS6461

EX NO: 5 B FILE HANDLING: RANDOM FILE ACCESS

Aim:

To write a C++ program for creating student data using random file access.

Algorithm:

1. Start the program.


2. Define student class and create the function get and show.
3. Overload stream operation function for displaying the file information.
4. Invoke function using random file access.
5. Use stream operator function to read and the write the contents
6. Display the RESULT

.
Object Oriented Programming Lab Manual CS6461

7. Stop the program

EX NO: 6 A CLASS AND OBJECTS IN JAVA

Aim:
To write a java to implement class and object

Algorithm:
1. Start the program.
2. Write try, catch and throw blocks.
3. If an exception occurs in try block, then detect and throw an exception
4. Thrown exception caught by catch block and the exception is printed.
5. Print the RESULT.
6. Stop the program

.
Object Oriented Programming Lab Manual CS6461

EX NO: 6B STRINGS IN JAVA

Aim:

To write a java program to perform string operation

Algorithm:

1. Start the program.


2. Create a class to handle string functions
3. Declare a string and initialize it.
4. Perform the string operations on the string.
5. Display the output.
6. Stop the program

.
Object Oriented Programming Lab Manual CS6461

EX NO: 7 DESIGNING PACKAGES WITH JAVA

Aim:

T o create a package in java and import the user defined package in a current
application.

Algorithm:

1. Start the program.

2. Create the package as mypackage and define a class called balance which consist
of two data members account holder name and balance

.
Object Oriented Programming Lab Manual CS6461

3. Define member function show () to display balance of the account holder.

4. Import the package in new class called as test balance which consist of main function

5. Create object for balance and call the display function.

6. Display the RESULT.

7. Stop the program.

EX NO: 8 INTERFACES AND INHERITANCE IN JAVA

Aim:

T o write a java program to find area of circle and volume of a cylinder using interfaces
and inheritance in Java

Algorithm:

1. Start the program.


2. Create three classes Point, Circle and Cylinder where they inherit as per the
inheritance tree

.
Object Oriented Programming Lab Manual CS6461

3. Create the interface name as area and declare variables and methods in interface
4. Define class cylinder and the class circle which implements the interface area,
volume and define member function compute () for each class to compute area
of circle and volume of the cylinder.
5. Create a class called interfacetest define main function and Create object for
cylinder and circle
6. Create object for interface
7. Assign circle object to interface object and call compute function of circle to find area
of circle.
8. Display the RESULT.
9. Stop the program.

EX.NO: 9A THREADS IN JAVA

Aim:

To write a java program to implement threads

Algorithm:

1. Start the program


2. Create a class worker that implements the runnable interface
3. Define the run method
4. Create a new thread for the worker class
5. Execute the thread by calling the start method
6. Display the RESULT
.
Object Oriented Programming Lab Manual CS6461

7. Stop the program

EX. NO: 9B MULTITHREADING

Aim:

To write a java program to implement multithreading concept

Algorithm:

1. Start the program

2. Create a class ThreadDemo that extends the Thread class

3. Override the run method of the Thread class

4. Create a new thread by creating object for the ThreadDemo class

5. Execute the thread by calling the start method


.
Object Oriented Programming Lab Manual CS6461

6. Display the RESULT

7. Stop the program

EX NO: 10 A EXCEPTIONS HANDLING IN JAVA

Aim:

To write a java program to implement multithreading concept

Algorithm:

1. Start the program.


2. Write try, catch and throw blocks.
3. If an exception occurs in try block, then detect and throw an exception.
4. Thrown exception caught by catch block and the exception is printed.
5. Print the RESULT.
6. Stop the program.

.
Object Oriented Programming Lab Manual CS6461

EX NO: 10B USER DEFINED EXCEPTION

Aim:

To write a java program to handle user defined exceptions.

Algorithm:

1. Start the program


2. Create a class MyException that extends the class Exception
3. Initialize the base class constructor using super

.
Object Oriented Programming Lab Manual CS6461

4. Handle the exception by creating an object for the class MyException


5. Use throw keyword to throw the exception
6. Display the RESULT
7. Stop the program

CONTENTS BEYOND SYLLABI

EX NO: 1 CONSOLE INPUT AND OUTPUT

Aim:
To write a C++ program for getting the input using the function getline ( ) and display
the output using function write ( ).

Algorithm:

1. Start the program.


2. Declare the variables size, city, string1 and string2.
3. Get the city name using function getline ( ).
4. Display the output using function write ( ).

.
Object Oriented Programming Lab Manual CS6461

5. Stop the program.

EX NO: 2 FILE HANDLING USING C++

Aim:
To write a C++ program to read the content of a file.

Algorithm:
1. Start the program.
2. Declare the variables.
3. Get the file name to read.
4. Using ifstreamin (filename) check whether the file exist.
5. If the file exist then check for the end of file condition.
6. Read the contents of the file.

.
Object Oriented Programming Lab Manual CS6461

7. Print the contents of the file.


8. Stop the program.

EX NO: 3 SORTING OF STRING IN A FILE

Aim:

To write a java program to read and sort the contents of the file.

Algorithm:

1. Start the program.


2. Declare an array for storing the string elements and initialise the capacity of the array.
3. Create a file to read the n number of string using FileReader Class.
4. Create a file to write the sorted string using FileWriter Class.
5. Using readLine method read the string from a file “One.txt” and store the string in an
array dn[].

.
Object Oriented Programming Lab Manual CS6461

6. Perform sorting operation using compareTo method.


7. Invoke write method store the sorted string array dn[]into a file “Two.txt”
8. Stop the program.

You might also like