Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 54

CHETTINAD VIDYASHRAM

R.A. PURAM., CHENNAI – 28

COMPUTER SCIENCE

OBSERVATION RECORD BOOK OF

CLASS XII

NAME :

ROLL NO.:

CLASS & SEC. : XII –


INDEX

S.NO PAGE
DATE NAME OF THE PROGRAM SIGNATURE
. NO.
To shift the even numbers to the left and odd
1 05/06/2018    
numbers to the right of an array
Mergeing of array A and B into C in descending
2 13/06/2018    
order
Sort the int array using Bubble sort and search
3 18/06/2018    
a number using binary search

4 20/06/2018 Display the alternate numbers and its row sum    

To find the maximum and minimum of each row


5 25/06/2018  
and each column in 2 D integer array
To manipulate the Library books using
6 29/06/2018  
structure
Sum and difference of two complex numbers
7 05/07/2018  
using structure
To maintain salary slip for N employees using
8 11/07/2018  
class and objects
To calculate the travel amount and discount
9 18/07/2018  
using class and object
To print the sum of all numbers, odd, and even
10 23/07/2018  
numbers using function overloading.
To print the school information using
11 27/07/2018  
inheritance
To count and display the lines, words,
12 30/07/2018 alphabets, digits, space and special characters  
using file.
Read data from a file, convert the lower case
13 03/08/2018 into upper and vice versa, store and print the  
same
14 08/08/2018 To edit a player record using binary file.  

To store and display book informations using


15 13/08/2018  
binary file

16 16/08/2018 Stack operations using character arrays    

17 21/08/2018 Queue operations using integer array    


S.NO PAGE
DATE NAME OF THE PROGRAM SIGNATURE
. NO.
Circular Queue operations using structured
18 29/08/2018    
array
To Add, Delete and Display integer values in
19 04/09/2018    
a stack using linked list
To Add, Delete and Display integer numbers
20 08/09/2018    
in a Queue using linked list

    SQL COMMANDS    

Create a table TEACHER and write SQL


1 03/10/2018 commands and record the output using    
TEACHER table
Write the SQL Commands and Record the
2 09/10/2018    
output using STUDENT and MARK tables

Write the SQL Commands and Record the


3 23/10/2018    
output using DEPT and EMPLOYEE tables

Write the SQL Commands and Record the


4 26/10/2018    
output using BOOKS and ISSUED tables

COMPUTER SCIENCE(083) - C++


RECORD PROGRAMS (2018- 19)

1.Given 2 integer arrays A[ ] and B[ ] of sizes M and N respectively. Write a function named MIX( ) which
will produce a third array named C[ ], in which the following sequence is followed.
 All even numbers of A from left to right are copied into C from left to right
 All odd numbers of A from left to right are copied into C from right to left
 All even numbers of B from left to right are copied into C from left to right
 All odd numbers of B from left to right are copied into C from right to left
A, B and C are passed as arguments to MIX( ).
Eg: A is {3,2,1,7,6,3} and B is {9,3,5,6,2,8,10} c is {2,6,6,2,8,10,5,3,9,3,7,1,3}

#include<iostream.h>
#include<conio.h>
void MIX(int a[ ],int b[ ],int c[ ],int m,int n)
{ int i,j=m+n-1,k=0;
for(i=0;i<m;i++)
{ if(a[i]%2==0)
{ c[k]=a[i];
k++;
}
else
{ c[j]=a[i];
j--;
}
}
for(i=0;i<n;i++)
{
if(b[i]%2==0)
{ c[k]=b[i];
k++;
}
else
{ c[j]=b[i];
j--;
}
}
}

void main()
{ clrscr();
int m,n,i,j,a[50], b[50],c[100];
cout<<"\nEnter the limit for Array A?\n"<<endl;
cin>>m;
cout<<"\nEnter the limit for Array B?\n"<<endl;
cin>>n;
cout<<"\nEnter the Values for Array A:\n"<<endl;
for( i=0;i<m;i++)
cin>>a[i];
cout<<"\nEnter the Values for Array B:\n"<<endl;
for(i=0;i<n;i++)
cin>>b[i];
MIX(a,b,c,m,n);
cout<<"Array C values are:";
for(i=0;i<m+n;i++)
cout<<c[i]<<"\t";
getch();
}

output:
-------
Enter the limit for Array A?
3
Enter the limit for Array B?
4
Enter the Values for Array A:
1
2
3
Enter the Values for Array B:
4
5
6
7
Array C values are:2 4 6 7 5 3 1

2. Suppose A[ ], B[ ], C[ ] are integer array of integers of size M, N and M+N respectively. The numbers in
array A and B should be arranged in ascending order using selection sort. Also write a function
MERGE( )to produce the third array C by merging arrays A and B in descending order using merge sort.
Pass the array A, B and C as arguments in the function.

#include<iostream.h>
#include<conio.h>
void SELECTION_SORT(int a[],int n)
{ int i,j,t,min;
for(i=0;i<=n;i++)
{ min=i;
for(j=i+1;j<n;j++)
if(a[j]<a[min])
min=j;

if( i!=min )
{
t=a[i];
a[i]=a[min];
a[min]=t;
}
}
}
void MERGE(int a[ ], int b[ ],int c[ ],int m,int n)
{
int k=0,i=m-1,j=n-1;
cout<<endl;
while(i>=0 && j>=0)
{
if(a[i]>=b[j])
c[k++]=a[i--];
else
c[k++]=b[j--];
}

while(i>=0)
c[k++]=a[i--];
while(j>=0)
c[k++] = b[j--];
cout<<"\n\nMERGED ARRAY ELEMENTS - DESCENDING ORDER :\n";
for(i=0;i<k;i++)
cout<<c[i]<<endl;
}

void main()
{ clrscr();
int a[20],b[20],c[40],i,m,n,j,t;
cout<<"\n\nENTER SIZE FOR ARRAY A :\t";
cin>>m;
cout<<"\n\nENTER ELEMENTS FOR ARRAY A :\n";
for(i=0;i<m;i++)
cin>>a[i];
cout<<"\n\nENTER SIZE FOR ARRAY B :\t";
cin>>n;
cout<<"\n\nENTER ELEMENTS FOR ARRAY B :\n";
for(i=0;i<n;i++)
cin>>b[i];
SELECTION_SORT(a,m);
SELECTION_SORT(b,n);
MERGE(a,b,c,m,n);
getch();
}
output:
-------
ENTER SIZE FOR ARRAY A : 4

ENTER ELEMENTS FOR ARRAY A :


3
1
4
6
ENTER SIZE FOR ARRAY B : 3

ENTER ELEMENTS FOR ARRAY B :


7
2
5

MERGED ARRAY ELEMENTS - DESCENDING ORDER :


7
6
5
4
3
2
1

