You are on page 1of 11

dr;LIST OF PRACTICALS

CLASS XII
COMPUTER SCIENCE 2014-15
1) WAP using overloaded function to compute the area of rectangle and area of triangle using heros formula.

2) Define a class TRAVEL with the following descriptions :
Private members are :
Tcode no!of!pass no!of!"uses integer #ranging from $ to %%$$$)
Place string
Public members are:
A constructor to assign initial values of Tcode as 1$1 Place as &'aranasi( no!of!pass as %
no!of!"uses as 1.
A function )*D+TA),-# ) to input all information e.cept no!of!"uses according to the following rules
:
Number of !""e#$er" Number of bu"e"
,ess than /$ 1
+0ual to or more than /$ 1 less than 2$ 2
+0ual to or more than 2$ 3
A function 45TD+TA),-# ) to displa6 all the information

WAP to implement that reads the *o of Passengers 1 depending upon displa6s all the details including no of "uses
re0uired.
3) Define ac class 7esort in 8 99 with the following description :
Private mem"ers :
7no :: Data mem"er to store room no
*ame :: Data mem"er to store customer name
8harges :: Data mem"er to store per da6 charges
Da6s :: Data mem"er to store num"er of da6s of sta6
8ompute# ) :: A function to calculate and return amount as da6s;charges and
if the value of da6s;charges is more than 11$$$ then as
1.$2 ;da6s;charges.
Pu"lic <em"ers :
=etinfo# ) :: A function to enter the content 7no *ame charges and da6s.
Dispinfo# ) :: A function to displa6 7no*ame8harges Da6s and Amount
#Amount to "e displa6ed "6 calling function 8ompute# ))
WAP that implements the a"ove class.
/) Write a program to add two instances of d%"&!#'e class #having data mem"ers feet and inches). <a>e suita"le assumptions.
%) Write a 899 program using classes and o"?ects to simulate result preparation s6stem for 1$ students. The data
availa"le for each student includes rollno name marlsin 3 su"?ects. The percentage mar>s and grade are to "e
calculated from the given information. The percentage mar>s are the average mar>s and the grade ias calculated as
follows:
Per'e#&!$e M!r(" )r!de
@%$ A
BC%$ 1 @D$ D
BCD$ 1 @E% 8
BCE% 1 @F$ G
BCF$ 1 @C1$$ A
D) Write a program using functions in 899 to read the content from a te.t file -T47H.TIT count and displa6 the num"er of
alpha"ets present in it.
E) Write a function in 899 to read the content from a te.t file *4T+-. TIT count and displa6 the num"er of "lan> spaces
present in it.
2) Assuming the class +<P,4H++ given "elow write a program using functions in 899 to perform the following:J
#i) Write the o"?ects of +<P,4H++ to "inar6 file.
#ii) 7eads the o"?ects of +<P,4H++ from "inar6 file and displa6 them on screen.
8lass +<P,4H++
K
int +*8L
char +*A<+M$NL
P5G,)8:
'oid =+T)T#)K cinBB +*4Lgets#+*A<+)LO
'oid -P4W)T#) K coutBB +*4@@+*A<+L@@endlL O
OL
F) Assuming the class -T48Q write functions in 899 to perform following:
#i) Write the o"?ects of -T48Q to "inar6 file.
#ii) 7eads the o"?ects of -T48Q from "inar6 file and displa6 them on screen.
8lass -T48Q
K
int )T*4L
char )T+<M1$NL
P5G,)8:
'oid =+T)T#) K 8)*BB )T*4L gets#)T+<)LO
'oid -P4W)T#) K cout@@)T*4@@ & ( @@)T+<@@endl LO
OL
1$) Write a 899 program which reads one line at a time form the dis> file T+-T.TIT and displa6s it to a monitor. Hour
program has to read all the contents of the file. Assume the length of the line not to e.ceed 2$ characters. Hou have to include
all the header files if re0uired.
11) Aollowing is the structure of each record in a data file named &8olon6.dat(
struct 8olon6
K
char colon6!codeM1$NL
char colon6!nameM1$NL
int no!of!peopleL
OL
Wite a function to update the file with a new value of *o!of!people. The value of colon6!code and no!of!people are read
during the e.ecution of the program.
12) Asuming a "inar6 file A5*.DAT is containing o"?ects "elonging to a class ,A5=PT+7# as defined "elow). Write a
user defined function in 899 to add more o"?ects "elonging to class ,A5=PT+7 at the "ottom of it.
8lass ,A5=PT+7
K
int idnoL
char T6peM%NL
char DescM2%%NL
P5G,)8:
void *ewentr6#)K cinBB )dnoL gets#T6pe)L gets#Desc)LO
void -howonscreen#) K cout@@)dno@@( &@@T6pe@@endll@@Desc@@endlLO
OL
13. Assuming that a te.t file named T+IT1.T+IT alread6 contains some te.t written into it write a function named
vowelwords#) that reads the file T+IT1.T+IT and creates a new file named T+IT2.T+ITwhich shall contain onl6
those words from the file T+IT1.T+IT which does not start
with an uppercase vowel#i.e with RA+)45). A47 e.ample if the file T+IT1.TIT
contains.
C!rr* umbre++! !#d O,er'o!& -.e# %& R!%#"
then the file T+IT2.TIT shall contain
8!rr* -.e# %& R!%#"/
1/. Write a 899 program which initialiSes a string varia"le to the content. & Anil is a great teacher "ut unfortunatel6 it
>ills all its pupils. Parimohan( and output the srtring one character at a time to the dis> file 45T.TIT. Hou have to include all
the header files if re0uired.
1%. A te.t file named &report.t.t( e.ists on a dis>. Write a program to create its cop6 named &Ainerep.t.t(
which should "e in small letters "ut the first letter of the file and first alpha"etic character
following a full stop should "e in uppercase.
S0L
0/ 1r%&e S0L 0uer%e" &o 're!&e &.e &!b+e" 2 %#"er& &.e "e'%f%ed ro-" for &.e fo++o-%#$ 33
1
T!b+e 3 S'.oo+4u"
7tno Area!overed 8apacit6 *oofstudents Distance Transporter 8harges
1 'asant >un? 1$$ 12$ 1$ -hivamtravels 1$$$$$
2 PauS Qhas 2$ 2$ 1$ Anand travels 2%$$$
3 Pitampura D$ %% 3$ Anand travels D$$$$
/ 7ohini 1$$ F$ 3% Anand travels 1$$$$$
% Hamuna 'ihar %$ D$ 2$ Ghalla 8o. %%$$$
D Qrishna *agar E$ 2$ 3$ Hadav 8o. 2$$$$
E 'asundhara 1$$ 11$ 2$ Hadav 8o. 1$$$$$
2 Paschim 'ihar /$ /$ 2$ -peed travels %%$$$
F -a>et 12$ 12$ 1$ -peed travels 1$$$$$
1$ Tan> Puri 1$$ 1$$ 2$ Qisan Tours F%$$$
a)To show all information of students where capacit6 is more than the no of student in order of rtno.
#") To show area!covered for "uses covering more than 2$ >m. "ut charges less then 2$$$$.
#c) To show transporter wise total no. of students traveling.
#d) To show rtno area!covered and average cost per student for all routes where average cost per student is J
charges:noofstudents.
#e) Add a new record with following data:
#11 & <oti "agh(3%321$( >isan tours & 3%$$$)
2/
TA4LE 3 )RA5UATE
S/NO NAME STIPEN5 SU46ECT A7ERA)E 5I7/
1 QA7A* /$$ PPH-)8- D2 )
2 D)WAQA7 /%$ 84<P. -c. D2 )
3 D)'HA 3$$ 8P+<)-T7H D2 )
/ 7+QPA 3%$ PPH-)8- D3 )
% A7T5* %$$ <ATP- E$ )
D -AG)*A /$$ 8+P<)-T7H %% ))
E T4P* 2%$ PPH-)8- D/ )
2 74G+7T /%$ <ATP- D2 )
F 75G)*A %$$ 84<P. -c. D2 )
1$ ')QA- /$$ <ATP- %E ))
8!9 ,ist the names of those students who have o"tained D)' 1 sorted "6 *A<+.
8b9 Displa6 a report listing *A<+ -T)P+*D -5GT+8T and amount of stipend received in a 6ear assuming that the
-T)P+*D is paid ever6 month.
8'9 To count the num"er of students who are either PPH-)8- or 84<P5T+7 -8 graduates.
8d9 To insert a new row in the =7AD5AT+ ta"le:
11(QAT4,( 3$$ &computer sc( E% 1
#e) Assume that there is one more ta"le =5)D+ in the data"ase as shown "elow:
Ta"le: =5)D+
f) What will "e the output of the following 0uer6:
-+,+8T *A<+ AD')-47 A74< =7AD5AT+=5)D+ WP+7+ -5GT+8TC <A)*A7+AL
<A)*A7+A AD')-47
PPH-)8- ')*4D
84<P5T+7 -8 A,4Q
8P+<)-T7H 7ATA*
<ATP+<AT)8- <AP+-P
U3. Write -U, command for #i) to #vii) on the "asis of the ta"le -P47T-
Ta"le: -P47T-
#a) Displa6 the names of the students who have grade R8 in either =ame1 or =ame2 or "oth.
#") Displa6 the num"er of students getting grade RA in 8ric>et.
#c) Displa6 the names of the students who have same game for "oth =ame1 and =ame2.
#d) Displa6 the games ta>en up "6 the students whose name starts with RA.
#e) Assign a value 2$$ for <ar>s for all those who are getting grade RG or grade RA in "oth
=ame1 and =ame2.
#f) Arrange the whole ta"le in the alpha"etical order of *ame.
#g) Add a new column named R<ar>s.
/.
Em+o*ee"
+mpid Airstname ,astname Address 8it6
$1$ 7avi Qumar 7a? nagar =VG
1$% Parr6 Waltor =andhi nagar =VG
1%2 -am Tones 33 +lm -t. Paris
21% -arah Ac>erman //$ 5.-. 11$ 5pton
2// <anila -engupta 2/ Ariends street *ew Delhi
3$$ 7o"ert -amuel F Aifth 8ross Washington
33% 7itu Tondon -hastri *agar =VG
/$$ 7achel ,ee 121 Parrison -t. *ew Hor>
//1 Peter Thompson 11 7ed 7oad Paris
EmS!+!r*
+mpid -alar6 Genefits Designation
$1$ E%$$$ 1%$$$ <anager
1$% D%$$$ 1%$$$ <anager
1%2 2$$$$ 2%$$$ Director
21% E%$$$ 12%$$ <anager
2// %$$$$ 12$$$ 8ler>
3$$ /%$$$ 1$$$$ 8ler>
33% /$$$$ 1$$$$ 8ler>
/$$ 32$$$ E%$$ -alesman
//1 22$$$ E%$$ salesman
Write the -U, commands for the following :
#i) To show firstnamelastnameaddress and cit6 of all emplo6ees living in paris

