Professional Documents
Culture Documents
Sri Venkateswara College of Engineering Pennalur, Sriperumbudur
Sri Venkateswara College of Engineering Pennalur, Sriperumbudur
LAB MAN AL CS!!"# $B%EC& $'(EN&E) P'$*'AMM(N* LAB +EA' , (( +r B.E CSE SEMES&E' , Prepared by Signature Approved by
Name
Date
13-07- 00!
LAB MAN AL
Sub Code & Name: CS!!"# $B%EC& $'(EN&E) P'$*'AMM(N* LAB Bran23, CS Semester, -
L(S& $4 E5PE'(MEN&S ,.
C+CLE (
(MPLEMEN&A&($N (N C66
EX NO : 1
A) Income Tax Calculation Using Default Arguments B) Categorizing Em lo!ees Base" On Designation Using #tatic $em%ers C) A""ition Of T&o 'ri(ate Data $em%ers Using )rien" )unctions $atrix +ector $ulti lication $ani ulation Of Com lex Num%ers Using O erator O(erloa"ing An" T! e Con(ersions $atrix $ani ulation Using D!namic $emor! Allocation O(erloa"ing Ne& An" Delete O erators Im lementation Of 0in1e" 0ist Using Tem lates C+CLE ((
EX NO : * EX NO : , EX NO : EX NO : . EX NO : /
EX NO : 2
A) Im lementation Of Bu%%le #ort An" Insertion #ort Using Tem lates B) Im lementation Of 3ui1 #ort An" $erge #ort Using Tem lates Im lementation Of #tac1 An" 3ueue Using Exce tion 5an"ling
EX NO : 4
EX NO : 6 Im lementation Of $inimum # anning Tree Using In7eritance EX NO : 18 D!namic 'ol!mor 7ism An" 9TTI EX NO : 11 $ani ulation Of Com lex Num%ers Using )ile )unctions
LAB MANUAL
Sub Code & Name : CS!!"# $B%EC& $'(EN&E) P'$*'AMM(N* LAB $%er&i'e: (a Bran&): CS Seme'ter: #
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. . !irst get the salary amount from the user. ". Calculate income tax to be paid by both the methods. #. !inally display the tax amount to be paid. $. Stop. Sample input and output: %&'( ))))))))) 1. *efault tax percentage calculation 2. +etting tax percentage from the user 3. &xit &nter the option , 1 &nter the name &nter the salary amount - .amu - .s. 1"///
'0%& - .amu S010.2 - .s.1"/// 3'C4%& T05 - .s. $"// %&'( ))))))))) 1. *efault tax percentage calculation 2. +etting tax percentage from the user 3. &xit &nter the option , 2 &nter the name &nter the salary amount - Samuel - .s. 1"///
&nter the tax percent '0%& - Samuel S010.2 - .s.1"/// 3'C4%& T05 - .s. $"/
- /./"
%&'( ))))))))) 1. *efault tax percentage calculation 2. +etting tax percentage from the user 3. &xit &nter the option , 6ress any 7ey to continue888
Result: Thus a C++ program for calculating income tax using default arguments has been executed successfully.
LAB MANUAL
Sub Code & Name : CS!!"# $B%EC& $'(EN&E) P'$*'AMM(N* LAB
$%er&i'e : (b
Bran&):
CS
3. Total &mployees . &xit &nter the option , 1 &%6142&& 3* - "//1 '0%& &%6142&& 3* - "//3 '0%& - .amu
- San7ar , 2
The total number of managers %&'( ))))))))) 1. %anager;s 1ist 2. &ngineer;s 1ist 3. Total &mployees . &xit &nter the option , 2 &%6142&& 3* - "//2 '0%&
- .amnaresh
The total number of engineers , 1 %&'( ))))))))) 1. %anager;s 1ist 2. &ngineer;s 1ist 3. Total &mployees . &xit &nter the option , 3 The total number of employees , 3
Result: Thus
C++
program
to
categori9e
employees
based
on
LAB MANUAL
Sub Code & Name : CS!!"# $B%EC& $'(EN&E) P'$*'AMM(N* LAB $%er&i'e: (& Bran&): CS Seme'ter: #
To write a C++ program to add two pri:ate data members using friend functions. Algorithm: 1. Start. 2. Create two separate classes for reading two numbers. 3. *eclare sum function as a friend function. . 3n sum function add the two numbers and print it. ". Stop. Sample input and output: 0**3T34' 4! T<4 '(%=&.S )))))))))))))))))))))))))))))))))))))))))) &nter the first number , 12 &nter the second number , 2" The sum of 12 and 2" is 3$
Result: Thus a C++ program for adding two pri:ate data members using friend functions has been executed successfully.
LAB MANUAL
Sub Code & Name : CS!!"# $B%EC& $'(EN&E) P'$*'AMM(N* LAB $%er&i'e: 2 Bran&): CS Seme'ter: #
, ,
1 2
, 3 , , " , #
.esultant %atrix )))))))))))))))))))) 13 1# %0T.35 %(1T3613C0T34' )))))))))))))))))))))))))))))))))))))) 1. .ow %atrix 2. Column %atrix 3. &xit &nter the option , 2 &nter the rows and columns for the 1st matrix , 2 &nter the rows and columns for the 2nd matrix , 2 &nter 0 matrix )))))))))))))))))) &nter the :alue of a>/?>/? &nter the :alue of a>/?>1? &nter = matrix ))))))))))))))))) &nter the :alue of &nter the :alue of &nter the :alue of &nter the :alue of
, ,
1 2
, 3 , , " , #
.esultant %atrix )))))))))))))))))))) 3 # @ %0T.35 %(1T3613C0T34' )))))))))))))))))))))))))))))))))))))) 1. .ow %atrix 2. Column %atrix 3. &xit &nter the option , 3 6ress any 7ey to continue888
Result: Thus a C++ program to implement matrix :ector multiplication using friend functions has been executed successfully.
C/M"/01/ #.0 .0
LAB MANUAL
Sub Code & Name : CS!!"# $B%EC& $'(EN&E) P'$*'AMM(N* LAB $%er&i'e : # Bran&): CS Seme'ter : #
%&'( )))))))) 1. 0ddition 2. Subtraction 3. 3nteger to Complex . Complex to 3nteger ". *ouble to Complex #. Complex to double $. &xit &nter the option , &nter the real and &nter the real and *ifference , )@ + 2 imaginary part imaginary part i2 $ + i12 1" + i1/
%&'( )))))))) 1. 0ddition 2. Subtraction 3. 3nteger to Complex . Complex to 3nteger ". *ouble to Complex #. Complex to double $. &xit &nter the option , 3 &nter the number to be con:erted , 1/ The number in complex form is , 1/ + i/ %&'( )))))))) 1. 0ddition 2. Subtraction 3. 3nteger to Complex . Complex to 3nteger ". *ouble to Complex #. Complex to double $. &xit &nter the option , &nter the real and imaginary part , 3/ The number in integer form is , 3/ 1"
Result: Thus a C++ program to manipulate complex numbers using operator o:erloading and type con:ersions has been executed successfully.
LAB MANUAL
Sub Code & Name : CS!!"# $B%EC& $'(EN&E) P'$*'AMM(N* LAB $%er&i'e: + Bran&): CS Seme'ter: #
, , , ,
" # @ 1/
, , , ,
2 $ 12 1"
3. &xit &nter the option , 1 .&S(1T0'T %0T.35 ))))))))))))))))))))))))))))) $ 13 2/ 2" %&'( )))))))) 1. 0ddition 2. Subtraction 3. &xit &nter the option , 2 .&S(1T0'T %0T.35 ))))))))))))))))))))))))))))) 3 )1 ) )" %&'( )))))))) 1. 0ddition 2. Subtraction 3. &xit &nter the option , 3 6ress any 7ey to continue888
LAB MANUAL
Sub Code & Name : CS!!"# $B%EC& $'(EN&E) P'$*'AMM(N* LAB $%er&i'e: Bran&): CS Seme'ter: #
o:erloading new and delete operators. Algorithm: 1. Start 2. +et the rollno, name and the mar7s in each subBect from the user. 3. 4:erload new operator to allocate space for name and mar7s. . 3n the sum function calculate the mar7s. ". *isplay the student details finally. #. !inally delete the space allocated for name and mar7s by o:erloading delete operator. $. Stop. Sample input and output: 4C&.140*3'+ '&< 0'* *&1&T& 46&.0T4.S ))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) &nter the .oll no , 3# &nter the 'ame , +uruprasad &nter the mar7s one by one D@ D# D" DD D3 ST(*&'T %0.E 13ST )))))))))))))))))))))))))))))) .411 '4 3# '0%& +uruprasad T4T01 @1
Result: Thus a program to calculate student mar7s by o:erloading new and delete operators has been executed successfully.
LAB MANUAL
Sub Code & Name : CS!!"# $B%EC& $'(EN&E) P'$*'AMM(N* LAB $%er&i'e: . Bran&): CS Seme'ter: #
S(N* &EMPLA&ES
To write a program to de:elop a template for lin7ed list class and its methods. Algorithm: 1. Start. 2. *eclare a class for data and pointer to next node. 3. *e:elop a template for the class so that it can hold different datatypes. . Create a header node using new function and create other nodes in the same manner. ". Create a menu for insertion, deletion and display functions. #. !or inserting a node get the position and the number to be inserted from the user. $. 'ow insert the node at the correct position. @. !or deleting a node get the number to be deleted from the user. D. 0fter performing each and e:ery operation display the list to :iew the change. 1/. Stop. Sample input and output: 13'E&* 13ST )))))))))))))))) *atatypes )))))))))))) 1. 3nteger 2. !loating 6oint 3. &xit &nter the option , 1 C.&0T34' &nter the &nter the &nter the &nter the &nter the number number number number number F6ress F6ress F6ress F6ress F6ress DDD DDD DDD DDD DDD for for for for for the the the the the endG endG endG endG endG , , , , , 1/ 2/ 3/ / "/
&nter the number F6ress DDD for the endG , #/ &nter the number F6ress DDD for the endG , DDD 13'E&* 13ST %&'( )))))))))))))))))))))))))) 1. 3'S&.T34' 2. *&1&T34' 3. *3S6102 . &53T &nter the option , 1 &nter the position in which the number is to be inserted , 3 &nter the number to be inserted , 2" 13'E&* 13ST %&'( )))))))))))))))))))))))))) 1. 3'S&.T34' 2. *&1&T34' 3. *3S6102 . &53T &nter the option , 3 1/2/2"3/ /"/#/&'* 13'E&* 13ST %&'( )))))))))))))))))))))))))) 1. 3'S&.T34' 2. *&1&T34' 3. *3S6102 . &53T &nter the option , 2 &nter the position of the node to be deleted , $ 13'E&* 13ST %&'( )))))))))))))))))))))))))) 1. 3'S&.T34' 2. *&1&T34' 3. *3S6102 . &53T &nter the option , 3 1/2/2"3/ /"/&'* 13'E&* 13ST %&'( )))))))))))))))))))))))))) 1. 3'S&.T34' 2. *&1&T34' 3. *3S6102 . &53T &nter the option , *atatypes )))))))))))) 1. 3nteger 2. !loating 6oint 3. &xit &nter the option , 2
C.&0T34' &nter the &nter the &nter the &nter the &nter the &nter the &nter the
, , , , , , ,
13'E&* 13ST %&'( )))))))))))))))))))))))))) 1. 3'S&.T34' 2. *&1&T34' 3. *3S6102 . &53T &nter the option , 1 &nter the position in which the number is to be inserted , 3 &nter the number to be inserted , 2".2# 13'E&* 13ST %&'( )))))))))))))))))))))))))) 1. 3'S&.T34' 2. *&1&T34' 3. *3S6102 . &53T &nter the option , 3 1/."#2/.232".2#3/.1 /.1@"/.@D#/." &'* 13'E&* 13ST %&'( )))))))))))))))))))))))))) 1. 3'S&.T34' 2. *&1&T34' 3. *3S6102 . &53T &nter the option , 2 &nter the position of the node to be deleted , $ 13'E&* 13ST %&'( )))))))))))))))))))))))))) 1. 3'S&.T34' 2. *&1&T34' 3. *3S6102 . &53T &nter the option , 3 1/."#2/.232".2#3/.1 /.1@"/.@D&'* 13'E&* 13ST %&'( )))))))))))))))))))))))))) 1. 3'S&.T34' 2. *&1&T34' 3. *3S6102 . &53T &nter the option , *atatypes
)))))))))))) 1. 3nteger 2. !loating 6oint 3. &xit &nter the option ,3 6ress any 7ey to continue88888888
Result: Thus a template to implement lin7ed list class and its method has been executed successfully.
LAB MANUAL
Sub Code & Name : CS!!"# $B%EC& $'(EN&E) P'$*'AMM(N* LAB $%er&i'e: *a Bran&): CS Seme'ter: #
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. . Create a class with count and array as data members and member functions for both insertion and bubble sort. ". !or bubble sort compare each number with others and do the sorting operation. #. Similar procedure is followed for insertion sort but the pre:ious list of numbers was chec7ed after each sort. $. !inally display the list of numbers. @. Stop Sample input and output: *0T0T26&S ))))))))))))))))) 1. 3nteger 2. !loating point 3. &xit &nter the option , 1 S4.T3'+ 46T34'S )))))))))))))))))))))))))) 1. =ubble Sort 2. 3nsertion Sort 3. &xit &nter the option , 1 &nter no of terms , " &nter the numbers " @ 2
S4.T3'+ 46T34'S )))))))))))))))))))))))))) 1. =ubble Sort 2. 3nsertion Sort 3. &xit &nter the option , 3 *0T0T26&S ))))))))))))))))) 1. 3nteger 2. !loating point 3. &xit &nter the option , 2 S4.T3'+ 46T34'S )))))))))))))))))))))))))) 1. =ubble Sort 2. 3nsertion Sort 3. &xit &nter the option , 2 &nter no of terms , # &nter the numbers ".#2 #.1 "." 2.1$ The sorted array is 2.1$ 3."" .@D "."
3."" ".#2
.@D #.1
Result: Thus the program to implement bubble sort and insertion sort using templates has been executed successfully.
LAB MANUAL
Sub Code & Name : CS!!"# $B%EC& $'(EN&E) P'$*'AMM(N* LAB $%er&i'e: *b Bran&): CS Seme'ter: #
To write a program to implement Huic7 sort and merge sort using templates. Algorithm: 1. Start 2. +et the elements to be sorted form the user. 3. !rom the gi:en set of elements, a pi:ot element is selected and based on pi:ot element two arrays are created, one for elements lesser than pi:ot and other for elements greater than pi:ot. . These two arrays are sorted and this process of sorting is 7now as Huic7 sort. ". The fundamental operation of merge sort is merging two sorted lists. #. &ach element in the first list is compared with first element in the second list followed by next and it continues. $. The process of sorting the elements in this manner is called merge sort. @. Stop Sample input and output: *0T0T26&S ))))))))))))))))) 1. 3nteger 2. !loating point 3. &xit &nter the option , 1 S4.T3'+ 46T34'S )))))))))))))))))))))))))) 1. Iuic7 Sort 2. %erge Sort 3. &xit &nter the option , 1
&nter no of terms , " &nter the numbers " @ 2 The sorted array is 1 2 "
S4.T3'+ 46T34'S )))))))))))))))))))))))))) 1. Iuic7 Sort 2. %erge Sort 3. &xit &nter the option , 3 *0T0T26&S ))))))))))))))))) 1. 3nteger 2. !loating point 3. &xit &nter the option , 2 S4.T3'+ 46T34'S )))))))))))))))))))))))))) 1. Iuic7 Sort 2. %erge Sort 3. &xit &nter the option , 2 &nter no of terms , # &nter the numbers ".#2 #.1 "." 2.1$ The sorted array is 2.1$ 3."" .@D "."
3."" ".#2
.@D #.1
Result: Thus the program to implement Huic7 sort and merge sort using templates has been executed successfully.
LAB MANUAL
Sub Code & Name : CS!!"# $B%EC& $'(EN&E) P'$*'AMM(N* LAB $%er&i'e: , Bran&): CS Seme'ter: #
))))))))) 1. 6ush 2. 6op 3. Top . *isplay ". &xit &nter the option , 1 &nter the element , 2/ %&'( ))))))))) 1. 6ush 2. 6op 3. Top . *isplay ". &xit &nter the option , 1 &nter the element , 3/ %&'( ))))))))) 1. 6ush 2. 6op 3. Top . *isplay ". &xit &nter the option , 1 Stac7 is !ull888 %&'( ))))))))) 1. 6ush 2. 6op 3. Top . *isplay ". &xit &nter the option , 3/ 2/ 1/ %&'( ))))))))) 1. 6ush 2. 6op 3. Top . *isplay ". &xit &nter the option , 2 The popped element is 3/ %&'( ))))))))) 1. 6ush 2. 6op 3. Top . *isplay ". &xit &nter the option , " &5C&6T34' J0'*13'+ ))))))))))))))))))))))))))))))))
1. Stac7 2. Iueue 3. &xit &nter the option , 2 I(&(& )))))))))) &nter the number of elements , 3 %&'( ))))))))) 1. &nHueue 2. *eHueue 3. &xit &nter the option , 2 Iueue is empty %&'( ))))))))) 1. &nHueue 2. *eHueue 3. &xit &nter the option , 1 &nter the element , " %&'( ))))))))) 1. &nHueue 2. *eHueue 3. &xit &nter the option , 1 &nter the element , 1/ %&'( ))))))))) 1. &nHueue 2. *eHueue 3. &xit &nter the option , 1 &nter the element , 1" %&'( ))))))))) 1. &nHueue 2. *eHueue 3. &xit &nter the option , 1 Iueue is !ull88 %&'( ))))))))) 1. &nHueue 2. *eHueue 3. &xit &nter the option , 3 Result: Thus the program to implement stac7 and Hueue using exception handling has been executed successfully.