3. Suppose an array P containing N integer values are arranged in ascending order using bubble sort. Write a
user defined function to search for a integer from P with the help of binary search method. The function should
return an integer 0 to show absence of the number and integer 1 to show presence of the number in the array.
The function should have 3 parameters i. an array P ii. The number DATA to be searched iii. Number of
elements N
#include<iostream.h>
#include<conio.h>
void BUBBLE_SORT(int a[],int n)
{ int i,j,t;
for(i=0 ; i<n-1 ; i++)
{
for(j=0;j<n-i-1;j++)
if(a[j]>a[j+1])
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
}

int BINARY_SEARCH(int p[ ],int n,int data)


{ int beg=0, end=n-1,mid;
while(beg<=end)
{
mid=(beg+end)/2;
if(p[mid]==data)
return (1);
else if(data>p[mid])
beg=mid+1;
else
end=mid-1;
}
return 0;
}

void main()
{
clrscr();
int p[100],n,i,t,data;
cout<<"\nEnter the size \t";
cin>>n;
cout<<"\n\nEnter the values:\n";
for(i=0;i<n;i++)
cin>>p[i];
BUBBLE_SORT(p,n);
cout<<"\n\n\t\tSORTED ELEMENTS IN ASCENDING ORDER"<<endl;
cout<<"\t\t-----------------------------------"<<endl;
for(i=0;i<n;i++)
cout<<"\t\t\t\t"<<p[i]<<"\n";
cout<<"\n\nEnter data to be searched:\t";
cin>>data;
t=BINARY_SEARCH(p,n,data);
if(t==0)
cout<<"\nNUMBER IS NOT PRESENT!!!";
else
cout<<"\nNUMBER IS PRESENT!!!";
getch();
}

output:
-------
Enter the size 7

Enter the values:


2
1
4
5
3
6
9
SORTED ELEMENTS IN ASCENDING ORDER
-----------------------------------
1
2
3
4
5
6
9

Enter data to be searched: 6


NUMBER IS PRESENT!!!

4. Write a function that accepts a 2D int array in the size of M rows, N columns and print the alternate numbers
in the given format with its row sum.
For example: If the original matrix is
1 2 3 4 5 1 3 5 Sum=9
6 7 8 9 10 output should be 7 9 Sum=16
11 12 13 14 15 11 13 15 Sum=39
16 17 18 19 20 17 19 Sum=36

#include<iostream.h>
#include<conio.h>
void Display(int a[10][10],int m,int n)
{
int i,j,sum,k=0;
for(i=0;i<m;i++)
{
sum=0;
for(j=0;j<n;j++,k++)
{
if(k%2==0)
{
cout<<a[i][j]<<" ";
sum=sum+a[i][j];
}
else
cout<<" ";
}
cout<<"\tsum:"<<sum<<endl;
}
}

void main()
{
clrscr();
int a[10][10],m,n,i,j;
cout<<"Enter the size of matrix:";
cin>>m>>n;
cout<<"Enter the values:";
for(i=0;i<m;i++)
for(j=0;j<n;j++)
cin>>a[i][j];
Display(a,m,n);
getch();
}

output:
-------
Enter the size of matrix:4
5

Enter the values:1


2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

1 3 5 sum:9
7 9 sum:16
11 13 15 sum:39

5. Write a program using function called FIND_MIN_MAX ( ) that accept a 2D int array and its size as
argument find and print the maximum and minimum of each row and each column.

#include<iostream.h>
#include<conio.h>
void FIND_MIN_MAX(int a[10][10],int m,int n)
{
int i,j,min,max;

//for each row


for(i=0;i<m;i++)
{
min=max=a[i][0];
for(j=0;j<n;j++)
{
if(a[i][j]>max)
max=a[i][j];
else if (a[i][j]<min)
min=a[i][j];
}

cout<<"\nMaximum of Row "<<i+1<<” is ”<<max<<endl;


cout<<"\nMinimum of Row "<<i+1<<” is ”<<min<<endl;
}

// for each column


for(i=0;i<n;i++)
{
min=max=a[0][i];
for(j=0;j<m;j++)
{
if(a[j][i]>max)
max=a[j][i];
else if (a[j][i]<min)
min=a[j][i];
}
cout<<"\nMaximum of Column "<<i+1<<” is ”<<max<<endl;
cout<<"\nMinimum of Column "<<i+1<<” is ”<<min<<endl;
}
}

void main()
{
clrscr();
int a[10][10],m,n,i,j;
cout<<"Enter the size of matrix:";
cin>>m>>n;
cout<<"Enter the values:";
for(i=0;i<m;i++)
for(j=0;j<n;j++)
cin>>a[i][j];
FIND_MIN_MAX(a,m,n);
getch();
}

output:
-------
Enter the size of matrix:3 3
Enter the values:
10 2 13
41 15 26
7 80 39

Maximum of Row 1 is 13

Minimum of Row 1 is 2

Maximum of Row 2 is 41

Minimum of Row 2 is 15

Maximum of Row 3 is 80

Minimum of Row 3 is 7

Maximum of Column 1 is 41

Minimum of Column 1 is 7

Maximum of Column 2 is 80

Minimum of Column 2 is 2

Maximum of Column 3 is 39

Minimum of Column 3 is 13
6. A library maintains some records with the following record structure: book number, title, author, no. of
copies and price. Write a complete program using structure and do the following
a. Input N records b. Display all the records
c. Given the author name, display the book no, title, author, no of copies and price of all books.

#include<iostream.h>
#include<string.h>
#include<stdio.h>
#include<conio.h>
struct BOOK
{
int bno,no,price;
char title[20],author[20];
};
void INPUT(BOOK b[], int n)
{
cout<<"\nEnter details for "<<n<< " records:"<<endl;
for(int i=0;i<n;i++)
{
cout<<"\nEnter the book no : ";
cin>>b[i].bno;
cout<<"\nTitle : ";
gets(b[i].title);
cout<<"\nAuthor : ";
gets(b[i].author);
cout<<"\nNo of copies : ";
cin>>b[i].no;
cout<<"\nPrice : ";
cin>>b[i].price;
}
}

void DISPLAY(BOOK b[],int n)


{
cout<<"\nBook No"<<"\tTitle"<<"\tAuthor"<<"\t No of copies"<<"\tPrice"<<endl;
cout<<"\n------------------------------------------------------------------"<<endl;
for(int i=0;i<n;i++)
cout<<"\n\n"<<b[i].bno<<"\t"<<b[i].title<<"\t"<<b[i].author<< "\t\t"<<b[i].no<<"\t"
<<b[i].price<<endl;
}
void SEARCH(BOOK b[],char auth[20],int n)
{
int flag=0;
for(int i=0;i<n;i++)
if(strcmp(auth , b[i].author)==0)
{
cout<<"\n\t\tRECORD FOUND!!!\n";
cout<<"\nBook No"<<"\tTitle"<<"\tAuthor"<<"\t No of copies" <<"\tPrice" <<endl;
cout<<"\n------------------------------------------------------------------"<<endl;
cout<<"\n\n"<<b[i].bno<<"\t"<<b[i].title<<"\t"<<b[i].author<< "\t\t"<<b[i].no <<"\t"
<<b[i].price<<endl;
flag=1;
}
if(flag==0)
cout<<"\n\n\n\t\tRECORD DOES NOT EXIST!!!\n"<<endl;
}

void main()
{
clrscr();
BOOK b[100];
char auth[20];
int n;
cout<<"\nEnter the no of records to be stored: ";
cin>>n;
INPUT(b,n);
DISPLAY(b,n);
cout<<"\n\nEnter the author name to be Searched: ";
gets(auth);
SEARCH(b,auth,n);
getch();
}

Output:
-------
Enter the no of records to be stored: 2
Enter details for 2 records:
Enter the book no : 1
Title : Miles
Author : Brown
No of copies : 3
Price : 500
Enter the book no : 2
Title : Joy
Author : John
No of copies : 5
Price : 750

Book No Title Author No of copies Price


------------------------------------------------------------------
1 Miles Brown 3 500
2 Joy John 5 750

Enter the author name to be Searched: John

RECORD FOUND!!!

Book No Title Author No of copies Price


------------------------------------------------------------------
2 Joy John 5 750
7. WAP to find the sum and difference of two complex numbers using functions SUM( ) and DIFF( ) that
accepts two complex numbers as arguments and return the result using structure.(return type of the function is
structure)
#include<iostream.h>
#include<conio.h>
struct complex
{ int real,imag;
};
complex SUM(complex c1,complex c2)
{ complex c3;
c3.real=c1.real+c2.real;
c3.imag=c1.imag+c2.imag;
return c3;
}

complex DIFF(complex c1,complex c2)


{ complex c3;
c3.real=c1.real-c2.real;
c3.imag=c1.imag-c2.imag;
return c3;
}

void main()
{ clrscr();
complex z1,z2,z3,z4;
cout<<"\n\nEnter real and imaginary part of complex no. 1 : ";
cin>>z1.real>>z1.imag;
cout<<"\n\nEnter real and imaginary part of complex no. 2 : ";
cin>>z2.real>>z2.imag;
z3=SUM(z1,z2);
cout<<"\n\nThe sum of complex no.s : ";
cout<<z3.real<<" "<<z3.imag<<"i";
z4=DIFF(z1,z2);
cout<<"\n\nThe difference of complex no.s : ";
cout<<z4.real<<" "<<z4.imag<<"i";
getch();
}
output:
-------
Enter real and imaginary part of complex no. 1 : 2 5
Enter real and imaginary part of complex no. 2 : -1 -6
The sum of complex no.s : 1 -1i
The difference of complex no.s : 3 11i

8. Write a program using class and object to simulate the salary sheet representation of N emploees. For each
employee the data members are – name, age, basic, hra, da, pf, gsal, netsal and tax. Calculate hra, da and pf as
15%, 18% and 12% on basic respectively. Calculate gross salary gsal as basic+hra+da and netsalary as gsal-
(pf+tax). Calculate the tax as follows
Basic Tax
<=10000 2% of gross salary
>10000 & <=50000 5% of gross salary
>50000 10% of gross salary

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<iomanip.h>
class EmpSal
{
char name[30];
int age;long basic;
float HRA,DA,PF;
float gsal,netsal,tax;
public:
void GetValue()
{ cout<<"\nNAME:\t";
gets(name);
cout<<"\nAGE:\t";
cin>>age;
cout<<"\nBASIC SALARY:\t";
cin>>basic;
}
void Compute()
{
HRA=0.15*basic;
DA=0.18*basic;
PF=.12*basic;
gsal=basic+HRA+DA;
if(basic<=10000)
tax=.02*gsal;
else if((basic>10000)&&(basic<=50000))
tax=.05*gsal;
else if(basic>50000)
tax=.1*gsal;
netsal=gsal-(PF+tax);
}

void PrnResult()
{
cout<<name<<" "<<age<<" "<<basic<<" "<<HRA<<" "<<DA<<" "
<<" "<<gsal<<" "<<PF<<" ";
cout<<setprecision(4)<<tax<<" ";
cout<<setprecision(4)<<netsal<<endl;
}
};
void main()
{
clrscr();
int n;
EmpSal s[20];
cout<<"\n\nENTER NUMBER OF EMPLOYEES:\t";
cin>>n;
for(int i=0;i<n;i++)
{
cout<<"\n"<<" EMPLOYEE "<<i+1<<" DETAILS : "<<"\n";
s[i].GetValue();
s[i].Compute();
}
clrscr();
cout<<"\n\t\t\tEMPLOYEE DETAILS\n";
cout<<"\t\t\t----------------\n\n\n";
cout<<"\nNAME AGE BASIC HRA DA GROSS SALARY PF TAX NET SALARY\n";
cout<<"-------------------------------------------------------\n\n\n";
for(i=0;i<n;i++)
s[i].PrnResult();
getch();
}

output:
-------
ENTER NUMBER OF EMPLOYEES: 2

EMPLOYEE 1 DETAILS :

NAME: Arjun

AGE: 19

BASIC SALARY: 8000

EMPLOYEE 2 DETAILS :

NAME: Akash

AGE: 40

BASIC SALARY: 30000

EMPLOYEE DETAILS
------------------------------

NAME AGE BASIC HRA DA GROSS SALARY PF TAX NET SALARY


--------------------------------------------------------------------------------------------------------
Arjun 19 8000 1200 1440 10640 960 212.8 9467.2002
Akash 40 30000 4500 5400 39900 3600 1995 34305

9. Define a class Travel in C++ with the following descriptions:


Private Members
TravelCode of type long
Place of type character array(string)
Season of type character array(string)
Total_fare of type float
Discount of type float
Public Members:
A constructor to assign initial values to TravelCode as 0, place as “NULL”,
Season as “General” , Total_fare = 0 , Discount = 0.
A function NewTravel() which allows user to enter TravelCode, Place, Season and
Total_fare. Calculates the Discount as per the following conditions:
Season Discount (%) on Total_fare
Diwali 10
Holi 5
Christmas 15
Summer 20
General 0
A function ShowTravel() to display all data members on screen.

#include <iostream.h>
#include<string.h>
#include <conio.h>
class Travel
{
long travelcode;
char place[30];
char season[30];
float total_fare,discount;
public:
Travel()
{
travelcode=0;
strcpy(place,NULL);
strcpy(season,"General");
total_fare=0;
discount=0;
}

void NewTravel()
{
cout<<"Enter travelcode,place,season,totalfare:";
cin>>travelcode>>place>>season>>total_fare;
if(strcmp(season,"Diwali")==0)
discount=(10.0/100.0)*total_fare;
else if(strcmp(season,"Holi")==0)
discount=(5.0/100.0)*total_fare;
else if(strcmp(season,"Christmas")==0)
discount=(15.0/100.0)*total_fare;
else if(strcmp(season,"Summer")==0)
discount=(20.0/100.0)*total_fare;
else
discount=0;
total_fare=total_fare-discount;
}
void ShowTravel()
{
cout<<"Travelcode\tPlace\tSeason\tTotalfare\n";
cout<<travelcode<<"\t\t"<<place<<"\t"<<season<<"\t"<<total_fare;
}
};

void main()
{
clrscr();
Travel t;
t.NewTravel();
t.ShowTravel();
getch();
}

output:
--------
Enter travelcode,place,season,totalfare:
101
Chennai
Diwali
3500
Travelcode Place Season Totalfare
101 Chennai Diwali 3150

10. Write definitions for two versions of an overloaded function. First version sum( ) takes an argument as size
and integer array and the function should print the sum of all the elements. Second version sum() takes three
arguments as int array, array size and a character which has the default value as ‘O’. If the passed character is
‘E’ , it prints the sum of even elements otherwise prints the sum of odd elements.

#include<iostream.h>
#include<conio.h>
#include<process.h>
void sum(int n,int a[])
{
long int s=0;
for(int i=0;i<n;i++)
s+=a[i];
cout<<"sum of all the elements:"<<s<<endl;
}

void sum(int a[],int n,char ch='O')


{
long int s=0;
if(ch=='E')
{
for(int i=0;i<n;i++)
if(a[i]%2==0)
s+=a[i];
cout<<"sum of even numbers = "<<s<<endl;
}
else
{
for(int i=0;i<n;i++)
if(a[i]%2!=0)
s+=a[i];
cout<<"sum of odd numbers = "<<s<<endl;
}
}
void main()
{
clrscr();
int a[100],n,i;
cout<<"\nEnter the Number of Elements : ";
cin>>n;
cout<<"\nEnter "<<n<<" Numbers : ";
for(i=0;i<n;i++)
cin>>a[i];

sum(n,a);
sum(a,n,'E');
sum(a,n);
getch();
}

Output

Enter the number of elements : 5


Enter 5 numbers:
1 2 3 4 5

Sum of all the elements : 15


Sum of even numbers: 6
Sum of odd numbers: 9

11. C.V. School maintains a list of its students and teachers. Write a C++ program that illustrates the
Multilevel inheritance. A class School is the base class with data members Name, Address and Mobile number
and has public member functions Readdata( ) - to input values and Printdata( ) – to display values.
School is publicly inherited by a class Student and adds the data members Enrol, Class and Group. A public
member function Readdata( ) invokes Readdata( ) of School and also accepts the Group. Function
Printdata( ) invokes Printdata( ) of School and also prints the Group of student. A function Readstudent( )
accepts Enrol, Class, Section and Printstudent( ) prints these details.
Student is publicly inherited by another class Teacher and adds the data members Date of joining and
Subject. A function Readdata( ) invokes Readdata( ) of Student and also accepts the date of joining and
subject handled. Function Printdata( ) invokes Printdata( ) of Student and prints all the details of Teacher.

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class School
{ char name[20], address[50], mobile[15];
public:
void Readdata()
{ cout<<"Name :";
gets(name);
cout<<"Address :";
gets(address);
cout<<"Mobile number :";
gets(mobile);
}

void Printdata()
{ cout<<"\nName : "<<name<<"\tAddress : "<<address<<endl;
cout<<"Mobile no : "<<mobile;
}
};

class Student: public School


{
int enrol;
char Class[5];
char sec[3],group[20];
public:

void Readdata()
{
School::Readdata();
cout<<"Group(Commerce/Science)-taken by student/handled by teacher :";
gets(group);
}

void Readstudent()
{
cout<<"Enrol :";
cin>>enrol;
cout<<"Class :";
cin>>Class;
cout<<"Section :";
cin>>sec;
}

void Printdata()
{ School::Printdata();
cout<<"\t\tGroup : "<<group<<endl;
}

void Printstudent()
{
cout<<"\nEnrol : "<<enrol<<"\tClass : "<<Class<<"\tSection : "<<sec;
}
};

class Teacher: public Student


{ char doj[15],subject[20];
public:

void Readdata()
{ Student::Readdata();
cout<<"Date of joining:";
gets(doj);
cout<<"Subject handled:";
gets(subject);
}

void Printdata()
{ Student:: Printdata();
cout<<"Date ofjoining : "<<doj<<"\tSubject taught : "<<subject<<endl;
}
};

void main()
{
clrscr();
int ch;
Student s;
Teacher t;
cout<<"\n 1. Student details \n 2. Teacher details \n Enter the choice : ";
cin>>ch;
if(ch==1)
{ s.Readdata();
s.Readstudent();
s.Printdata();
s.Printstudent();
}
else if (ch==2)
{ t.Readdata();
t.Printdata();
}
else
cout<<"\n Not a valid option";
getch();
}

OUTPUT:

1. Student details
2. Teacher details
Enter the choice:1
Name :Kirupa
Address :Adyar
Mobile number:8679864321
Group(Commerce/Science)-taken by student/handled by teacher :Science
Enrol :11201
Class :12
Section :F1

Name : Kirupa Address : Adyar


Mobile no : 8679864321 Group : Science
Enrol : 11201 Class : 12 Section : F1

12. WAP to create a text file called story.txt, store information line by line, read the same from the file and
count and print the following: No. of lines, No. of words(each word ends with blank space or ‘.’), No. of
alphabets, no of digits, no of special characters, and blank spaces. (Maximum length of the line is 80 characters)

#include<fstream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<ctype.h>
void main()
{ clrscr();
fstream x;
int li,sp,sc,word,num,dig,alp;
li=sp=sc=word=num=alp=0;
char st[80];
x.open("story.txt",ios::out);
cout<<"\n\nEnter the story to be copied in to the file"<<endl;
cout<<"---------------------------------------------"<<endl;
cout<<"\n(Enter quit to terminate)"<<endl<<endl;
gets(st);
while(strcmp(st,"quit")!=0)
{
x<<st<<endl;
gets(st);
}
x.close();
cout<<"\n\nReading the contents from the file"<<endl;
cout<<"-------------------------------------\n"<<endl;
x.open("story.txt",ios::in);

while(x.getline(st,80))
{cout<<st<<endl;
li++;
for(int i=0;i<strlen(st);i++)
{
if(isspace(st[i]) || st[i]=='.')
word++;
if(isspace(st[i]))
sp++;
else if(isalpha(st[i]))
alp++;
else if(isdigit(st[i]))
num++;
else
sc++;
}
}
x.close();
cout<<"\n\n\n Number of lines in the file : "<<li;
cout<<"\n\n\n Number of Spaces in the file : "<<sp;
cout<<"\n\n\n Number of Words in the file : "<<word;
cout<<"\n\n\n Number of Alphabets in the file : "<<alp;
cout<<"\n\n\n Number of Digits in the file : "<<num;
cout<<"\n\n\n Number of Special Characters in the file : "<<sc;
getch();
}

output:
-------
Enter the story to be copied in to the file
---------------------------------------------
(Enter quit to terminate)

In the forest lived a lion. He


had a jackal? as his partner. They
always went 2gether.

Reading the contents from the file


-------------------------------------
In the forest lived a lion. He
had a jackal? as his partner. They
always went 2gether.

Number of lines in the file : 3


Number of Spaces in the file : 14
Number of Words in the file : 17
Number of Alphabets in the file : 65
Number of Digits in the file : 1
Number of Special Characters in the file : 4

13. Write a C++ program to create a text file called school.txt, store information about c.v and then display the
file. Create another text file called newschool.txt convert uppercase letters into lowercase letters and vice versa
and store it in the new file called newschool.txt and Display the newly created file.

#include<fstream.h>
#include<conio.h>
#include<ctype.h>
#include<stdio.h>
#include<string.h>
void main()
{ clrscr();
fstream x,y;
char ch[100],c;
x.open("school.txt",ios::out);
cout<<"\n Enter Information abt your school\n"<<endl;
cout<<"\nEnter quit to terminate\n"<<endl;
gets(ch);
while(strcmp(ch,"quit")!=0)
{ x<<ch<<endl;
gets(ch);
}
x.close();
x.open("school.txt",ios::in);
cout<<"\n\n\n Reading Information from the file:\n "<<endl;
while(!x.eof())
{
x.getline(ch,100,'.');
cout<<ch<<endl;
}
x.close();
cout<<"\n\n Case Conversion\n"<<endl;
cout<<"\n---------------------\n"<<endl;
x.open("school.txt",ios::in);
y.open("newschool.txt",ios::out);
while(!x.eof())
{
x.get(c);
if(isupper(c))
c=tolower(c);
else if(islower(c))
c=toupper(c);
y.put(c);
}
x.close();
y.close();
y.open("newschool.txt",ios::in);
while(!y.eof())
{
y.getline(ch,100,'.');
cout<<ch<<endl;
}
getch(); }

output:
-------

Enter Information abt your school

Enter quit to terminate

I am STUDYING in cv. i LIKE my SCHOOL.


quit

Reading Information from the file:

I am STUDYING in cv
i LIKE my SCHOOL

Case Conversion
---------------------
i AM studying IN CV. I like MY school.

 
14.Following is the structure of each record in a binary file named player.dat.
struct player
{ int pcode;
char pna[25], game[15],coun[25];
};
Write functions for the following i. function to create a file ii. Function to search and modify the existing
player record by player code iii. Function to display all the records. (To modify, the value of the player’s
code, player name, game and country are read during the execution of the program)

#include<fstream.h>
#include<conio.h>
#include<process.h>
#include <stdio.h>
struct player
{
int pcode;
char pna[25],game[15],country[25];
}p;
void ReadRecord()
{
cout<<endl;
cout<<"\nEnter the following:\n\n";
cout<<"Player code:";
cin>>p.pcode;
cout<<"\nPlayer Name:";
gets(p.pna);
cout<<"\nGame:";
cin>>p.game;
cout<<"\nCountry:";
cin>>p.country;
}
void DispRecord()
{
cout<<"\n"<<p.pcode<<"\t\t\t"<<p.pna<<"\t\t"<<p.game<<"\t\t"<<p.country<<"\n";
}

void ReadFile()
{ char ch='y';
fstream x("player.dat",ios::out|ios::binary);
while(ch=='y')
{
ReadRecord();
x.write((char*)&p,sizeof(p));
cout<<"\nAny more Records?(y/n)\n";
cin>>ch;
}
x.close();
}

void DisplayFile()
{
fstream x("player.dat",ios::in|ios::binary);
if(!x)
cout<<"\n File Does not Exist"<<endl;
else
{
cout<<"\nDetails in the file are:"<<endl;
cout<<"\nPLAYER CODE \t\t NAME \t\t GAME \t\t COUNTRY\n"<<endl;
while(x.read((char*)&p,sizeof(p)))
DispRecord();
}
x.close();
}

void Modify()
{ int c,i=0,r=0;
fstream x("player.dat",ios::in|ios::out|ios::binary);
if(!x)
cout<<"\nFile does not exist"<<endl;
else
{ cout<<"\n\nEnter the player code to be modified:\n";
cin>>c;
while(x.read((char*)&p,sizeof(p)))
{
r++;
if(p.pcode==c)
{
i++;
cout<<"\n\nEnter the New values:\n";
ReadRecord();
x.seekp((r-1)*sizeof(p),ios::beg);
x.write((char*)&p,sizeof(p));
}
}
}
x.close();
if(i==0)
cout<<"\nRECORD DOES NOT EXIST";
else
cout<<"\nRECORD IS UPDATED!!";
}

void main()
{ clrscr();
int ch;
do
{
cout<<" \n\t\t\tMENU"<<endl;
cout<<"\n\t\t\t-----"<<endl;
cout<<"\n\n1)Accept\n\n2)Modify\n\n3)Display\n\n4)Exit\n\n";
cout<<"\n\nEnter your choice:\n";
cin>>ch;
switch(ch)
{
case 1:
ReadFile();
clrscr();
break;
case 2:
Modify();
getch();
clrscr();
break;
case 3:
DisplayFile();
getch();
clrscr();
break;
case 4:
exit(0);
break;
default:
cout<<"Enter correct choice"<<endl;
getch();
clrscr();
break;
}
}while(ch!=4);
getch();
}

output:
-------

MENU
-----
1)Accept
2)Modify
3)Display
4)Exit