#ii) To displa6 the content of +mplo6ees ta"le in descending order of Airstname.
#iii) To displa6 the firstnamelastname and total salar6 of all managers from the ta"les +mplo6ee and empsalar6 where total
salar6 is calculated as salar69"enefits.
iv) To displa6 the ma.imum salar6 among managers and cler>s from the ta"le +mpsalar6.
%) -tud6 the following ta"les -TAAA and -A,A7H and write -U, commands for the 0uestion #i) to #iv) and give output for -U,
0ueries #v) to #vi)
relation : -TAAA

)D *A<+ D4T D+PT -+I U5A,A
1$1 -iddharth 12:$1:$2 -ales < <GA
-tudent *4 8lass *ame =ame1 =rade =ame2 =rade2
1$ E -ammer 8ric>et G -wimming A
11 2 -u?it Tennis A ->ating 8
12 E Qamal -wimming G Aoot"all G
13 E 'enna Tennis 8 Tennis A
1/ F Archana Gas>et"all A 8ric>et A
1% 1$ Arpit 8ric>et A Atheletics 8
1$/ 7aghav 2:$%:22 Ainance < 8A
1$E *aman 1/:$%:22 7esearch < <T+8P
11/ *upur 1:$2:$3 -ales A <GA
1$F Tanvi 12:E:$/ Ainance A )8WA
1$% 7ama 1/:/:$E 7esearch < GT+8P
11E Tace 2E:D:2E -ales A <T+8P
111 Gino6 12:1:F$ Ainance < 8A
13$ -amuel E:3:FF -ales < <GA
12E 7agini 12:12:$2 7esearch A GT+8P
relation : -A,A7H
)D GA-)8 A,,4WA*8+ 84<<!P+78
1$1 1%2/$ %/$$ 3
1$/ 23$$$ 1/%2 /
1$E 1/2E$ 2/%1 3
11/ 21$$$ 3/%1 1/
1$F 2/%$$ 1/%2 1$
1$% 1E$$$ 12%$ 2
11E 12/%$ 1/$$ 3
111 13%/1 3D%2 F
13$ 2%$$$ /E2% 1%
12E 1/223 %2D2 2
i) Displa6 the name of all 8As who are wor>ing for more than % 6ears
ii) Displa6 the num"er of staff ?oined 6earJwise
iii) Pi>e the Allowance of all female staff wor>ing in finance sector and ?oined the compan6 "efore 2$$$
iv) Displa6 the average salar6 given to the emplo6ee in each department
v) -+,+8T D+PT 845*T#;)
A74< -TAAA
WP+7+ -+ICm
=745P GH D+PT
PA')*= 845*T#;) B2
vi) -+,+8T A'=#GA-)89 A,,4WA*8+) U5A,A
A74< -A,A7H -1 -TAAA -2
WP+7+ -1.)DC-2.)D
=745P#U5A,A)
vii) -+,+8T D)-T)*8T U5A,A A74< -TAAA
viii) -+,+8T *A<+ GA-)89A,,4WA*8+
A74< -TAAA - -A,A7H -A
WP+7+ -.)DC-A.)D A*D H+A7#D4T)@2$$2
D) 8onsider the ta"les ITEMS 1 COMPANY. Write -U, commands for the statements #i) to #iv) and
give the outputs for -U, 0ueries #v) 1 #vi) .

