Sie sind auf Seite 1von 7

List of Programs for Practical file

Subject: Computer Science Old(283)


Batch : 2019-20
1 Write a program to print the following series up to nth term entered by the user:
12+(12+22)+ (12+22+32)+ (12+22+32+42)+…………… (12+22+32+42+…..n2)
2 Write a function CHANGE( ) in C++, which accepts an array of integer and its size as parameters
and divide all those array elements by 5 which are divisible by 5 and multiply other-array elements by
4. Sample Input Data of the array
A[0] A[1] A[1] A[2] A[3]
10 3 4 20 7

Content of the array after Calling CHANGE() function:


A[0] A[1] A[1] A[2] A[3]
2 12 16 4 28
3 Write a program in C++ that takes a 2-D array of size 4x4 as argument and swap(interchange) the
elements of first column with third column.
Example: If two dimensional array contains the following elements:
3 7 10 9
25 13 2 8
13 21 21 12
15 16 12 19
After swapping elements of 2-D array :
10 7 3 9
2 13 25 8
21 21 13 12
12 16 15 19
4 Write a user defined function Half( ) , which takes 2D array and its size(row and column) as arguments
and print the upper half(diagonal) 0f the array.
e.g. If 2d array is :
2 3 4 5
7 8 9 1
4 5 6 3
1 3 6 7
The output will be:
2 3 4 5
8 9 1
6 3
7
5 Write a function in C++, which accepts an integer array and its size as arguments and exchange the
values of first half side elements with the second half side elements of array.
e.g. if an array of eight elements has initial content as:
2 4 1 6 7 9 23 10
Then the function should arrange the elements as follows:
7 9 23 10 2 4 1 6
6 Write a function in C++ to print the sum of all the non-negative elements present on both the diagonal of
a two dimensional array passed as argument to the function.
7 Write a function in C++ which accept an integer array and its size as parameters and swap the elements
of every even location with its following odd location.
e.g. if an array contains the following elements:
2 4 1 6 5 7 9 23 10
Then the function should rearrange array as:
4 2 6 1 7 5 23 9 10
8 Write a program to illustrate Insertion sort in Single Dimensional Array.
9 Write a program to illustrate Binary search in Single Dimensional Array.
10 Write a definition of a function SUMMIDCOL( int ARR[][10], int N, int M) in C++ which finds the sum
of middle column’s elements of array ARR(where N represent number of rows and M represent the
number of columns which is odd)
Example:
3 7 10 9 2
25 13 12 8 4
13 21 20 12 5
15 16 8 19 3
Output: Sum of Middle column’s elements : 50
11 Write the definition of a member function Q_Insert( ) and Q_Delete( ) for a class Queue in C++ to insert
a new application information in a dynamically allocated queue and to remove information whose code
is already given below as a part of the program.
struct Application
{
int App_Id;
char App_Name[20];
Application *next;
};
class Queue
{
Application *Front, *Rear;
public:
Queue()
{
Front = Rear= NULL;
}
void Q_Insert();
void Q_Delete();
};
12 Write the functions in C++ to perform POP and PUSH operations in dynamically allocated stack
containing the object of the following structure:
struct Member
{
long Mno; //Member Number
char Mname[20]; //Member Name
Member *link;
};
class STACK
{
Member *top;
public:
STACK()
{
top = NULL;
}
void POP();
void PUSH();
};
13 Write the functions in C++ to perform POP and PUSH operations in dynamically allocated stack
containing the object of the following structure:
struct Member
{
long Mno; //Member Number
char Mname[20]; //Member Name
Member *Link;
};
class STACK
{
Member *top;
public:
STACK()
{
top = NULL;
}
void POP();
void PUSH();
};
14 Write a function in C++ to count and display the no of three letter words in the file “VOWEL.TXT”.
Example:
If the file contains:
A boy is playing cricket. I love to eat pizza. A plane is in the sky.
Then the output should be: 4
15 Write a program to count the number of ‘the’ and “was” words present in a text file “data.txt”.
16 Write a program to count number of lines starting with alphabet ‘T’ in a text file “entry.txt”
17 Write a function in C++ to search for a ItemNo from a binary file ”Item.dat” and display its details,
assuming that the binary file is containing the objects of the following class:
class ITEM
{ int Ino;
char Iname[20];
public:
int RetINO()
{ return Ino; } void
Enter()
{ cin>>Ino; gets(Iname); }
void display()
{ cout<<Ino<<”\t”<<Iname<<endl; }
};
18 Write a function in C++ to read contents from the file “CAR.DAT” and display the details of car with
milage between 100 to 150.
class CAR
{ int C_No;
char C_Name[20];
float Milage;
public:
int Ret_Milage()
{ return Milage;
}
void Enter()
{ cin>>C_No; gets(C_Name);cin>>Milage }
void display()
{ cout<<C_No<<”\t”<<C_Name<<”\t”<<Milage;
}
};
19 Define a class Applicant in C++ with following description
Private members :
 ANo(Admission Number) of type int
 Name of type string
 Agg(Aggregate Marks) of type float
  Grade of type char
 A member function GradeMe() to find the grade as per the Aggregate obtained by the student.