Enter your choice:


1
Enter the following:
Player code:111
Player Name: Dhoni
Game: Cricket
Country: India
Any more Records?(y/n)
y
Enter the following:
Player code:222
Player Name: Ronaldo
Game: Football
Country: Portugal
Any more Records?(y/n)
n
MENU
-----
1)Accept
2)Modify
3)Display
4)Exit
Enter your choice:
3

Details in the file are:


PLAYER CODE NAME GAME COUNTRY
111 Dhoni Cricket India
222 Ronaldo Football Portugal

MENU
-----
1)Accept
2)Modify
3)Display
4)Exit
Enter your choice:
2

Enter the player code to be modified:


222

Enter the New values:


Enter the following:
Player code:333
Player Name:Viswanathan Anand
Game:Chess
Country:India
RECORD IS UPDATED!!
MENU
-----
1)Accept
2)Modify
3)Display
4)Exit
Enter your choice:
3

Details in the file are:


PLAYER CODE NAME GAME COUNTRY
111 Dhoni Cricket India
333 Viswanathan Anand Chess India

MENU
-----
1)Accept
2)Modify
3)Display
4)Exit

Enter your choice:


4

15. Following is the record structure of the binary file Books.dat.


class BOOK
{ int bcode; char title[20]; char subject[15]; float price;
public:
void InputBook( ){
cout<<”Enter book code, title, subject and price”;
cin>>bcode>>title>>subjec>>price;}
void ShowBook( ) {cout<<bcode<<” “<<title<<” “<<subject<<” “<<price<<endl;}
int RetBookCode() { return bcode; }
char *RetSubject( ) { return(subject); }
};
Using given class, write functions i. To create a file and store few records ii. Function to search records on
given subject and display all matching records iii. Function to read the objects of books from the binary file
Books.dat and display all the objects where book code is from 1001 to 1007

