List Of Practicals for Practical Record Class XII B

List Of Practicals for Practical Record
Class XII B- 2012-13
1.
C++
Write a program to play the following game:
The player guesses a number from 2 to 19 and then the program generates three random Revision
numbers from 101 to 119. If the sum of the digits of any of these numbers matches the
player’s number, then the player is declared as winner otherwise the player looses the game
2.
Write a program to generate a random number from 1 to 100 and let the user guess it in three C++
choices. In every choice, compare the number guessed by the user and give the hint as your Revision
number is very near to the expected number or your number is very far to the expected
number. If user guesses the random number within 3 choices, then declare as winner with % of
accuracy (correct guess in choice 1 is 100%, at choice 2 is 50%, at choice 3 is 30%)
3.
Write a program to generate the following patterns
a)
4.
5.
1
121
12321
1234321
123454321
b)
C++
Revision
5
545
543 45
5432345
543212345
C++
Write a program to generate Fibonacci series upto Nth term where N is given as input and also
Revision
display the total number of terms present upto Nth term.
Write a program to input a number and check whether it is a prime number or not
C++
Revision
C++
Revision
6.
Write a program to input a number and check whether it is a perfect number or not.
Example : 6 is a perfect number as sum of its factors 1 + 2 + 3 is again 6.
7.
Write a program to input a number and check whether it is a exact number or not.
Hint : if sum of factorials of each digit of a numbe is again the same number, then it is a exact
number.
Example : 145 = 1! + 4! + 5! (1+24+120 = 145)
8.
Write a program to input two number say a and b and display all prime numbers between a C++
Revision
and b and also display the total number of prime numbers present in this range.
9.
Define a function Factorail() which accepts an integer value and returns its factorial. Write a
main program to display the factorial value of 1 to 10 using Factorial() function.
C++
Revision
C++
Revision
10. Define a function powerOf() which takes two arguments base value say X and the power value C++
Y
Revision
say Y and value of returns X (don’t use any predefined function).
11.
Write a program of your choice to demonstrate function overloading.
12. Define a class HOTEL in C++ with the following description:
Private Members
 Rno
//Data Member to store Room No
 Name
//Data Member to store customer Name
 Tariff
//Data Member to store per day charge
 NOD
//Data Member to store Number of days
 CALC