Table : ITEMS
I5 PNAME PRICE M5ATE 0T:
T$$1 -oap 12.$$ 11:$3:2$$E 2$$
T$$2 Paste 3F.%$ 23:12:2$$D %%
T$$3 Deodorant 12%.$$ 12:$D:2$$E /D
T$$/ Pair 4il 22.E% 2%:$F:2$$E 32%
T$$% 8old 8ream DD.$$ $F:1$:2$$E 1//
T$$D Tooth Grush 2%.$$ 1E:$2:2$$D /%%

Table : COMPANY
I5 COMP C%&*
T$$1 P,, <um"ai
T$$D 8olgate Delhi
T$$F P,, <um"ai
T$$E Paras Par6ana
T$$% Ponds *oida
T$$11 Wipro Ahmeda"ad
i) Displa6 the items detail produced "6 Wipro 1 Paras.
ii) To displa6 product name compan6 name 1 price for those items which )Ds are e0ual to the )Ds of compan6.
iii) To delete the items produced "efore 2$$E.
iv) To displa6 the total stoc> value of items.

Po%#&er"
U 1) Write a program using function su"str#) that will scan a string for the occurrence of a given string for the occurrence of a
given su"Jstring. The protot6pe of the function would "e:
char ; su"str#char ; string1 char ;string2)L
The function should return a pointer to the element in "&r%#$1 where "&r%#$2 "egins. )f "&r%#$2 doesnt occur in "&r%#$1 then
"ub"&r should return a *5,,.
2) WAP in 899 to find whether the string is a palindrome or not using pointer.
3) WAP to reverse a string using pointer.
/) WAP to input a string 1 find its length using pointer.
%) WAP using function replace having protot6pe
)nt replace#char ;s char c1 char c2)L
which replaces ever6 occurrence of c1 in the string s with c2 and returns the num"er of replacements it made.
D) WAP using functions to compress an6 given string such that the multiple "lan>s present in it are eliminated.The function
should return the compressed string.
E) WAP using fuction that ta>es two string arguments and returns the concatenated string.
Arrays
1r%&e !++ &.e ro$r!m" be+o- u"%#$ Fu#'&%o#"33
0 19 WAP using functions in 899 which accepts an integer arra6 and its siSe as parameters and rearranges the arra6 in
reverse.
E;!m+e:)f an arra6 of nine elements initiall6 contains the elements as / 2 % 1 D E 2 12 1$
Then the function should rearrange the arra6 as 1$12 2 E D 1 % 2 /
29 Write a function in 899 which accepts an integer arra6 and its siSe as arguments and swap the elements of ever6
even location with its following odd location.
E;!m+e : )f an arra6 of nine elements initiall6 contains the elements as 2/1D%EF231$
then the function should rearrange the arra6 as /2D1E%23F1$
3) Write a function in 899 to print the product of each row of a two dimensional arra6 passed as the arguments of
the function
E;!m+e: if the two imensional arra6 contains
Then the output should appear as:
Product of 7ow 1 C 2$$$
Product of 7ow 2 C D$$$
Product of 7ow 3 C3D$$
Product of 7ow / C 2/$$
</9 Write function in 899 which accepts an integer arra6 and siSe as arguments and replaces elements having odd
values with thrice its value and elements having even values with twice its value.
E;!m+e 3 if an arra6 of five elements initiall6 contains elements as 3 / % 1D F
The the function should rearrange the content of the arra6 as F 2 E% 32 2E
49 Write a function in 899 which accepts a 2D arra6 of integers and its siSe as arguments and displa6s the elements
which lie on diagonals. MAssuming the 2D Arra6 to "e a s0uare matri. with odd dimension i.e. 3.3 %.% E.E
etcWN
E;!m+e 3 if the arra6 content is
5 / <
D = 2
1 2 >
4ut put through the function should "e :
Diagonal 4ne : % E F
Diagonal Two : 3 E 1
59 Write a function in 899 which accepts a 2D arra6 of integers and its siSe as arguments and displa6s the elements
of middle row and the elements of middle column. MAssuming the 2D Arra6 to "e a s0uare matri. with odd
dimension i.e. 3.3 %.% E.E etcWN
E;!m+e 3 )f the arra6 content is
3 % /
E D F
2 1 2
4utput through the function should "e :
<iddle 7ow : E D F
<iddle 8olumn : % D 1
?9 Write function in 899 which accepts an integer arra6 and siSe as arguments and assign values into a 2D arra6 of
integers in the following format :
If &.e !rr!* %" 1@ 2@ <@ 4@ 5@ ?
The resultant 2D arra6 is given "elow
1 2 3 / % D
1 2 3 / % $
1 2 3 / $ $
1 2 3 $ $ $
1 2 $ $ $ $
1 $ $ $ $ $
If &.e !rr!* %" 1@ 2@ <
The resultant 2D arra6 is given :
1 2 3
1 2 $
1 $ $
=9 Write function in 899 which accepts an integer arra6 and siSe as arguments and assign values into a 2D arra6 of )
ntegers in the following format :
If &.e !rr!* %" 1@ 2@ <@ 4@ 5@ ?
The resultant 2D arra6 is given "elow :
1 $ $ $ $ $
1 2 $ $ $ $
1 2 3 $ $ $
1 2 3 / $ $
1 2 3 / % $
1 2 3 / % D
If &.e !rr!* %" 1@ 2@ <
The resultant 2D arra6 is given :
1 $ $
1 2 $
1 2 3
2) Write a function in 899 which accepts an integer arra6 and its siSe as arguments and e.changes the values of first
half side elements with the second half side elements of the arra6.
E;!m+e 3
)f an arra6 of 2 elements initial content as 2 / 1 D E F 23 1$
The function should rearrange arra6 as E F 23 1$ 2 / 1 D
F) Assume an arra6 + containing elements of structure +mplo6ee is re0uired to "e arranged in descending order of
-alar6. Write a 899 function to arrange same with the help of "u""le sort the arra6 and its siSe is re0uired to "e
passed as parameters to the function. Definition of structrure +mplo6ee is as follows:
-truct +mplo6ee
K
int +noL
char nameM2%NL
float -alar6L
OL
109 Write a userJdefined function in 899 to displa6 those elements of 2D arra6 TM/NM/N which are divisi"le
"6 1$$.
119 =iven two arra6s of integers I and H of siSes m and n respectivel6. Write a function named <+7=+#) which will
third arra6 named V such that the following se0uence is followed.
#i) All odd num"ers of I from left to right are copied into V from left to right.
#ii) All even num"ers of I from left to right are copied into V from right to left.
#iii) All odd num"ers of H from left to right are copied into V from left to right.
#iv) All even num"ers of H from left to right are copied into V from right to left.
I H and V are passed as arguments to <+7=+#).
E$. I is K3 2 1 E D 3O and KF 3 % D 2 2 1$O
the resultant arra6 V is K3 1 E 3 F 3 % 1$ 2 2 D D 2O
12)Write a userJdefined function named ,ower!half#) which ta>es 2D arra6 A with siSe * rows and * columns as
argument and prints the lower half of the arra6.
+g. 2 3 1 % $ 2
E 1 % 3 1 E 1
)nput 2 % E 2 1 the output will "e 2 % E
$ 1 % $ 1 $ 1 % $
3 / F 1 % 3 / F 1 %
1<9 -uppose a 1D arra6 A7 containing integers is arranged in ascending order. Write a user defined function in 899
to search for one integer from A7 with the help of "inar6 search method to show presence of the num"er in the
arra6. The function should have three parameters: #1) an arra6 A7 #2) the num"er to "e searched and #3) the
num"er of elements * in the arra6.
149 Write a program in 899 to sort an arra6 in ascending order depending on the users choice using
a. )nsertion -ort
". Gu""le -ort
c. -election -ort
1%) Write a function in 899 which accepts a 2D arra6 of integers and its siSe as arguments
and displa6s elements which are e.actl6 two digit num"er.
)f 2D arra6 is