Equivalent Aggregate Marks range and 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 D
Public members :
 A function ENTER() to allow user to enter values for ANo , Name , Agg and call function
GradeMe() to find grade.
 A function RESULT() to allow user to view the contents of all the data members.
20 Define a class HOTEL in C++ with the following description:
Private Members:
 Rno - Data member to store room number
 Name - Data member to store customer name
 Tariff - Data member to store per day charges
 NOD - Data member to store number of days of stay
 A member function CALC() to calculate and return amount as NOD*Tariff and if the value of
NOD*Tariff is more than 10000 then return amount as 1.05*NOD*Tariff

Public Members:
  A function Checkin() to allow user to enter values for Rno, Name, Tariff and NOD.
 A function Checkout() to display value of all the data members and amount by calling function
CALC().
21 Define a class FLIGHT in C++ with the following description:
Private Members:
 Data member FNo of type integer
 Data member Destination of type string
 Data member Distance of type float
 Data member Fuel of type float
 A member function CALFUEL() to calculate the value of Fuel as per the following criteria:
Distance Fuel
<=1000 500
More than 1000 and less than 2000 1100
>=2000 2200

Public Members:
 A function FEEDINFO() to allow user to enter values for FNO , Destination, Distance, Fuel
and call function CALFUEL() to calculate quantity of fuel.
 A function SHOWINFO() to display value of all the data members.
22 Consider the following class Coach :
class Coach
{
protected :
int CoachId;
public :
Coach( )
{
CoachId=0;
}
void get()
{ cin>>CoachId;
}
int getId()
{
return CoachId ;
}
};
Write a code in C++ to publically derive another class ‘player’ with the following additional members
derived in the public visibility mode.
Data Members :
 PId of type integer
 Pname of type string
 Score of type int
Member functions :
 A default constructor to initialize the data members PId by zero, Pname by NULL(\0) and Score
with 0.
 INPUT( ) : To enter PId, Pname and Score
 OUTPUT( ) : To display the data members on the screen.
23 Consider the following tables STORE and SUPPLIERS and answer part (i) and (ii) of this
question:
Table : STORE
Item No Item Scode Qty Rate LastBuy
2005 Sharpener Classic 23 60 8 31-Jun-09
2003 Ball Pen 0.25 22 50 25 01-Feb-10
2002 Gel Pen Premium 21 150 12 24-Feb-10
2006 Gel Pen Classic 21 250 20 11-Mar-09
2001 Eraser Small 22 220 6 19-Jan-09
2004 Eraser Big 22 110 8 02-Dec-09
2009 Ball Pen 0.5 21 180 18 03-Nov-09