#include<fstream.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
class BOOK
{
int bcode;
char title[20], subject[15];
float price;
public:
void InputBook()
{cout<<"\nEnter book code, title, subject and price : \n\n";
cin>>bcode;
gets(title);
gets(subject);
cin>>price;
}

void ShowBook( )
{
cout<<"\n"<<bcode<<"\t"<<title<<"\t"<<subject<<"\t"<<price<<endl;
}
int RetBookCode( )
{
return(bcode);
}

char *RetSubject( )
{
return(subject);
}
};

void CREATE()
{
BOOK b;
fstream x("Books.dat",ios::out|ios::binary);
char ch;
do
{
b.InputBook();
x.write((char *)&b,sizeof(b));
cout<<"\nAny more book y/n?";
cin>>ch;
}while(ch=='y' ||ch =='Y');
x.close();
}

void SEARCH_DISP(char sub[15])


{
BOOK b;
int flag=0;
fstream x("Books.dat",ios::in|ios::binary);
while(x.read((char *)&b,sizeof(b)))
{
if(strcmpi(b.RetSubject(),sub)==0)
{
b.ShowBook();
flag=1;
}

}
if(flag==0)
cout<<"\nNo book with this subject"<<endl;
x.close();
}

void DISPLAY()
{
BOOK b;
int flag=0;
fstream x("Books.dat",ios::in|ios::binary);
while(x.read((char *)&b,sizeof(b)))
{
if(b.RetBookCode()>=1001 && b.RetBookCode()<=1007)
{
b.ShowBook();
flag=1;
}
}
if(flag==0)
cout<<"\nNo book within the code 1001 & 1007"<<endl;
x.close();
}