12 22 /%% 11
32E /% 32 1F2/
1/31 1/D 2% 2
1/ F 3 12F
4utput is
1/ 2% 32 /% 11 22 12
L%#(ed L%"&"A S&!'("A 0ueue"
1) 8onsider the following program for lin>ed QUEUE : 4
struct *4D+
K int .L
float 6L
*4D+ ;ne.tL OL
class U5+5+
K *4D+ ;7;AL
pu"lic :
U5+5+# )
K 7C*5,,L
AC*5,,L
O
void )*-+7T# )L
void D+,+T+# )L
void -how# )L
XU5+5+# )L OL
Define )*-+7T# ) 1 D+,+T+# ) functions outside the class.
(2) WAP using function to insert and delete a set of integer values in a circular queue and display them.
<9 WAP using function to perform PUSH operation in a !"amicall! all#cate stac$ containing name and
registration num"er of students. Also declare the relevant structure:class and pointers.
/) WAP using function Uuedel# ) in 899 to displa6 and delete an element from a d6namicall6 allocated
Uueue containing nodes of the following structure :
struct student
K
int rollnoL
char nameM2$NL
student ;lin>L
OL
%) 8onsider the following portion of a program which implements a lin>ed stac> for ,i"rar6 . WAP using
functions P5-P#) 1 P4P#)to insert 1 delete a node in the stac> with re0uired information