Table : SUPPLIERS
Scode Sname
21 Premium Stationary
22 Tetra Supply
23 Soft Plastics
(i) Write SQL commands for the following statements :
1. To display detail of all the items in the store table in ascending order of Lastbuy.
2. To display Item No and Item name of those items from store table whose rate is more than 15
rupees.
3. To display the details of those items whose Supplier code(Scode) is 22 or Quantity in store
(Qty) is more than 110 from store table.
4. To display minimum rate of items for each supplier individually as per Scode from table store.

(ii) Give the output of the following SQL queries:


1. SELECT COUNT(DISTINCT Scode) FROM STORE;
2. SELECT Rate*Qty FROM STORE WHERE ItemNo = 2004;
3. SELECT Item , Sname FROM STORE S, SUPPLIER P WHERE S.Scode = P.Scode AND
ItemNo = 2006;
4. SELECT MAX(LastBuy) FROM STORE;
24 Consider the following tables Student and answer (a) and (b) parts of this question :
Table : Student
Rollno Name Age Gender Department Fee
101 Ankit 20 M Computer 700
102 Payal 23 F Hindi 400
103 Mohit 27 M Maths 900
104 Priyanka 19 F Computer 700
105 Anjali 25 F English 600
106 Sanket 29 M Hindi 400
107 Rahul 31 M Computer 700
108 Rashmi 22 F Maths 900
(a). Write SQL commands for the following statements :
(i) To display all the information about the students of Computer Department.
(ii) To display the name of male students only who are in Maths Department.
(iii) To increase the fee of all the students of computer department by 100
(iv) To display the average fee of student.
(v) To delete the record of a student whose rollno is 107
(b). Give the output of the following SQL queries:
(i) select count(*) from student where age > 24 ;
(ii) select Max(fee) from student where gender = ‘M’ ;
(iii) select name , age , department from student where fee between 700 and 900 ;
(iv) select name , age , gender from student where department in(‘Computer’ , ‘Hindi’) ;
25 Consider the following tables CLUB and COACH Write SQL queries for part (i) and find output for SQl
queries of part(ii) of this question :
Table : CLUB
CoachID CoachName Age Sports DateofApp Pay Gender
101 KUKREJA 35 KARATE 1996-03-27 1000 M
102 RAVINA 34 KARATE 1998-01-20 1200 F
103 KARAN 34 SQUASH 1998-02-19 2000 M
104 TARUN 33 BASKETBALL 1998-01-01 1500 M
105 AMIT 36 SWIMMING 1998-01-12 750 M
106 RAHUL 36 SWIMMING 1998-02-24 800 M
107 DEEPAK 39 SQUASH 1998-02-20 2200 M
108 MOHIT 39 KARATE 1998-02-22 1100 M
109 SHALINI 37 SWINMMING 1998-01-13 900 F
110 SEEMA 41 BASKETBALL 1998-02-19 1700 F
111 ABHISHEK 37 FOOTBALL 1996-02-15 1100 M

Table : COACHES
SportsPerson Gender CoachID
AJAY M 101
SEEMA F 102
VINOD M 104
TANEJA F 103
(i) Write SQL commands for the following statements :
1) To display all information about swimming coaches in the club.
2) To list the names of all coaches with their date of appointment(DateofApp) in descending order.
3) To display CoachName, Age, Gender and Bonus(15% of pay) for all the coaches.
4) To display the CoachName, SportsPerson from table CLUB and COACHES with their CoachID
(ii) Give the output of the following SQL queries:
1) SELECT COUNT(DISTINCT SPORTS) FROM CLUB;
2) SELECT MIN(AGE) FROM CLUB WHERE GENDER=’F’;
3) SELECT CoachID, CoachName FROM CLUB WHERE PAY BETWEEN 1000 AND 1500;
4) SELECT CoachName, Age, Sports, SportsPerson, Pay FROM CLUB, COACHES WHERE
CLUB.CoachID = COACHES.CoachID AND Pay>1000;

Das könnte Ihnen auch gefallen