void main()
{
clrscr( );
int ch;
char sub[15];
CREATE( );
do
{
cout<<"\n1. Display Books on given subject\n2. Display books between book codes 1001 & 1007";
cout<<"\n3. Exit\n\nEnter your choice : ";
cin>>ch;
if(ch==1)
{
cout<<"\nEnter subject : ";
gets(sub);
SEARCH_DISP(sub);
}
else if(ch==2)
DISPLAY( );
else if(ch==3)
cout<<"\nSearching is over";
else
cout<<"\nEnter the right choice";
}while(ch!=3);
getch( );
}
output:
-------
Enter book code, title, subject and price :
1005
Ramayana
Religious
2000

Any more book y/n?y

Enter book code, title, subject and price :

1
Gravity
Science
300
Any more book y/n?n

1. Display Books on given subject


2. Display books between book codes 1001 & 1007
3. Exit

Enter your choice : 1

Enter subject : Science

1 Gravity Science 300

1. Display Books on given subject


2. Display books between book codes 1001 & 1007
3. Exit

Enter your choice : 2

1005 Ramayana Religious 2000

1. Display Books on given subject


2. Display books between book codes 1001 & 1007
3. Exit
Enter your choice : 3

Searching is over

16. Write a program for stack operations to store, delete and display characters using arrays.