//A function to calculate and return amount as NOD*Tariff
and if the value of NOD*Tariff is more than 10000 then as 1.05*NOD*Tariff
Function
Overloadin
g Chapter
3
Classes
and
Objects
Chapter 4
Page 1 of 8
Public Members:
Checkin( )
//A function to enter the content RNo,Name, Tariff and
NOD
Checkout()
//A function to display Rno, Name, Tariff, NOD
and Amount (Amount to be displayed by calling function CALC( )
13. 2. Define a class Applicant in C++ with following description:
Private Members
 A data member ANo ( Admission Number) of type long
 A data member Name of type string
 A data member Agg(Aggregate Marks) of type float
 A data member Grade of type char
 A member function GradeMe( ) to find the Grade as per the Aggregate Marks
obtained by a student. Equivalent Aggregate marks range and the respective
Grades are shown as follows
Aggregate Marks
Grade
> = 80
A
Less than 80 and > = 65
B
Less than 65 and > = 50
C
Less than 50 and > = 33
D
Less than 33
E
Public Members
 A constructor to initialize all the data members with appropriate initial values.
 A function Enter( ) to allow user to enter values for ANo, Name, Agg & call function
GradeMe( ) to find the Grade
 A function Result ( ) to allow user to view the content of all the data members.
Classes
and
Objects
14. Define a class MyString with the following description
Classes
and
Objects
Private Members
 A data member STRING
 A data member LEN (Length of String) of integer type.
Public Members
 a Constructor function to initialize string with null and len with 0
 a function to input a string and assign value to len accordingly.
 A function MyCopy(char *s) which copies the contents of string s to datamember
STRING and update len value.
 A function MyCat(char *s) which concatenates string S with STRING. The concatenated
string must be in STRING and update len accordingly
 A function MyCompare(char *s) which comapres STRING with S and returns a integer
value (very similar to strcmp function).
 A function ToUpperCase() which converts string to upper case.
 A function ToLowerCase() which converts string to lower case.
Note : don’t use any predefined string functions in all these above functions.
15. Define a class named HOUSING with the following descriptions:
Private Members:
 REG_NO
integer (Ranges 10-1000)
 NAME
array of characters (string)
 TYPE
character
 COST
float
Public Members
 A constructor to initialize all the data members with appropriate initial values.
 Function Read_Data() to input the data members
 Function Display() to display the details of all the data members.
Constructo
rs &
Destructor
s
Chapter 4
&5
Chapter 4
Classes
and
Objects
Chapter 4
Page 2 of 8

Function Draw_Nos() to choose and display the details of 2 houses selected randomly
from an array of 10 objects of type HOUSING. Use random function to generate the
registration nos to match with REG_NO from the array.
16. Imagine a publishing company that markets both books and audio-cassete versions of its
works. Create a class publication that storea the title ( string) and price (float) of a publication.
From this class derive two classes : BOOK, which adds page count (int) and TAPE,which adds a
playing time in minutes (float). Each of these three classes should have a getdata() function to
get its data from the user at the keyboard, and a putdata() function to display its data.
Write main frunction to test the book and tape classes by creating objects of them and calling
all the funcitons.
17. Assume that the bank maintains two kinds of accounts for customers, one called as savings
account and the other as current account. The savings account provides compound interest
and withdrawal facilities but not cheque book facility. The current account provides cheque
book facility but no interest. Current account holders should also maintain minimum valance
and if the balance falls below this level, a service charge is imposed.
Create a class Account that storea customer name, account number and opening balance.
From this account class derive the classes Current and Savings to make them more spedific to
their requirements. Include necessary member funcitons. (Refer page 290 of 9th edition)
Inheritanc
e
Chapter 6
Inheritanc
e
Chapter 6
18.
Data File
Assume a text file “coordinate.txt” is already created. Using this file create a C++ function
Handling
to count the number of words having first character capital.
Chapter 7
19.
Data File
Function to count number of lines from a text files (a line can have maximum 80 characters
Handling
or ends at ‘.’
Chapter 7
20.
Data File
Write a function in a C++ to count the number of uppercase alphabets, alphabats, digits,
Handling
white spaces and vowels present in a text file “BOOK.txt”
Chapter 7
21. Assume a text file “Test.txt” is already created. Using this file, write a function to create Data File
three files “LOWER.TXT” which contains all the lowercase vowels and “UPPER.TXT” which Handling
contains all the uppercase vowels and “DIGIT.TXT” which contains all digits.
Chapter 7
22. Write a function in C++ to count the no. of “He”, or “She” words present in a text file
“story.txt”.If the file “story.txt” content is as follows:
He is playing in the ground. She is
playing with her dolls.
The output of the function should be
Count of He/She in file is: 2
23. Write a function in C++ to search for camera from a binary file “CAMERA.DAT” containing
the objects of class CAMERA (as defined below). The user should enter the ModelNo and
the function should search and display the details of the camera.
Data File
Handling
Chapter 7
Data File
Handling
Chapter 7
class CAMERA
{ long ModelNo; float MegaPixel; int Zoom; Char Details[120];
public:
void Enter() {
cin>>ModelNo>>MegaPixel>>Zoom; gets(Details); }
void Display(){ cout<<ModelNo<<MegaPixel<<Zoom<<Details<<endl;
}
long GetModelNo() { return ModelNo;
}
24. Write a function to input a record number and display it randomly from a file called Data File
STUDENT.DAT. Assume that student.dat is having some records stored in it with STUDENT class Handling
that contains Admission no, student class, roll no,section, student name as data members. Chapter 7
Program should display the total number of records exist in student.dat and ask the user to
enter ther required record number to display.
Page 3 of 8
25. Write a program to input admission number and update/modify its contents in student.dat file Data File
whose records have stored using a class STUDENT with Admission no, student class, roll Handling
no,section, student name as data members.
Chapter 7
26. Write a program to create a dynamic integer array and display its contents with the help of Pointers
Chapter 8
pointers.
27. Write a program to create an integer array and sort it using Bubble Sort algorithm. Display the Arrays
Chapter 9
array before and after sorting.
28. Write a program to create an integer array and sort it using InsertionSort algorithm. Display Arrays
Chapter 9
the array before and after sorting.
29. Write a program to search for an element and display its location if found in an integer array Arrays
Chapter 9
using Linear Search Algorithm.
30. Write a program to search for an element and display its location if found in an integer array Arrays
Chapter 9
using Binary Search Algorithm.
31. Write a Get2From1() function in C++ to transfer the content from one array ALL[ ] to two
different arrays Odd[ ] and Even[ ]. The Odd[ ] array should contain the values from odd
positions(1,3,5,….) of ALL[ ] and Even[ ] array should contain the values from even
positions (0,2,4,…) of ALL[ ].
Example: If the ALL array contains 12,34,56,67,89,90 the Odd[ ] array should contain 34,
67,90 and the Even[ ] array should contain 12,56,89
32. Write a function in C++ which accepts an integer array and its size as argument and
exchanges the value of first half side elements with the second half side elements of the
array.
Example: If an array of eight elements has initial content as 2,4,1,6,7,9,23,10. The
function should rearrange the array as 7,9,23,10,2,4,1,6.
33. Write function SORTPOINTS() in c++ to sort an array of structure Game in descending order
of points using Bubble Sort Note: Assume the following definition of structure Game
struct Game
{long PNo; // Player Number
char PName[20];
long points;};
Write
a
function in C++ to merge the contents of two sorted arrays A & B into third array C.
34.
Assuming array A is sorted in ascending order, B is sorted in descending order, the
resultant array is required to be in ascending order.
35. Write a separate program to find each of the following.
a) Sum of two matrices
b) Product of two matrices
c) Transpose of a Matrix
d) Row sum and column sum
36.
Arrays
Chapter 9
Arrays
Chapter 9
Linked
Lists,
Write a menu driven program to perform push, pop, display operations in a formula based
Stacks,
stack.
Queues
Chapter 10
37. Write a menu driven program to perform insert, delete and display operations in a formula
bases queue.
38. Write a menu driven program to insert a new node at the beginning, insert a new node at
the end, insert a new node after a specified node and delete a node from beginning, delete
a node from end, delete a node from middle and display the linked list.
Page 4 of 8
39.
Write a menu driven program to perform push, pop, display operations in a Dynamic stack.
40. Write a menu driven program to perform insert, delete and display operations in Dynamic
queue.
Chapter 12 – SQL Queries
Write SQL commands for (i) to (viii) on the basis of relations given below:
BOOKS
book_id
Book_name
author_name
Publishers
k0001
Let us C
Sanjay mukharjee
EPB
p0001
Genuine
J. Mukhi
FIRST PUBL.
m0001
Mastering c++
Kanetkar
EPB
n0002
Vc++ advance
P. Purohit
TDH
k0002
Near to heart
Sanjeev
FIRST PUBL.
Price
450
755
165
250
350
Type qty
Comp 15
Fiction 24
Comp 60
Comp 45
Fiction 30
ISSUED
Book_ID
Qty_Issued
L02
13
L04
5
L05
21
i. To show the books of FIRST PUBL Publishers written by P.Purohit.
ii. To display cost of all the books written for FIRST PUBL.
iii. Depreciate the price of all books of EPB publishers by 5%.
iv. To display the BOOK_NAME,price of the books whose more than 3 copies have been issued.
v. To show total cost of books of each type.
vi. To show the detail of the most costly book.
Q2. Write SQL commands for (a) to (f) and write output for (g) on the basis of PRODUCTS relation given
below:
PRODUCT TABLE
PCODE PNAME
COMPANY
PRICE STOCK MANUFACTURE WARRANTY
P001 TV
BPL
10000 200
12-JAN-2008
3
P002 TV
SONY
12000 150
23-MAR-2007
4
P003 PC
LENOVO
39000 100
09-APR-2008
2
P004 PC
COMPAQ
38000 120
20-JUN-2009
2
P005 HANDYCAM
SONY
18000 250
23-MAR-2007
3
a) To show details of all PCs with stock more than 110.
b) To list the company which gives warranty for more than 2 years.
c) To find stock value of the BPL company where stock value is sum of the products of price and stock.
d) To show number of products from each company.
e) To count the number of PRODUCTS which shall be out of warranty on 20-NOV-2010.
f) To show the PRODUCT name which are within warranty as on date.
g). Give the output of following statement.
(i) Select COUNT(distinct company) from PRODUCT.
(ii) Select MAX(price)from PRODUCT where WARRANTY<=3
3.
Table : SchoolBus
Page 5 of 8
(b)
(c)
(d)
(e)
(f)
(g)
Rtno Area_overed
Capacity Noofstudents Distance Transporter
Charges
1
Vasant kunj
100
120
10
Shivamtravels 100000
2
Hauz Khas
80
80
10
Anand travels 85000
3
Pitampura
60
55
30
Anand travels 60000
4
Rohini
100
90
35
Anand travels 100000
5
Yamuna Vihar
50
60
20
Bhalla Co.
55000
6
Krishna Nagar
70
80
30
Yadav Co.
80000
7
Vasundhara
100
110
20
Yadav Co.
100000
8
Paschim Vihar
40
40
20
Speed travels
55000
9
Saket
120
120
10
Speed travels
100000
10
Jank Puri
100
100
20
Kisan Tours
95000
To show all information of students where capacity is more than the no of student in order of
rtno.
To show area_covered for buses covering more than 20 km., but charges less then 80000.
To show transporter wise total no. of students traveling.
To show rtno, area_covered and average cost per student for all routes where average cost per
student is - charges/noofstudents.
Add a new record with following data:
(11, “ Moti bagh”,35,32,10,” kisan tours “, 35000)
Give the output considering the original relation as given:
(i) select sum(distance) from schoolbus where transporter= “ Yadav travels”;
(ii) select min(noofstudents) from schoolbus;
(iii) select avg(charges) from schoolbus where transporter= “ Anand travels”;
(i)
select distinct transporter from schoolbus;
4.
(a)
(b)
(c)
(d)
(e)
(f)
TABLE : GRADUATE
S.NO
NAME
STIPEND
SUBJECT
AVERAGE
DIV.
1
KARAN
400
PHYSICS
68
I
2
DIWAKAR
450
COMP. Sc.
68
I
3
DIVYA
300
CHEMISTRY
62
I
4
REKHA
350
PHYSICS
63
I
5
ARJUN
500
MATHS
70
I
6
SABINA
400
CEHMISTRY
55
II
7
JOHN
250
PHYSICS
64
I
8
ROBERT
450
MATHS
68
I
9
RUBINA
500
COMP. Sc.
62
I
10
VIKAS
400
MATHS
57
II
List the names of those students who have obtained DIV 1 sorted by NAME.
Display a report, listing NAME, STIPEND, SUBJECT and amount of stipend received in a year
assuming that the STIPEND is paid every month.
To count the number of students who are either PHYSICS or COMPUTER SC graduates.
To insert a new row in the GRADUATE table: 11,”KAJOL”, 300, “computer sc”, 75, 1
Give the output of following sql statement based on table GRADUATE:
(i)
Select MIN(AVERAGE) from GRADUATE where SUBJECT=”PHYSICS”;
(ii) Select SUM(STIPEND) from GRADUATE WHERE div=2;
(iii) Select AVG(STIPEND) from GRADUATE where AVERAGE>=65;
(iv) Select COUNT(distinct SUBDJECT) from GRADUATE;
Assume that there is one more table GUIDE in the database as shown below:
Table: GUIDE
MAINAREA
ADVISOR
Page 6 of 8
PHYSICS
COMPUTER SC
CHEMISTRY
MATHEMATICS
VINOD
ALOK
RAJAN
MAHESH
g) What will be the output of the following query:
SELECT NAME, ADVISOR
FROM GRADUATE,GUIDE WHERE SUBJECT= MAINAREA;
5.
Write SQL command for (i) to (vii) on the basis of the table SPORTS
Table: SPORTS
Student NO
10
11
12
13
14
15
(a)
(b)
(c)
(d)
(e)
(f)
(g)
Class
7
8
7
7
9
10
Name
Sammer
Sujit
Kamal
Venna
Archana
Arpit
Game1
Cricket
Tennis
Swimming
Tennis
Basketball
Cricket
Grade
B
A
B
C
A
A
Game2
Swimming
Skating
Football
Tennis
Cricket
Atheletics
Grade2
A
C
B
A
A
C
Display the names of the students who have grade ‘C’ in either Game1 or Game2 or both.
Display the number of students getting grade ‘A’ in Cricket.
Display the names of the students who have same game for both Game1 and Game2.
Display the games taken up by the students, whose name starts with ‘A’.
Assign a value 200 for Marks for all those who are getting grade ‘B’ or grade ‘A’ in both Game1
and Game2.
Arrange the whole table in the alphabetical order of Name.
Add a new column named ‘Marks’.
6. Write SQL command for (i) to (vii) on the basis of the table Employees & EmpSalary
Empid
010
105
152
215
244
Firstname
Ravi
Harry
Sam
Sarah
Manila
300
335
400
441
Robert
Ritu
Rachel
Peter
Empid
010
105
152
215
244
300
Salary
75000
65000
80000
75000
50000
45000
Table: Employees
Lastname
Kumar
Waltor
Tones
Ackerman
Sengupta
Samuel
Tondon
Lee
Thompson
Table: EmpSalary
Benefits
15000
15000
25000
12500
12000
10000
Address
Raj nagar
Gandhi nagar
33 Elm St.
440 U.S. 110
24 Friends
street
9 Fifth Cross
Shastri Nagar
121 Harrison St.
11 Red Road
City
GZB
GZB
Paris
Upton
New Delhi
Washington
GZB
New York
Paris
Designation
Manager
Manager
Director
Manager
Clerk
Clerk
Page 7 of 8
335
400
441
40000
32000
28000
10000
7500
7500
Clerk
Salesman
Salesman
Write the SQL commands for the following :
(i)
To show firstname,lastname,address and city of all employees living in paris
(ii)
To display the content of Employees table in descending order of Firstname.
(iii)
To display the firstname,lastname and total salary of all managers from the tables Employee
and empsalary , where total salary is calculated as salary+benefits.
(iv)
To display the maximum salary among managers and clerks from the table Empsalary.
Give the Output of following SQL commands:
(i)
Select firstname,salary from employees ,empsalary where designation = ‘Salesman’ and
Employees.empid=Empsalary.empid;
(ii)
Select count(distinct designation) from empsalary;
(iii)
Select designation, sum(salary) from empsalary group by designation having count(*) >2;
(iv)
Select sum(benefits) from empsalary where designation =’Clerk’;
7. (a) What do you understand by Selection and Projections in relational algebra ?
Consider the following table EMPLOYEE and salgrade and answer (b) and (c) part of the Question:
Table: EMPLOYEE
ECODE
NAME
DESIG
SGRADE
DOJ
DOB
101
Abdul Ahmad
EXECUTIVE
S03
23-Mar-2003
13-Jan-1980
102
Ravi Chander
HEAD-IT
S02
12-Feb-2010
22-Jul-1987
103
John Ken
RECEPTIONIST
S03
24-Jan-2009
24-Feb-1983
104
Nazar Ameen
GM
S02
11-Aug-2006
03-Mar-1984
105
Priyam Sen
CEO
S01
29-Dec-2004
19-Jan-1982
Table:SALGRADE
SGRADE
SALARY
HRA
S01
56000
18000
S02
32000
12000
S03
24000
8000
(b) Write SQL commands for the following statements:
(i) To display the details of all EMPLOYEES in descending order of DOJ.
(ii) To display NAME and DESIG of those EMPLOYEES whose SALGRADE is either S02 or SO3.
(iii) To display the content of all the EMPLOYEES table, whose DOJ is in between 09-Feb-2006 and 08-Aug2009.
(iv) To add a new row with the following
109, ‘Harish Roy’, ‘HEAD-IT’, ‘S02’,’09-Sep-2007’, ’21-Apr-1983’
(c) Give the output of the following SQL queries :
(i) SELECT COUNT(SGRADE), SGRADE FROM EMPLOYEE GROUP BY SGRADE;
(ii) SELECT MIN(DOB), MAX(DOJ) FROM EMPLOYEE;
(iii) SELECT NAME,SALARY FROM EMPLOYEE E, SALGRADE S
WHERE E.SGARDE=S.SGRADE AND E.ECODE<103;
(iv) SELECT SGRADE, SALARY+HRA FROM SALGRADE WHERE SGRADE=’S02’
Page 8 of 8