Vous êtes sur la page 1sur 12

Computer Science (083) Practical File for Class XII

Index for C++ Programming


Name: _____________________________ Section: ___ Roll No.: ____

Last Date of Submission (Program No. 1 21) Last Date of Submission (Program No. 22 2#) Last Date of Submission (Program No. 3! $!) SN . 1. Program Des%ri&tion

31 !" 2!11 31 !# 2!11 31 1! 2!11 'o&i%

2. ..

Write a program to play the following game: The player guesses a number from 2 to 19 an then the program generates three ran om numbers from 1!1 to 199. "f the sum of the igits of any of these numbers matches the player#s number$ then the player is eclare a winner otherwise the player looses the game. Write a function to generate the nth term in a +ibonacci se,uence. -se this function to print first N terms of the se,uence. Write programs to input the 'alues of x an n an sum up n terms of each of the following series:

%&& Re'ision (%lass )"*

%&& Re'ision (%lass )"*

x3 x5 x7 1/ 3! & 5! / 7!

%&& Re'ision (%lass )"*

0.

. . . WAP to generate n lines of the following patterns on the computer screen: (i* "f n is 0$ the output is 1 121 12.21 12.0.21

%&& Re'ision (%lass )"*

(ii* "f n is 0$ the output is 1111111 11111 111 1

(iii* "f n is 2$ the output is 1 1 1 1 1 1 1 1 1 1 1 1 (i'* "f n is 9$ the output is

1 1 1 1 111111111 1111111 11111 111 1

1 1 1

3 Write a program to rea a string an print out the . following : 1* No. of capital alphabets$ 2* No. of small alphabets$ .* No. of non/alphabets$ 0* No. of Wor s. (-se suitable functions for each operation* 4 Write a program to rea a string an print it after . replacing each of its capital alphabets by the correspon ing small alphabet an each small alphabet by its correspon ing capital alphabet. 2 Write a program to input a string. "f the string is a . palin rome then concatenate 56ello 7alin rome 5$ otherwise concatenate 56ello Non/palin rome 5 with the gi'en string. Then isplay the resultant string. 8 Write a program in %&& which accepts an integer array . an its si9e as arguments:parameters an e;changes the 'alues of first half si e elements with the secon half si e elements of the array. <;ample: "f an array of eight elements has initial contents as 2$0$1$4$2$9$2.$1! The function shoul rearrange the array as 2$9$2.$1!$2$0$1$4 9 Write a program to input n (=>2!* integers in an array . an then isplay the array after remo'ing all the uplicate entries from it. 1 Write a program to input the elements in a matri; of ! si9e m ; n an o the following operations on it: . (i* fin the row sums (ii* fin the column sums (iii* fin the iagonal sums (i'* fin the transpose ('* isplay the upper half ('i* isplay the lower half 1 Write a program to input the morning$ noon$ an e'ening 1 temperature for each of the se'en ays of a wee? an . then isplay a report showing the following: 1. @a;imum an minimum morning temperature 2. @a;imum an minimum noon temperature .. @a;imum an minimum e'ening temperature 0. A'erage morning temperature 3. A'erage noon temperature 4. A'erage e'ening temperature 2. A'erage temperature of the wee?

%&& Re'ision (%lass )"*

%&& Re'ision (%lass )"* %&& Re'ision (%lass )"*

%&& Re'ision (%lass )"*

%&& Re'ision (%lass )"*

%&& Re'ision (%lass )"*

%&& Re'ision (%lass )"*

(-se a 2B array* 1 Write a menu ri'en program to use a macro$ an inline 2 function$ an an outline function to fin the s,uare of . an integer input from the use. 1 Write a program to sort a list of character$ integers$ . floats$ or strings epen ing upon the user#s choice. -se . function o'erloa ing to o this. 1 Write a program to input two numbers n an ; an then 0 calculate ;n using a function power(* with suitable . parameters an return ata type. "f the 'alue of n is not passe to the function$ it shoul calculate ;1. 1 Write a program to input two numbers an increment the 3 smaller by 1!C. (-se the concept of return by . reference*. 1 Write a program to input Name an Aggregate mar?s of 4 each of the n (=>2!* stu ents of a class using . structures. The program shoul then isplay this mar?s list in the ascen ing or er of names or escen ing or er of mar?s epen ing upon the user#s choice. The lists shoul be isplaye in the following format using the gotox(() function: S.No. Name @ar?s ///// /////////////////// ///// 1 Write a program to input two istances in feet an 2 inches an then isplay the sum of these istances. -se . a function for this purpose. The function shoul ta?e the two istances as parameters an return the resultant istance. The program shoul also use a function A Dust(* that a Dusts a gi'en istance so that if the number of inches in a istance is more than or e,ual to 12$ it shoul be properly a Duste into feet. 1 Befine a class ST-B<NT that has the following ata 8 members: . Name) *o++ Number) ,ar-s of . sub/e%ts an member functions to input an isplay ata. "t also has a function member to assign stream on the basis of the table gi'en below: 01erage ,ar-s Stream 94C or more %omputer Science 91C / 93C <lectronics 84C / 9!C @echanical 81C / 83C <lectrical 23C / 8!C %hemical 21C / 23C %i'il Write a program to efine the class ST-B<NT an input the ata (e;clu ing Stream* of n (=>2!* stu ents an for each stu ent allot the stream. Bisplay a formatte report using the functions an eclarations a'ailable in iomani&.2. 1 Write a program to fin out the sum$ ifference$ an 9 pro uct of two rational numbers. -se a class with . suitable ata an function members to this Dob. The

%&& Re'ision (%lass )"* %&& Re'ision (%lass )"* %&& Re'ision (%lass )"* %&& Re'ision (%lass )"*

Structures

Structures

%lasses an EbDects

%onstructors an Bestructors

class shoul also ha'e two constructors F one non/ parameterise constructor which initiali9es a rational no. to !:1 an the other a parameteri9e constructor to initiali9e a rational number. 2 Write a program to efine a class 7E"NT with ata ! members x an y an function members to input an . isplay the co/or inates of a point. Also write a function member to fin the istance of a point from another point gi'en as a parameter an a copy constructor. Then efine a class Triangle which has three ata member each of type 7E"NT. Befine function members to input the co/or inates of three 'ertices$ isplay the co/or inates of the 'ertices$ an calculate an return the area of a triangle. 2 Write a program to efine a class ST-B<NT as specifie 1 in program no. 18. +rom this class eri'e a class . WERG"NH_ST-B<NT with e;tra ata members IEJ an E++"%<_ABBR<SS. Write appropriate function members an complete the program to emonstrate the use of inheritance. 2 Write a program to input the name of a te;t file from 2 the user an isplay: . a* The number of blan?s present in the file. b* The number of lines present in the file. c* The number of capital alphabets present in the file. * The number of small alphabets present in the file. e* The number of lines starting with a capital alphabet. f* The number of wor s present in the file. g* The number of igits present in the file. h* The number of wor s en ing with a 'owel 2 Write a program to input the name of a te;t file from . the user. Then input a string an search for it in the . file an isplay the status whether it is present in the file or not. The program shoul also chec? the e;istence of the file in the beginning. 2 Write a program to input a te;t file name$ rea the 0 contents of the file an create a new file name . %E7K.T)T$ which shall contain only those wor s from the file (which has been specifie by the user* that on#t en with a 'owel. +or e;ample$ if the original file contains Physical, Mental, or Emotional harm to anyone is a crime. Anonymous Then the te;t file %E7K.T)T shall contain Physical, Mental, or Emotional harm is . Anonymous 2 Write a program to perform S<AR%6 an R<7LA%< operation 3 on a te;t file. +or this$ input the name of a te;t file . from the user. Then input two characters an search for the first character in the file an replace it with the secon character. Bo it for all the occurances of the first character in the te;t file. (-se a temporary file for this purpose* 2 Beclare a structure telerec in %&&$ containing name (2! 4 characters* an telephone number. Write a program to

%opy %onstructor an %ontainership

"nheritance

Te;t +ile (Rea ing*

Te;t +ile (Rea ing*

Te;t +ile (Rea ing an Writing*

Te;t +ile (@o ification*

Jinary +ile (Rea ing an

. maintain a binary file of telephone recor s. The program shoul allow the following functions on the file: 1* To appen recor s in the file. 2* Bisplay the name for a gi'en telephone number. "f the telephone number oes not e;ist then isplay error message Mrecor not foun M. .* Bisplay the telephone number(s* for a gi'en name. "f the name oes not e;ist then isplay error message Mrecor not foun M. 2 A bloo ban? maintains a ata file that contains the 2 following information for e'ery onor: Name$ Bate of . Jirth$ Telephone number$ Jloo group. Write a program in %&& to o the following: 1* Hi'en a bloo group$ isplay name$ ate of birth an phone number of all the persons of the gi'en bloo group. 2* Appen recor s in the file. .* "nput a telephone number an mo ify the correspon ing recor . 2 %reate two payroll files %E@71.BAT an %E@72.BAT. <ach 8 of the files shoul ha'e recor s with the following . fiel s: <mpNo : "nteger Name : A string of 2! characters Salary : A floating point number. Joth the files shoul be create in the increasing or er of the <mpNo. Kour program shoul then merge the two files an obtain a thir file N<W%E@7.BAT. The program shoul also isplay the ata from all the three files. Bo not use arrays for merging an sorting of the files. 2 Write a menu ri'en program in %&& to perform the 9 following functions on a binary file 5JEEG.BATN . containing obDects of the following class: class Joo? O int Joo?NoP char Joo?_nameQ2!RP public: :: function to enter boo? etails 'oi enter etails(*P ::function to isplay Joo? etails 'oi show etails(*P ::function to return Joo?_no int Rboo?_no(* Oreturn Joo?_noPS ::function to return Joo?_name int Rboo?_name(* Oreturn Joo?_namePS SP 1. Appen Recor s 2. @o ify a recor for a gi'en boo? no. (-se see?g(*$ tellg(* for this purpose* .. Belete a recor with a gi'en boo? no. 0. Search for a recor with a gi'en Joo? name 3. Bisplay a sorte list of recor s (sort on Joo? No.* 4. Bisplay a sorte list of recor s (Sort on Joo? Name*

Writing*

Jinary +ile (Rea ing an Writing*

Jinary +ile (Rea ing an Writing*

Jinary +ile (Rea ing$ Writing$ an @o ification*

Note: (i* -se ynamic array for sorting of the file. (ii* -se goto;y(* to isplay the formatte reports. (iii* The program shoul be passwor protecte . . Write a program to create a lin?e list in which each ! no e contains the roll number an name of a stu ent. . Then perform search operations for name as well as roll no. on this list. . Write a menu ri'en program which allows the user to 1 perform the following operations on a one imensional . array: "nsertion$ eletion$ sorting (selection$ insertion*$ isplay. . Write a menu ri'en program to search an integer in a 2 list of integers using any of the following techni,ues. . (i* Linear Search (ii* Jinary Search -se bubble sort to sort the list$ if re,uire . . Write a program to input integer ata in two arrays. . Sort one of the arrays in ascen ing or er an the other . in escen ing or er. Then merge them into a thir array so that the ata in the thir array is in ascen ing or er. The program shoul then isplay the ata from all the three arrays. . Write a function in %&& which accepts an integer array 0 an its si9e as arguments:parameters an assigns the . elements into a two/ imensional array of integers in the following format: "f the array is 1$ 2$ .$ 0$ 3$ 4 "f the array is 1$ 2$ . The resultant 2/B array is: The resultant 2/B array is: 1 2 . 0 3 4 1 2 . 1 2 . 0 3 ! 1 2 ! 1 2 . 0 ! ! 1 ! ! 1 2 . ! ! ! 1 2 ! ! ! ! 1 ! ! ! ! ! . . Suppose a company ?eeps a single imensional array 3 K<ARQ1!!R such that K<ARQGS contains the number of . employees appointe in year G. Write a %&& which stores ran om number of employees (! F 3!* in the array an then performs the following tas?s: a* To fin each of the years in which no employee was appointe . b* To fin the number of years in which no employee was appointe . c* To fin the number of employees who were appointe 3 years ago or before. . Write a menu ri'en program which allows the user to 4 perform the following operations on a stac? (Array . implementation*: 1* 7ush 2* 7op .* Bisplay . Write a menu ri'en program which allows the user to 2 perform the following operations on a ,ueue (Array

Bata Structures (Self Referential Structures* Bata Structures (Arrays*

Bata Structures (Arrays*

Bata Structures (Arrays*

Bata Structures (Arrays*

Bata Structures (Array*

Bata Structures (Array Stac?* Bata Structures (Array Tueue*

. implementation*: 1* "nsert 2* Belete .* Bisplay . Write a menu ri'en program which allows the user to 8 perform the following operations on a stac? (Lin?e . implementation*: 1* 7ush 2* 7op .* Bisplay . Write a menu ri'en program which allows the user to 9 perform the following functions on a ,ueue (Lin?e . implementation*: 1* "nsert 2* Belete .* Bisplay 0 Write a program using a stac? to input a number an ! isplay it as a pro uct of its prime factors in the . escen ing or er. <.g.$ if the number input is 232$ then the output shoul be 2 ; . ; . ; 2 ; 2. (The smallest factor of any number is guarantee to be a prime*

Bata Structures (Lin?e Stac?*

Bata Structures (Lin?e Tueue*

Bata Structures (Stac?*

Index for S3L


Name: _____________________________ Section: ___ Roll No.: ____

Consider the tables given below and answer the questions that follow: able: Employee Salary Zone A e 3$$$$ 35$$$ 3%$$$ 3&$$$ 3%$$$ 37$$$ 3-$$$ West Centre West (orth ,ast .outh (orth %& 3$ )$ 3& %%& %-

N o ! % 3 ) 5 7

Name "u#ul 'riti#a (avee n *da+ (upur "o#sh .hell+

!ra"e A A

#ept !$ !$ %$ 3$ %$ !$ 3$

C / A

#e pt !$ %$ 3$

able: #epartment #Name $inSal $a%Sal .ales 0inance Admin %5$$$ 3$$$$ %5$$$ 3%$$$ 5$$$$ )$$$$

&'# ! 5 7

Write .12 commands to: Create (a)le * Insert Into !3 Create the above tables and insert tuples in them3 Simple Select %3 4ispla+ the details of all the emplo+ees3 33 )3 4ispla+ the .alar+5 6one5 and 7rade of all the emplo+ees3

4ispla+ the records of all the emplo+ees along with their annual salaries3 he .alar+ column of the table contains monthl+ salaries of the emplo+ees3 53 4ispla+ the records of all the emplo+ees along with their annual salaries3 he .alar+ column of the table contains monthl+ salaries of the emplo+ees3 he new column should be given the name 8Annual .alar+93 Con"itional Select usin +,ere Clause -3 4ispla+ the details of all the emplo+ees who are below 3$ +ears of age3 73 &3 4ispla+ the names of all the emplo+ees wor#ing in (orth :one3 4ispla+ the salaries of all the emplo+ees of department !$3

-sin N-..

;3 ! $ 3

4ispla+ the details of all the emplo+ees whose 7rade is (*223 4ispla+ the details of all the emplo+ees whose 7rade is not (*223

-sin #IS(INC( Clause ! 4ispla+ the names of various :ones from the table ,mplo+ee3 A :one name should appear onl+ once3 ! 3 ! 4ispla+ the various department numbers from the table ,mplo+ee3 A department number should be displa+ed % onl+ once3 3

-sin .o ical 'perators (N'(/ AN#/ '0) ! 4ispla+ the details of all the emplo+ees of department !$ who are above 3$ +ears of age3 3 3 ! ) 3 ! 5 3 ! 3 ! 7 3 ! & 3 -sin IN 'perator ! 4ispla+ the names of all the emplo+ees who are wor#ing in department %$ or 3$3 >*sing ?( operator@ ; 3 % 4ispla+ the names and salaries of all the emplo+ees who are wor#ing neither in West :one nor in Centre :one3 $ >*sing ?( operator@ 3 4ispla+ the details of all the emplo+ees whose grade is between <A= and <C=3 4ispla+ the details of all the emplo+ees whose salar+ is between 3%$$$ and 3&$$$3 4ispla+ the names of all the emplo+ees who are wor#ing in department %$ or 3$3 4ispla+ the names and salaries of all the emplo+ees who are wor#ing neither in West :one nor in Centre :one3 4ispla+ the details of all the emplo+ees who are getting a salar+ of more than 35$$$ in the department 3$3

-sin 1E(+EEN 'perator % 4ispla+ the details of all the emplo+ees whose salar+ is between 3%$$$ and 3&$$$3 ! >*sing /, W,,( operator@ 3 % 4ispla+ the details of all the emplo+ees whose grade is between <A= and <C=3 % >*sing /, W,,( operator@

3 -sin .I2E 'perator % 4ispla+ the name5 salar+5 and age of all the emplo+ees whose names start with <"=3 3 3 % ) 3 % 5 3 % 3 % 7 3 -sin A re ate functions % 4ispla+ the sum and average of the salaries of all the emplo+ees3 & 3 % ; 3 3 $ 3 -sin '0#E0 13 clause 3 4ispla+ the details of all the emplo+ees in the ascending order of their salaries3 ! 3 3 % 3 3 4ispla+ the details of all the emplo+ees in the ascending order of their grades and within grades in the 3 descending order of their salaries3 3 4ispla+ the details of all the emplo+ees in the descending order of their names3 4ispla+ the number of emplo+ees wor#ing in department !$3 4ispla+ the highest and the lowest salaries being paid in department !$3 4ispla+ the details of all the emplo+ees whose names contain <a= as the second character3 4ispla+ the name5 salar+5 and age of all the emplo+ees whose names do not contain <a= 4ispla+ the name5 salar+5 and age of all the emplo+ees whose names contain <a= 4ispla+ the name5 salar+5 and age of all the emplo+ees whose names end with <a=3

-sin !0'-P 13 clause 3 4ispla+ the total number of emplo+ees in each department3 ) 3 3 5 4ispla+ the highest salar+5 lowest salar+5 and average salar+ of each :one3

3 3 4ispla+ the average age of emplo+ees in each department onl+ for those departments in which average age is - more than 3$3 3

-sin -P#A(E/ #E.E(E/ A.(E0 (A1.E 3 Put the grade / for all those whose grade is (*223 7 3 3 & 3 3 ; 3 ) $ 3 ) ! 3 Creatin an" -sin 4IE+s ) Create a view WestC6one which displa+s the records of emplo+ees wor#ing in West :one onl+3 % 3 ) 3 3 ) ) 3 ) 5 3 ) 3 5'IN of t6o ta)les ) 4ispla+ the details of all the emplo+ees who wor# in .ales department3 7 3 ) & 3 4ispla+ the (ame and 4epartment (ame of all the emplo+ees3 *sing the view WestC6one increase the salar+ of all the emplo+ees b+ !%A3 4ispla+ the records of the emplo+ees from the view AboveC3$ who wor# in the .ales department3 4ispla+ the data from the view WestC6one3 Create a view AboveC3$ which displa+s the records of onl+ those emplo+ees who are above 3$ +ears of age3 Add another column Bire4ate of t+pe 4ate in the ,mplo+ee table3 4elete the records of all the emplo+ees of department !$ who are above )$ +ears of age3 4elete the records of all the emplo+ees whose grade is C and salar+ is below 3$$$$3 ?ncrease the salar+ of all the emplo+ees above 3$ +ears of age b+ !$A3

#0'P (A1.E/ #0'P 4IE+ ) 4rop the views created above3 ; 3 5 $ 3 4rop the tables ,mplo+ee and 4epartment3