#include<iostream.h>
#include<conio.h>
const int size=5;
class stack
{
private:
char a[size];
int top;
public:
stack()
{top=-1;}

void push(char);
void pop();
void display();

};

void stack::push(char data)


{ if(top==size-1)
cout<<"\nstack is overflow\n";
else
{
top++;
a[top]=data;
}
}

void stack::pop()
{
if(top==-1)
cout<<"\nstack is underflow\n";
else
{
char data=a[top];
cout<<"\nDeleted element is :"<<data<<endl;
top--;
}
}

void stack::display()
{
if(top==-1)
cout<<"\nstack is underflow\n";
else
{
cout<<"\nstack elements are:\n";
for(int i=top;i>=0;i--)
cout<<a[i]<<"\t";
}
}

void main()
{
clrscr();
int ch;
stack s;
while(1)
{
cout<<"\n1.push\n2.pop\n3.display\n4.exit\n";
cout<<"Enter the choice\n";
cin>>ch;
if(ch==1)
{ char data;
cout<<"Enter any character (data) to add ";
cin>>data;
s.push(data);
}
else if(ch==2)
s.pop();
else if(ch==3)
s.display();
else if(ch==4)
break;
else
cout<<"\nInvalid choice\n";
}
getch();
}

Output:

1.push
2.pop
3.display
4.exit
Enter the choice
1
Enter any character(data) to add A
1.push
2.pop
3.display
4.exit
Enter the choice
1
Enter any character(data) to add B
1.push
2.pop
3.display
4.exit
Enter the choice
1
Enter any character(data) to add C
1.push
2.pop
3.display
4.exit
Enter the choice
3
stack elements are

C B A

1.push
2.pop
3.display
4.exit
Enter the choice
2
Deleted element is :C
1.push
2.pop
3.display
4.exit
Enter the choice
3
stack elements are:
B A

17.Write a program using queue to store, delete and display integer numbers using array.

#include<iostream.h>
#include<conio.h>
#define size 5
class queue
{
private:
int a[size],rear,front;
public:
queue()
{rear=front=-1;
}

void add();
void del();
void display();
};

void queue::add()
{
if(rear==size-1)
{
cout<<"\nqueue is overflow\n";
return;
}
else if(rear==-1)
front=rear=0;
else
rear++;

int data;
cout<<"\nEnter any number (element) to be added";
cin>>data;
a[rear]=data;
cout<<"\n\nvalue is inserted!!";
}

void queue::del()
{
if(front== -1)
{
cout<<"\nqueue is underflow\n";
return;
}
cout<<"\nDeleted element is :"<<a[front]<<endl;
if(front==rear)
front=rear=-1;
else
front++;
}

void queue::display()
{
if(front==-1)
{
cout<<"\nqueue is underflow\n";
return;
}

cout<<"\nqueue elements are:\n";


for(int i=front;i<=rear;i++)
cout<<a[i]<<"\t";
}

void main()
{
clrscr();
int ch;
queue s;
while(1)
{ clrscr();
cout<<"\n1.Add\n2.Delete\n3.Display\n4.Exit\n";
cout<<"Enter the choice\n";
cin>>ch;
if(ch==1)
s.add();
else if(ch==2)
s.del();
else if(ch==3)
s.display();
else if(ch==4)
break;
else
cout<<"\nInvalid choice\n";
getch();
}

getch();
}

Output:
1.Add
2.Delete
3.Display
4.Exit
Enter the choice
1
Enter any number (element) to be added 1

1.Add
2.Delete
3.Display
4.Exit
Enter the choice
1
Enter any number (element) to be added 2
1.Add
2.Delete
3.Display
4.Exit
Enter the choice
1
Enter any number (element) to be added 3

1.Add
2.Delete
3.Display
4.Exit
Enter the choice
3
queue elements are:
1 2 3

1.Add
2.Delete
3.Display
4.Exit
Enter the choice
2
Deleted element is : 1
1.Add
2.Delete
3.Display
4.Exit
Enter the choice 3
queue elements are:
2 3

18. Write a program using circular queue operations to store, delete and display records with the following
record structure using array of structure.
struct Product
{ int pcode;
char pname[25];
float price;
};
#include<iostream.h>
#include<process.h>
#include<conio.h>
#include<stdio.h>
struct product
{ int pcode;
char pname[25];
float price;
};
const int size=3;
class cir
{
private:
product a[size];
int front,rear;
public:
cir()
{
front=-1,rear=-1;
}
void add(product);
void del();
void disp();
};
void cir::add(product val)
{
if(front==0 && rear==size-1||front==rear+1)
cout<<"\nQueue is full"<<endl;
else
{
if(rear==-1)
front=rear=0;
else if(rear==size-1)
rear=0;
else
rear++;
a[rear]=val;
cout<<"\nRecord is inserted"<<endl;
}
}

void cir::del()
{
if(front==-1)
cout<<"\nQueue is Empty"<<endl;
else
{
cout<<"\nDeleted Record : ";
cout<<a[front].pcode<<"\t"<<a[front].pname<<"\t"<<a[front].price<<endl;
if(front==rear)
front=rear=-1;
else if(front==size-1)
front=0;
else
front++;
}
}
void cir::disp()
{ int i;
if(front==-1)
cout<<"\nQueue is empty"<<endl;
else if(front<=rear)
for(i=front;i<=rear;i++)
cout<<a[i].pcode<<"\t"<<a[i].pname<<"\t"<<a[i].price<<endl;
else
{
for(i=front;i<size;i++)
cout<<a[i].pcode<<"\t"<<a[i].pname<<"\t"<<a[i].price<<endl;
for(i=0;i<=rear;i++)
cout<<a[i].pcode<<"\t"<<a[i].pname<<"\t"<<a[i].price<<endl;

}
}

