Sri Venkateswara College of Engineering Pennalur, Sriperumbudur
Sri Venkateswara College of Engineering Pennalur, Sriperumbudur
Prepared by Approved by
Signature
LAB MANUAL
SEMESTER : 3
LM-CS2209
LAB MANUAL
LM Rev. No:00
Branch: CS Semester: 3
CYCLE II
Aim:
To write a C++ program to calculate income tax using default
arguments.
Algorithm:
1. Start.
2. Create a class with two data members, name and salary.
3. Create two functions , one for calculating income tax using
default percentage and other for calculating income tax using tax
percentage read from the user.
4. First get the salary amount from the user.
5. Calculate income tax to be paid by both the methods.
6. Finally display the tax amount to be paid.
7. Stop.
MENU
---------
1. Default tax percentage calculation
2. Getting tax percentage from the user
3. Exit
NAME : Ramu
SALARY : Rs.15000
INCOME TAX : Rs. 7500
MENU
---------
1. Default tax percentage calculation
2. Getting tax percentage from the user
3. Exit
NAME : Samuel
SALARY : Rs.15000
INCOME TAX : Rs. 750
MENU
---------
1. Default tax percentage calculation
2. Getting tax percentage from the user
3. Exit
Result:
Thus a C++ program for calculating income tax using default
arguments has been executed successfully.
LM-CS2209
LAB MANUAL
LM Rev. No:00
Aim:
To write a C++ program to categorize employees based on
designation using static data members.
Algorithm:
1. Start
2. Create a class for employee with two count variables declaring as a
static member and employee id, name and designation as other data
members.
3. Get the employee id name and designation from the user.
4. If the designation is MANAGER increment first count by 1 and if it
is ENGINEER increment second count by 1.
5. Finally display the total number of managers, engineers and
employees.
6. Stop.
MENU
---------
1. Manager’s List
2. Engineer’s List
3. Total Employees
4. Exit
EMPLOYEE ID : 5001
NAME : Ramu
EMPLOYEE ID : 5003
NAME : Sankar
MENU
---------
1. Manager’s List
2. Engineer’s List
3. Total Employees
4. Exit
EMPLOYEE ID : 5002
NAME : Ramnaresh
MENU
---------
1. Manager’s List
2. Engineer’s List
3. Total Employees
4. Exit
Result:
Thus a C++ program to categorize employees based on
designation using static data members has been executed successfully.
LM-CS2209
LAB MANUAL
LM Rev. No:00
Aim:
To write a C++ program to add two private data members using
friend functions.
Algorithm:
1. Start.
2. Create two separate classes for reading two numbers.
3. Declare sum function as a friend function.
4. In sum function add the two numbers and print it.
5. Stop.
Result:
Thus a C++ program for adding two private data members using
friend functions has been executed successfully.
LM-CS2209
LAB MANUAL
LM Rev. No:00
Sub Code & Name : CS2209 OBJECT ORIENTED Date: 13-07-09
PROGRAMMING LAB
Page 14
Algorithm:
1. Start.
2. Create two classes one for reading the input matrices and other for
resultant matrix.
3. Declare calculate function as a friend function.
4. Create a menu for Row and Column matrix.
5. For the Row matrix call the corresponding calculate function and
find the resultant matrix and print it.
6. For the Column matrix call the corresponding calculate function and
find the resultant matrix and print it.
7. Stop.
MATRIX MULTIPLICATION
--------------------------------------
1. Row Matrix
2. Column Matrix
3. Exit
Enter A matrix
------------------
Enter the value of a[0][0] = 1
Enter the value of a[0][1] = 2
Enter B matrix
-----------------
Enter the value of b[0][0] = 3
Enter the value of b[0][1] = 4
Enter the value of b[1][0] = 5
Enter the value of b[1][1] = 6
Resultant Matrix
--------------------
13 16
MATRIX MULTIPLICATION
--------------------------------------
1. Row Matrix
2. Column Matrix
3. Exit
Enter A matrix
------------------
Enter the value of a[0][0] = 1
Enter the value of a[0][1] = 2
Enter B matrix
-----------------
Enter the value of b[0][0] = 3
Enter the value of b[0][1] = 4
Enter the value of b[1][0] = 5
Enter the value of b[1][1] = 6
Resultant Matrix
--------------------
3 4
6 8
MATRIX MULTIPLICATION
--------------------------------------
1. Row Matrix
2. Column Matrix
3. Exit
Result:
Thus a C++ program to implement matrix vector multiplication
using friend functions has been executed successfully.
C/MN/01/28.02.02
LM-CS2209
LAB MANUAL
LM Rev. No:00
Sub Code & Name : CS2209 OBJECT ORIENTED Date: 13-07-09
PROGRAMMING LAB
Page 18
Algorithm:
1. Start.
2. Create a menu for addition and subtraction of complex numbers and
type conversion of integer to complex, double to complex and vice
versa.
3. By overloading operators + and – add and subtract the two complex
numbers.
4. For integer to complex, get the integer from the user and represent
it in complex form by making the imaginary part zero.
5. For complex to integer, get the complex number from the user and
just print the real part.
6. For double to complex and complex to double follow the same
procedure but represent the numbers in decimal form.
7. Stop.
MENU
--------
1. Addition
2. Subtraction
3. Integer to Complex
4. Complex to Integer
5. Double to Complex
6. Complex to double
7. Exit
MENU
--------
1. Addition
2. Subtraction
3. Integer to Complex
4. Complex to Integer
5. Double to Complex
6. Complex to double
7. Exit
MENU
--------
1. Addition
2. Subtraction
3. Integer to Complex
4. Complex to Integer
5. Double to Complex
6. Complex to double
7. Exit
Result:
Thus a C++ program to manipulate complex numbers using operator
overloading and type conversions has been executed successfully.
LM-CS2209
LAB MANUAL
LM Rev. No:00
Sub Code & Name : CS2209 OBJECT ORIENTED Date: 13-07-09
PROGRAMMING LAB
Page 23
Algorithm:
1. Start
2. Create a class matrix.
3. Allocate the memory dynamically for the two dimensional array.
4. Number of rows and columns are to be initialized to zero using
default constructors.
5. Get the rows and the columns from the user and it must be the same
for both the matrices.
6. Depending upon the menu add or subtract the two matrices.
7. Print the resultant matrix.
8. Stop.
MATRIX MANIPULATION
-----------------------------------
Enter the number of rows and columns = 2 2
Enter A matrix
------------------
Enter the value of a[0][0] = 5
Enter the value of a[0][1] = 6
Enter the value of a[1][0] = 8
Enter the value of a[1][1] = 10
Enter B matrix
------------------
Enter the value of b[0][0] = 2
Enter the value of b[0][1] = 7
Enter the value of b[1][0] = 12
Enter the value of b[1][1] = 15
MENU
--------
1. Addition
2. Subtraction
3. Exit
RESULTANT MATRIX
-----------------------------
7 13
20 25
MENU
--------
1. Addition
2. Subtraction
3. Exit
RESULTANT MATRIX
-----------------------------
3 -1
-4 -5
MENU
--------
1. Addition
2. Subtraction
3. Exit
Result:
Thus a program for matrix manipulation using dynamic memory
allocation has been executed successfully.
LM-CS2209
LAB MANUAL
LM Rev. No:00
Sub Code & Name : CS2209 OBJECT ORIENTED Date: 13-07-09
PROGRAMMING LAB
Page 27
Exercise: 5 Branch: CS Semester: 3
Aim:
To write a program to perform calculate student marks by
overloading new and delete operators.
Algorithm:
1. Start
2. Get the rollno, name and the marks in each subject from the user.
3. Overload new operator to allocate space for name and marks.
4. In the sum function calculate the marks.
5. Display the student details finally.
6. Finally delete the space allocated for name and marks by
overloading delete operator.
7. Stop.
Result:
Thus a program to calculate student marks by overloading new
LM-CS2209
LAB MANUAL
LM Rev. No:00
Sub Code & Name : CS2209 OBJECT ORIENTED Date: 13-07-09
PROGRAMMING LAB
Page 29
Exercise: 6 Branch: CS Semester: 3
Aim:
To write a program to develop a template for linked list class
and its methods.
Algorithm:
1. Start.
2. Declare a class for data and pointer to next node.
3. Develop a template for the class so that it can hold different
datatypes.
4. Create a header node using new function and create other nodes in
the same manner.
5. Create a menu for insertion, deletion and display functions.
6. For inserting a node get the position and the number to be
inserted from the user.
7. Now insert the node at the correct position.
8. For deleting a node get the number to be deleted from the user.
9. After performing each and every operation display the list to view
the change.
10. Stop.
LINKED LIST
----------------
Datatypes
------------
1. Integer
2. Floating Point
3. Exit
CREATION
Enter the number (Press 999 for the end) = 10
Enter the number (Press 999 for the end) = 20
Enter the number (Press 999 for the end) = 30
Enter the number (Press 999 for the end) = 40
Enter the number (Press 999 for the end) = 50
Enter the number (Press 999 for the end) = 60
Enter the number (Press 999 for the end) = 999
Datatypes
------------
1. Integer
2. Floating Point
3. Exit
CREATION
Enter the number (Press 999 for the end) = 10.56
Enter the number (Press 999 for the end) = 20.23
Enter the number (Press 999 for the end) = 30.14
Enter the number (Press 999 for the end) = 40.18
Enter the number (Press 999 for the end) = 50.89
Enter the number (Press 999 for the end) = 60.54
Enter the number (Press 999 for the end) = 999
Datatypes
------------
1. Integer
2. Floating Point
3. Exit
Result:
Thus a template to implement linked list class and its method
has been executed successfully.
LM-CS2209
LAB MANUAL
LM Rev. No:00
Sub Code & Name : CS2209 OBJECT ORIENTED Date: 13-07-09
PROGRAMMING LAB
Page 39
Exercise: 7a Branch: CS Semester: 3
Aim:
To write a program to implement bubble sort and insertion sort
using templates.
Algorithm:
1. Start
2. Create a menu or integer and float data types.
3. Create a menu for bubble sort and insertion sort.
4. Create a class with count and array as data members and member
functions for both insertion and bubble sort.
5. For bubble sort compare each number with others and do the sorting
operation.
6. Similar procedure is followed for insertion sort but the previous
list of numbers was checked after each sort.
7. Finally display the list of numbers.
8. Stop
DATATYPES
-----------------
1. Integer
2. Floating point
3. Exit
Enter the option = 1
SORTING OPTIONS
--------------------------
1. Bubble Sort
2. Insertion Sort
3. Exit
Enter the option = 1
Enter no of terms = 5
Enter the numbers
5 8 2 4 1
The sorted array is
1 2 4 5 8
SORTING OPTIONS
--------------------------
1. Bubble Sort
2. Insertion Sort
3. Exit
Enter the option = 3
DATATYPES
-----------------
1. Integer
2. Floating point
3. Exit
Enter the option = 2
SORTING OPTIONS
--------------------------
1. Bubble Sort
2. Insertion Sort
3. Exit
Enter the option = 2
Enter no of terms = 6
Enter the numbers
5.62 6.14 5.54 2.17 3.55 4.89
Result:
Thus the program to implement bubble sort and insertion sort
using templates has been executed successfully.
LM-CS2209
LAB MANUAL
LM Rev. No:00
Sub Code & Name : CS2209 OBJECT ORIENTED Date: 13-07-09
PROGRAMMING LAB
Page 45
Exercise: 7b Branch: CS Semester: 3
Algorithm:
1. Start
2. Get the elements to be sorted form the user.
3. From the given set of elements, a pivot element is selected and
based on pivot element two arrays are created, one for elements
lesser than pivot and other for elements greater than pivot.
4. These two arrays are sorted and this process of sorting is know as
quick sort.
5. The fundamental operation of merge sort is merging two sorted
lists.
6. Each element in the first list is compared with first element in
the second list followed by next and it continues.
7. The process of sorting the elements in this manner is called merge
sort.
8. Stop
DATATYPES
-----------------
1. Integer
2. Floating point
3. Exit
Enter the option = 1
SORTING OPTIONS
--------------------------
1. Quick Sort
2. Merge Sort
3. Exit
Enter the option = 1
Enter no of terms = 5
Enter the numbers
5 8 2 4 1
SORTING OPTIONS
--------------------------
1. Quick Sort
2. Merge Sort
3. Exit
Enter the option = 3
DATATYPES
-----------------
1. Integer
2. Floating point
3. Exit
Enter the option = 2
SORTING OPTIONS
--------------------------
1. Quick Sort
2. Merge Sort
3. Exit
Enter the option = 2
Enter no of terms = 6
Enter the numbers
5.62 6.14 5.54 2.17 3.55 4.89
Result:
Thus the program to implement quick sort and merge sort using
templates has been executed successfully.
LM-CS2209
LAB MANUAL
LM Rev. No:00
Sub Code & Name : CS2209 OBJECT ORIENTED Date: 13-07-09
PROGRAMMING LAB
Page 49
Exercise: 8 Branch: CS Semester: 3
Algorithm:
1. Start
2. Create a class for stack and queue.
3. For stack include push, pop and display operations.
4. For queue include enqueue, dequeue and display opeartions.
5. Write exception for overflow and underflow of stack and queue
using try block, throw statement and catch block.
6. Perform each and every operation and check for exceptions.
7. Stop
EXCEPTION HANDLING
--------------------------------
1. Stack
2. Queue
3. Exit
Enter the option = 1
STACK
----------
Enter the number of elements = 3
MENU
---------
1. Push
2. Pop
3. Top
4. Display
5. Exit
Enter the option = 1
Enter the element = 10
MENU
---------
1. Push
2. Pop
3. Top
4. Display
5. Exit
Enter the option = 1
Enter the element = 20
MENU
---------
1. Push
2. Pop
3. Top
4. Display
5. Exit
Enter the option = 1
Enter the element = 30
MENU
---------
1. Push
2. Pop
3. Top
4. Display
5. Exit
Enter the option = 1
Stack is Full!!!
MENU
---------
1. Push
2. Pop
3. Top
4. Display
5. Exit
Enter the option = 4
30 20 10
MENU
---------
1. Push
2. Pop
3. Top
4. Display
5. Exit
Enter the option = 2
The popped element is 30
MENU
---------
1. Push
2. Pop
3. Top
4. Display
5. Exit
Enter the option = 5
EXCEPTION HANDLING
--------------------------------
1. Stack
2. Queue
3. Exit
Enter the option = 2
QUEUE
----------
Enter the number of elements = 3
MENU
---------
1. Enqueue
2. Dequeue
3. Exit
Enter the option = 2
Queue is empty
MENU
---------
1. Enqueue
2. Dequeue
3. Exit
Enter the option = 1
Enter the element = 5
MENU
---------
1. Enqueue
2. Dequeue
3. Exit
Enter the option = 1
Enter the element = 10
MENU
---------
1. Enqueue
2. Dequeue
3. Exit
Enter the option = 1
Enter the element = 15
MENU
---------
1. Enqueue
2. Dequeue
3. Exit
Enter the option = 1
Queue is Full!!
MENU
---------
1. Enqueue
2. Dequeue
3. Exit
Enter the option = 3
Result:
Thus the program to implement stack and queue using exception
handling has been executed successfully.