struct ,i"rar6
K
int idL
char namesM2$NL
OL
class stac>
K
,i"rar6 ;topL
pu"lic :
stac>#)
K
topC*5,,L
O
void P5-P#)L
void P4P#)L
OL
D) =ive the necessar6 declarations for a 0ueue containing float t6pe num"ersL write a user defined
function in 899 to insert a float t6pe num"er in the 0ueue. 5se lin>ed representation of 0ueue.
E) 8onsider the following portion of a program which implements names 0ueue for Goo>s .
Write the definition of function )nsert#) to insert a new node in the 0ueue with re0uired
information . /
struct Goo>
K
char namesM/NM2$NL
OL
class UueueofGoo>s
K
Goo> UM1$NL
pu"lic :
int front rearL
UueueofGoo>s#)
K
frontCrearCJ1L
O
void )nsert#)L
void Delete#)L
OL
B9 WAP using a function in 899 to perform )nsert operation in d6namicall6 allocated Uueue containing
names of students.
F) Write a function in 899 which accepts a character arra6 and its siSe as arguments and reverse that arra6 without
using second arra6 and li"rar6 function.
E;!m+e : if the arra6 is having: &8omputer -cience(
Then after reversal it should rearranged as: &ecneic- retupmo8(
1$) Write a function in 899 to perform insert operation on a d6namicall6 allocated Uueue. /
struct *ode
K
)nt 8odeL
char DescriptionM1$NL
*ode ; lin>L
O
11) Write a function in 899 to perform insert operation on a d6namicall6 allocated Uueue. /
struct *ode
K
)nt 8odeL
char DescriptionM1$NL
*ode ; lin>L
O

You might also like