void main()
{
cir c;
int ch;
product val;
clrscr();
while(1)
{
cout<<"\n\n\t\t\tCircular Queue";
cout<<"\n\t\t\t--------------"<<endl;
cout<<"\n\n\n1.Insert\n\n2.Delete\n\n3.Display\n\n4.Exit\n\nEnter your choice : ";
cin>>ch;
if(ch==1)
{
cout<<"\nEnter pcode";
cin>>val.pcode;
cout<<"\nEnter pname";
gets(val.pname);
cout<<"\nEnter the price";
cin>>val.price;
c.add(val);
getch();
}
else if(ch==2)
{c.del();
getch();
}
else if(ch==3)
{c.disp();
getch();
}
else if(ch==4)
exit(0);
else
cout<<"\nInvalid choice"<<endl;
}

Output:
-------
Circular Queue
--------------
1.Insert

2.Delete

3.Display

4.Exit

Enter pcode 101


Enter pname Hamam
Enter the 45.75
Enter your choice : 1

Enter product code, name and price 101 Hamam 45.75

Record is inserted

Circular Queue
--------------
1.Insert
2.Delete
3.Display
4.Exit
Enter your choice : 1
Enter pcode 102
Enter pname Colgate
Enter the 75.25

Record is inserted

Circular Queue
--------------
1.Insert
2.Delete
3.Display
4.Exit

Enter your choice : 3


101 Hamam 45.75
102 Colgate 75.25

Circular Queue
--------------
1.Insert
2.Delete
3.Display
4.Exit

Enter your choice : 2


Deleted Record : 101 Hamam 45.75

Circular Queue
--------------
1.Insert
2.Delete
3.Display
4.Exit
Enter your choice : 3
102 Colgate 75.25

Circular Queue
--------------
1.Insert
2.Delete
3.Display
4.Exit
Enter your choice : 2
Deleted Record : 102 Colgate 75.25

Circular Queue
--------------
1.Insert
2.Delete
3.Display
4.Exit
Enter your choice : 2
Queue is Empty

Circular Queue
--------------
1.Insert
2.Delete
3.Display
4.Exit

Enter your choice : 4

19. Write a program to Add, delete and display an integer using linked list for stack operation.

#include<iostream.h>
#include<conio.h>
struct node
{
int data;
node *next;
};
class stack
{
private:
node *top;
public:
stack()
{
top=NULL;
}
void push(int);
void pop();
void display();
};
void stack::push(int val)
{node *ptr;
ptr=new node;
ptr->data=val;
ptr->next=NULL;
if(top==NULL)
top=ptr;
else
{ ptr->next=top;
top=ptr;
}
}

void stack::pop()
{node *ptr;
ptr=top;
if(top==NULL)
cout<<"\nStack is empty\n";
else
{ cout<<"\nDeleted value is "<<top->data;
top=top->next;
delete ptr;
}
getch();
}
void stack::display()
{node *ptr;
ptr=top;
if(top==NULL)
cout<<"\nStack is empty\n";
else
{ cout<<"\nThe values are:\n";
while(ptr!=NULL)
{ cout<<ptr->data<<" ";
ptr=ptr->next;
}
}
getch();

void main()
{
clrscr();
int ch,val;
stack ob;
do
{
cout<<"\n\n\nLINKED LIST FOR STACK OPERATION\n\n";
cout<<"\n\n1.PUSH\n\n2.POP\n\n3.DISPLAY\n\n4.Exit\n";
cout<<"\nEnter your choice\n";
cin>>ch;
switch(ch)
{
case 1:
cout<<"\nEnter any value\n";
cin>>val;
ob.push(val);
clrscr();
break;
case 2:
ob.pop();
clrscr();
break;
case 3:
ob.display();
clrscr();
break;
case 4:
break;
default:
cout<<"\nInvalid choice\n";
getch();
clrscr();
}
}while(ch!=4);
}
OUTPUT:
LINKED LIST FOR STACK OPERATION
1.PUSH
2.POP
3.DISPLAY
4.Exit
Enter your choice 1

Enter any value


10
LINKED LIST FOR STACK OPERATION
1.PUSH
2.POP
3.DISPLAY
4.Exit
Enter your choice 1

Enter any value


20
LINKED LIST FOR STACK OPERATION
1.PUSH
2.POP
3.DISPLAY
4.Exiy
Enter your choice 3
The values are:
20 10

20. Write a program to store, delete, and display integer values using linked list for Queue operations.
#include<iostream.h>
#include<conio.h>
#include<process.h>
struct node
{
int data;
node *next;
};

class queue
{
private:
node *front, *rear;
public:
queue()
{
front=rear=NULL;
}
void insert();
void dele();
void display();
};

void queue::insert()
{
node *ptr;
ptr=new node;
cout<<"\nEnter any value\n";
cin>>ptr->data;
ptr->next=NULL;
if(front==NULL) // or rear
front=rear=ptr;
else
{
rear->next=ptr;
rear=ptr;
}
}

void queue::dele()
{
node *ptr;
ptr=front;
if(front==NULL)
cout<<"\nQueue is empty\n";
else
{
cout<<"\nDeleted value is "<<front->data;
if(front==rear)
front=rear=NULL;
else
front=front->next;
delete ptr;
}
getch();
}

void queue::display()
{
node *ptr;
ptr=front;
if(front==NULL)
cout<<"\nQueue is empty\n";
else
{ cout<<"\nThe values are:\n";
while(ptr!=NULL)
{
cout<<ptr->data<<" ";
ptr=ptr->next;
}
}
getch();

void main()
{
clrscr();
int ch;
queue ob;
while(1)
{
cout<<"\n\n\nLINKED LIST FOR QUEUE OPERATION\n\n";
cout<<"\n\n1.INSERT\n\n2.DELETE\n\n3.DISPLAY\n\n4.Exit\n";
cout<<"\nEnter your choice\n";
cin>>ch;
switch(ch)
{
case 1:
ob.insert();
clrscr();
break;
case 2:
ob.dele();
clrscr();
break;
case 3:
ob.display();
clrscr();
break;
case 4:
exit(0);
default:
cout<<"\nInvalid choice\n";
getch();
clrscr();
}
}
}
Output:

LINKED LIST FOR QUEUE OPERATION


1. INSERT
2. DELETE
3. DISPLAY
4. EXIT
Enter your choice
1
Enter any value
10
LINKED LIST FOR QUEUE OPERATION
1. INSERT
2. DELETE
3. DISPLAY
4. EXIT
Enter your choice
1
Enter any value
20
LINKED LIST FOR QUEUE OPERATION
1. INSERT
2. DELETE
3. DISPLAY
4. EXIT
Enter your choice
1
Enter any value
30
LINKED LIST FOR QUEUE OPERATION
1. INSERT
2. DELETE
3. DISPLAY
4. EXIT
Enter your choice
3
The values are :
10 20 30

LINKED LIST FOR QUEUE OPERATION

1. INSERT
2. DELETE
3. DISPLAY
4. EXIT
Enter your choice
2
Deleted value is 10
LINKED LIST FOR QUEUE OPERATION
1. INSERT
2. DELETE
3. DISPLAY
4. EXIT
Enter your choice
3
The values are :
20 30

SQL
SQL RECORD QUESTIONS - XII (2018-2019)

1. Write SQL commands for questions (1) to (5) and write outputs for question (6) to (8) using the given table teacher.

Table: Teacher

TID Name Department Date_of_join Salary Gender


1001 Raja Computer 21/5/98 18500 Male
1002 Sangita English 21/5/97 19000 Female
1003 Ritu Maths 29/8/98 11000 Female
1004 Kumar Computer 13/6/96 10000 Male
1005 Venkataraman Maths 31/10/99 19500 Male
1006 Sidhu Computer 21/5/86 14000 Male
1007 Aishwarya English 11/1/88 12000 Female

1. Give suitable SQL command to create the tables Teacher with the following constraints:
Attribute Date Type Constraint
TID Number primary key
Name string
Department string Not Null and default is ‘computer’
Date_of_join Date
Salary float greater than 10000
Gender Char

create table teacher (Tid number(5) primary key, name char(20), department char(20) not null
default=”computer”, date_of_join date, salary number(6,2) check salay>10000, gender char(6));

2. To list the name, date_of_join of all female teachers in ascending order of date of joining
Select name, date_of_join from teacher where gender=’Female’ order by date_of_join;

3. To list all teacher’s name and department whose name starts with “S”
Select name, department from teacher where name like ‘S%’;

4. To display the department and the number of teachers in each department


Select department, count(*) from teacher group by department;

5. To count the male and female teachers of the table


Select gender, count(*) from teacher group by gender’;

Write outputs for the following sql comands


6. Select Department, max(salary) from teacher group by Department having max(salary) >=19000;
DEPARTMENT MAX(SALARY)
English 19000
Maths 19500

7. Select avg(salary) from teacher where gender=’female’;


AVG(SALARY)
14000
8. Select count(distinct Department) from teacher;
COUNT(DISTINCT DEPARTMENT)

3
II. . Write SQL commands for questions (1) to (4) and write outputs for question (5) to (7) using the given table
STUDENT and MARK

TABLE: STUDENT
Rol Name St Gender
l d
120 Jones 10 Male
121 Radhika 11 Female
270 Harish 12 Male
274 Higgins 11 Female
279 Akbar 12 Male
301 Sanjana 10 Female
304 Rakesh 12 Male

TABLE: MARK
Rol Eng Mat Phy Che CS Total
l C
120 89 75 25 72 80 0
121 78 52 20 75 50 0
270 72 82 60 25 90 329
274 54 80 25 80 50 0
279 75 50 60 40 45 0
301 52 60 50 80 80 0
304 37 30 25 20 20 0

1. To display the name, std, gender and total of std 10 and std 12 students in ascending order of name field.
Select name, std, gender , total from student s, mark m where std in (10,12) and s.roll=m.roll order by
name;

2. To display the names ends with letter ‘a’.


Select name from student where name ‘%a”;

3. To add a new field called average with float data type in Mark table.
Alter table mark add(average number(3,2) );

4. Update the average field with average mark. Average=total/5.


Update mark set average=total/5;

Write outputs

5. Select s.roll, name, total from student s, mark m where std =11 and total >250 and s.roll= m.roll;
S.roll name total
121 Radhika 275
274 Higgins 289

6. select count(distinct std) from student;


count(distinct std)
3

7. select gender, count(*) from student group by gender;


Gender count(*)
Male 4
Female 3
III. Write SQL commands for the statements (1) to (6) and give outputs for SQL queries (7) to (8)
Table : Dept
Deptno Dept_name place
10 Sales Mumbai
20 Accounts Delhi
30 Production Kolkatta
40 Stock Chennai
Table : Employee
Empno Name Deptno desig Salary
101 Raviteja 10 Salesman 22000
102 Sam David 20 Manager 35000
103 Abdul Saleem 10 Clerk 18000
104 Ramji 30 Manager 33000
105 Santhosh 20 Salesman 24000
106 Kannan 30 Clerk 19000

1. To display the records of employees whose name starts with ‘R’ in descending order of salary.
Select * from employee where name like ‘R%’ order by salary desc;

2. To display the name, department and place of all managers.


Select name , department, place from employee where desig=’manager’;

3. To display name, department, designation and salary of all employees who are working in Delhi.
Select name, dept_name, desig, salary from employee e, dept d where place=’delhi’ and
e.deptno=d.deptno;

4. To display deptno highest and lowest salary of each department of employee table.
Select deptno, max(salary), min(salary) from employee group by deptno;

5. To add a new field called bonus with number data type with 2 decimal places in the employee table
Alter table employee add(bonus number(6,2));

6. Fill the bonus field with 70% of salary


Update employee set bonus=salary*.7;

Write outputs
7. Select deptno, sum(salary) from employee group by deptno;
Deptno sum(salary)
10 40000
20 59000
30 52000

8. Select name, dept_name, place ,salary from employee e, dept d where place not in(‘Chennai’,’Delhi’) and
e.deptno=d.deptno;

name dept_name place salary


Raviteja sales Mumbai 22000
Abdul Saleem sales Mumbai 18000
Ramji production Kolkatta 33000
Kannan Production Kolkatta 19000

IV. Write SQL commands for the statements (1) to (5) and give outputs for SQL queries (6) to (8)
Table: BOOKS

Book_Id Book_Name Author_Name Publishers Price Type Quantity


C01 Fast Cook Lata Kapoor EPB 355 Cookery 5
F01 The Tears William Hopkins First 650 Fiction 20
T01 My C++ Brain & Brooke EPB 350 Text 10
T02 C++ Brain A.W.Rossaine TDH 350 Text 15
F02 Thuderbolts Anna Roberts First 750 Fiction 50

Table: ISSUED
Book_Id Quantity_Issued
T01 4
C01 5
F01 2
C01 6
T02 3

1. To list the book names and quantity in descending order of quantity from books of Text type.
Select BOOK_name, quantity from books where type=’text’ order by quantity desc;

2. To display the names and price from books in ascending order of price.
select Book_name, price from books order by price;

3. To increase the price of all books of EPB publishers by Rs. 50.


update books set price=price+50 where publishers=’EPB’ ;

4. To display the Book Name, Quantity Issued and Price for all books of EPB publishers.
select book_name, quantity_Issued, price from books where publishers=”EPB”;

5. To display book name, price, quantity and total amount. (Total amount= price x quantity).
select book_name, price, quantity, price*quantity “Total Amount” from books ;

Write outputs
6. Select count(DISTINCT Publishers) from books;
count(DISTINCT publishers)
3

7. Select Book_Name, Author_Name,quantity_Issued from books b,Issued I where Publishers = ‘First’ AND
S.Book_Id=I.Book_id;
BOOK_Name Author_name Quantity_Issued
The Tears William Hopkins 2

8. Select type,min(Price) from books group by type;


Type min(price)
Cookery 355
Fiction 650
Text 350

*****

You might also like