You are on page 1of 55

COMPUTER

SCIENCE
(283)
PRACTICAL FILE
NAME: - PRATHAM GARG
CLASS: - XII-A
BOARD ROLL NO.:-
SESSION: - 2019-2020
SCHOOL: - GOODLEY PUBLIC SCHOOL
SUBMITTED TO: - MS SONIKA GUPTA
(PGT COMPUTER SCIENCE)
INDEX
S.NO PROGRAM LISTING SIGNATURE
1. To check no. is palindrome
2. Count no. of vowels in a line
3. Equality of two matrices
4. Function overloading
5. Display details of student
(using class)
6. Converting each line of first
file in uppercase into
another file
7. Appending information of a
file
8. Enter and display
information in a file
9. Sort array by bubble sort and
search by linear search
10. Sort array by selection sort
and search by binary search
11. Merging sorted array
12. Find largest and smallest
element in array
13. Insertion, deletion,
transversal in linked list
14. Addition, deletion in stack
using arrays
15. Addition, deletion in stack
using linked list
16. Addition, deletion in queue
in arrays
17. Addition, deletion in queue
using linked list
18. Addition, transversal in stack
using linked list (menu
based)
19. Addition, transversal in
queue using linked list (menu
based)
20. Insertion, deletion in circular
queue
21. SQL Queries
C++
CODING
/*QUES 1:- PROGRAM TO CHECK WHETHER THE GIVEN NO. IS
PALINDROME OR NOT*/

CODING:-
#include<iostream.h>
#include<conio.h>
void main()
{ int a,no,b;
char ch;
clrscr();
do
{ int temp=0;
cout<<"Enter any no. = ";
cin>>no;
b=no;
for(;no>0;)
{ a=no%10;
temp=temp*10+a;
}
if(temp==b)
{ cout<<"Palindrome"<<endl; }
else
{ cout<<"not Palindrome"<<endl; }
cout<<"do you want to continue(y,n) = ";
cin>>ch;
}while(ch=='Y'||ch=='y');
getch();
}
OUTPUT:-
/*QUES 2:- PROGRAM TO FIND NO. OF VOWELS IN A GIVEN LINE OF
TEXT*/

CODING:-
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
void main()
{
char str[50];
int vowels = 0, i = 0;
clrscr();
cout<<"enter the string = ";
gets(str);
while(str[i] != '\0')
{
if(str[i]=='A' || str[i]=='a' || str[i]=='E' || str[i]=='e' || str[i]=='I' ||
str[i]=='i' ||str[i]=='O' || str[i]=='o' || str[i]=='U' || str[i]=='u')
vowels++;
i++;
}
cout<<endl<<"the total no. of vowels in a given line of text is <<vowels;
getch();
}

OUTPUT:-
/*QUES 3:- PROGRAM TO CHECK EQUALITY OF TWO MATRICES*/

CODING:-
#include<iostream.h>
#include<conio.h>
void main()
{ clrscr();
int k=3;
int a[20][20],b[20][20];
cout<<" matrix A "<<endl;
cout<<"enter first matrix row wise \n";
for(int r=0;r<3;++r)
{ for(int q=0;q<3;++q)
{ cin>>a[r][q]; }
}
gotoxy(40,1);
cout<<"matrix B "<<endl;
gotoxy(35,2);
cout<<"enter second matrix row wise \n";
gotoxy(35,3);
for(r=0;r<3;++r)
{ for(int q=0;q<3;++q)
{ gotoxy(35,k++);
cin>>b[r][q];
}
cout<<endl;
}
int flag=0;
for(int c=0;c<3;++c)
{ for(int o=0;o<3;++o)
{ if(a[c][o]!=b[c][o])
{ flag=1;
break;
}
}
if(flag==1)
break;
}
gotoxy(40,50);
if(flag==1)
cout<<"matrices are not equal";
else if(flag==0)
cout<<"matrices are equal";
getch ();
}
OUTPUT:-
/*QUES 4:- PROGRAM TO ILLUSTRATE THE CONCEPT OF FUNCTION
OVERLOADING*/

CODING:-
#include<iostream.h>
#include<stdlib.h>
#include<conio.h>
#define pi 3.14
class fn
{ public:
void area(int); //circle
void area(int,int); //rectangle
void area(float ,int,int); //triangle
};
void fn::area(int a)
{ cout<<"Area of Circle:"<<pi*a*a; }
void fn::area(int a,int b)
{ cout<<"Area of rectangle:"<<a*b; }
void fn::area(float t,int a,int b)
{ cout<<"Area of triangle:"<<t*a*b; }
void main()
{ int ch;
char k;
int a,b,r;
fn obj;
cout<<"\n\t\tFunction Overloading";
cout<<"\n1.Area of Circle\n2.Area of Rectangle\n3.Area of Triangle\n4.Exit\n";
do{
cout<<"Enter your Choice:";
cin>>ch;
switch(ch)
{ case 1:
cout<<"Enter Radius of the Circle:";
cin>>r;
obj.area(r);
break;
case 2:
cout<<"Enter l&b of the Rectangle:";
cin>>a>>b;
obj.area(a,b);
break;
case 3:
cout<<"Enter base & height of the Triangle:";
cin>>a>>b;
obj.area(0.5,a,b);
break;
case 4:
exit(0);
}
cout<<endl<<"do you want to continue(y/n)= ";
cin>>k;
}while(k=='Y'||k=='y');
getch();
}

OUTPUT:-
/*QUES 5:- PROGRAM (USING CLASS) TO HOLD DETAILS OF 10
STUDENTS AND PROVIDE THE FACILITY OF DISPLAYING DETAILS OF
THE TOPPER AS WELL AS OF SPECIFIC STUDENT BY PROVIDING HIS OR
HER ROLLNO.*/

CODING:-
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class student
{ private:
int rollno;
char name[26];
float marks;
public:
void readstudent()
{ cout<<"\nEnter rollno : ";cin>>rollno;
cout<<"Enter name : "; gets(name);
cout<<"Enter marks : ";cin>>marks;
}
void dispstudent()
{ cout<<"roll no. : "<<rollno<<endl;
cout<<"name : "<<name<<endl;
cout<<"marks : "<<marks<<endl;
}
int getrollno()
{ return rollno; }
float getmarks()
{ return marks; }
};
void main()
{ clrscr();
int n;
student details[10];
cout<<"To add details of how much student(b/w 1 to 10) = ";
cin>>n;
for(int i=0;i<n;i++)
{ cout<<"\nEnter details of student "<<i+1<<":";
details[i].readstudent(); }
int choice,rno,pos=-1,highmarks=0;
cout<<"\n\n Main Menu\n";
cout<<"1.Specific Student\n";
cout<<"2.Topper\n";
cout<<"3.Exit \n";
do{
cout<<"\n Enter your choice(1..3) : ";
cin>>choice;
switch(choice)
{ case 1:cout<<"\n Enter roll no of student : ";
cin>>rno;
for(i=0;i<n;++i)
{ if(details[i].getrollno()==rno)
{ details[i].dispstudent();
break; }
}
if(i==10)
cout<<"\n INVALID rollno!!!\n";
break;
case 2: for(i=0;i<n;++i)
{ if(details[i].getmarks()>highmarks)
{ pos=i;
highmarks=details[i].getmarks(); }
}
details[pos].dispstudent();
break;
case 3:break;
default:cout<<"\n wrong choice!!\n";
break;
}
} while(choice>=1&&choice<3);
getch();
}
OUTPUT :-
/*QUES 6:- PROGRAM TO CONVERT EACH LINE OF FIRST FILE INTO
ANOTHER*/

CODING:-
#include<iostream.h>

#include<conio.h>

#include<fstream.h>

#include<ctype.h>

#include<stdio.h>

class abc

{ char c[20];

public:

void enter()

{ cout<<"enter text : ";

cin>>c;

void display()

{ cout<<"new text is: "<<c;}

}a;

void main()

{ char c[20];

clrscr();

ifstream fin("old.txt",ios::in);
ofstream fout("new.txt",ios::out);

while(!fin.eof())

{ a.enter();

for(int i=0;i!='\0';i++)

{ if(islower(c[i]))

c=toupper(c[i]);

fout<<c[i]; }

a.display();

break;

fin.close();

fout.close();

OUTPUT:-
/*QUES 7:- PROGRAM THAT APPEND INFORMATION TO THE FILE AND
ALSO DISPLAY ITS CONTENT*/

CODING:-
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
class abc
{ int x,y,z,result;
public:
void data()
{ cout<<"x="; cin>>x;
cout<<"y="; cin>>y; }
void sum()
{ cout<<"result obtained is(x+y)="<<x+y; }
}obj;
void main()
{ ofstream fout("add.dat",ios::app); char ans='y';
while(ans=='y')
{ obj.data();
fout.write((char*)&obj,sizeof(obj));
obj.sum();
cout<<"\nrecord added to the file. "<<endl;
cout<<"\nwant to continue (y/n) "; cin>>ans;
}
fout.close(); getch();
}
OUTPUT :-
/*QUES 8:- PROGRAM TO ENTER STUDEN NAME, ADMISSION NO.,
PERCENTAGE INTO A FILE STUDENT.DAT AND DISPLAY INFORMATION
OF THOSE STUDENTS WHOSE PERCENTAGE IS ABOVE 75*/

CODING:-
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<stdio.h>
class student
{ char name[20];
int admno;
int percent;
public:
void getdata()
{ cout<<"student ";
cout<<"\tenter name : ";
gets(name);
cout<<"\t\tenter admission no. :";
cin>>admno;
cout<<"\t\tenter percentage : ";
cin>>percent;
}
void display()
{cout<<"name : "<<name<<"admission no. : “<<admno<<”percentage:”<<percent;
cout<<endl; }
float get()
{ return percent; }
};
void main()
{ clrscr();
student s[50];
int ch; char k;
fstream f;
f.open("student.dat",ios::in|ios::out|ios::binary);
do{ cout<<"to add details of how many students : ";
cin>>ch;
cout<<"enter details of student : "<<endl;
for(int i=0;i<ch;i++)
{ s[i].getdata();
f.write((char*)&s[i],sizeof(s[i])); }
cout<<"details of student having %age greater than 75 \n";
for(i=0;i<ch;i++)
{ f.read((char*)&s[i],sizeof(s[i]));
if(s[i].get()>75)
s[i].display();
else cout<<"......no student have %age greater than 75......";
}
cout<<"\n\ndo you want to continue(y/n) ";
cin>>k; cout<<endl;
}while(k=='y'||k=='Y');
f.close();
getch();
}

OUTPUT :-
/*QUES 9:- PROGRAM TO SORT AN ARRAY USING BUBBLE SORT AND
SEARCH AN ELEMENT USING LINEAR SEARCH*/

CODING:-
#include<iostream.h>
#include<conio.h>
int Lsearch(int[], int, int);
void BubbleSort(int[], int);
void main()
{ char choice;
clrscr();
int Abc[50],element, N, index;
cout<<endl<<"Enter desired array size(max. 50) " ;
cin>>N;
cout<<endl<<"Enter Array elements: "<<endl;
for(int i=0;i<N;i++)
cin>>Abc[i];
int ch;
do{ cout<<"DO U WANT (1)Linear search or (2)Bubble Sort? "; cin>>ch;
switch(ch)
{ case 1: cout<<endl<<"--------------linear search--------------"<<endl;
cout<<"Enter element to be searched for..";
cin>>element;
index=Lsearch(Abc,N,element);
if(index==-1)
cout<<endl<<"Sorry!! Element not found"<<endl;
else
cout<<"Element found at Position: "<<index+1<<endl;
break;
case 2: cout<<endl<<"--------------bubble sort--------------"<<endl;
BubbleSort(Abc,N);
cout<<"The Sorted array is as shown below.."<<endl;
for(i=0;i<N;i++)
cout<<Abc[i]<<" " ;
break;
}
cout<<endl<<"do you want to continue ? (Y/N)";
cin>>choice;
}while(choice=='Y'||choice=='y');
getch();
}
int Lsearch(int Abc[],int size, int element)
{ for(int i=0; i<size; i++)
{ if(Abc[i]==element)
return i; }
return -1;
}
void BubbleSort(int Abc[], int size)
{ int tmp;
for(int i=0; i<size; i++)
{ for(int j=0; j<(size-1);j++)
{ if(Abc[j]>Abc[j+1])
{ tmp=Abc[j];
Abc[j]=Abc[j+1];
Abc[j+1]=tmp;
}
}
}
}
OUTPUT :-
/*QUES 10:- PROGRAM TO SORT AN ARRAY USING SELECTION SORT
AND SEARCH AN ELEMENT USING BINARY SEARCH*/

CODING:-
#include<iostream.h>
#include<conio.h>
int Bsearch(int[], int, int);
void SelSort(int[], int);
void main()
{ char choice;
do { clrscr();
int AR[50],ITEM, N, index;
cout<<endl<<"Enter array size(max. 50) " ;
cin>>N;
cout<<endl<<"Enter Array elements : "<<endl;
cout<<"Enter Element no "<<endl;
for(int i=0;i<N;i++)
cin>>AR[i];
int ch;
cout<<endl<<"do you want Binary search(1) or Selection Sort(2)? "<<endl;
cin>>ch;
if (ch==1)
goto BinarySearch;
else if (ch==2)
goto SelSort;
BinarySearch:
{ cout<<"..............binary search..............";
SelSort(AR,N); //Array must be sorted so as to do binary search
cout<<"enter array elements: "<<endl;
for(i=0;i<N;i++)
cout<<AR[i]<<" " ;
cout<<endl<<"Enter element to be searched for ";
cin>>ITEM;
index=Bsearch(AR,N,ITEM);
if(index==-1)
cout<<endl<<"Sorry!! Given element not found"<<endl;
else
cout<<endl<<"Element found at Position: "<<index+1<<endl;
goto EndProgram;
}
SelSort:
{ cout<<"..............selection sort..............";
SelSort(AR,N);
cout<<"The Sorted array is as shown below "<<endl;
for(i=0;i<N;i++)
cout<<AR[i]<<" " ;
goto EndProgram; }
EndProgram:
cout<<endl<<"do you want to continue?(Y/N) ";
cin>>choice;
}while(choice=='Y'||choice=='y');
}
int Bsearch(int AR[],int size, int item)
{ int beg=0, last=size-1, mid;
while(beg<=last)
{ mid=(beg+last)/2;
if(item==AR[mid])
return mid;
else if (item>AR[mid])
beg=mid+1;
else
last=mid-1;
}
return -1;
}
void SelSort(int AR[], int size)
{ int small, pos, tmp;
for(int i=0; i<(size-1); i++)
{ small=AR[i];
pos=i;
for(int j=i+1;j<size; j++)
{ if(AR[j]<small)
{ small=AR[i];
pos=j;
}
}
tmp=AR[i];
AR[i]=AR[pos];
AR[pos]=tmp;
}
}
OUTPUT:-
/*QUES 11:- PROGRAM TO MERGE THE CONTENT OF TWO SORTED
ARRAYS*/

CODING:-
#include<iostream.h>
#include<conio.h>
void merge(int arr1[], int arr2[], int arr3[], int len1, int len2)
{ int p,q,k,a;
for(p=0, q=a, k=0;p<len1&&q>=0;)
{ if(arr1[p]<=arr2[q])
arr3[k++] = arr1[p++];
else
arr3[k++] = arr2[q--];
}
if(p<len1)
{ while(p<len1)
arr3[k++] = arr1[p++]; }
else
{ while(q>=0)
arr3[k++] = arr2[q--]; }
}
void main()
{ int arr1[50], arr2[50],arr3[100],a=0, len1, len2;
cout<<"enter length of first array ";
cin>>len1;
cout<<"\nenter length of second array ";
cin>>len2;
a=len1+len2;
cout<<"\nenter sorted values for first array(asc.) \n";
for(int i=0;i<len1;i++)
{ cin>>arr1[i]; }
cout<<"enter sorted values for second array(desc.) \n";
for(int j=0;j<len2;j++)
{ cin>>arr2[j]; }
merge(arr1, arr2, arr3, len1, len2);
cout<<"\nmerged array is:- \n";
for(i=0;i<a;i++)
cout<<arr3[i]<<" ";
getch();
}

OUTPUT:-
/*QUES12:- PROGRAM TO FIND THE LARGEST AND SMALLEST
ELEMENT IN AN ARRAY*/

CODING:-
#include<iostream.h>
#include<conio.h>
#include<dos.h>
#define align gotoxy(30,10);
void BubbleSort(int[], int);
void main()
{ char choice;
do{ align;
cout<<endl<<"P12. Program to Find the largest and the smallest number of a
given array."<<endl;
delay(2500);
clrscr();
align;
int AR[50],ITEM, N, index;
cout<<endl<<"Enter desired array size(max. 50) " ;
cin>>N;
cout<<endl<<"Enter Array elements: "<<endl;
for (int i=0; i<N; i++)
{ cout<<endl<<"Enter Element no "<<i+1<<endl;
cin>>AR[i];}
cout<<endl<<"We begin to bubble sort your data. Please wait!"<<endl;
delay(2000);
BubbleSort(AR,N);
cout<<"The Sorted array in ascending order is as shown below.."<<endl;
for(i=0;i<N;i++)
cout<<AR[i]<<" " ;
delay(1000);
cout<<endl<<" The largest element of the array is "<<AR[N-1];
cout<<endl<<" The smallest element of the array is "<<AR[0];
delay(2000);
cout<<endl<<"Would you like to repeat the program? (Y/N)";
cin>>choice;
}while(choice=='Y'||choice=='y');
cout<<endl<<"Thank You for using C++ !"<<endl;
cout<<endl<<"The Program is about to shut...";
delay(2500);
}
void BubbleSort(int AR[], int size)
{ int tmp;
for(int i=0; i<size; i++)
{ for(int j=0; j<(size-1);j++)
{ if(AR[j]>AR[j+1])
{ tmp=AR[j];
AR[j]=AR[j+1];
AR[j+1]=tmp;
}
}
}
}

OUTPUT:-
/*QUES 13:- PROGRAM TO PERFORM INSERTION, DELETION AND
TRANSVERSAL IN SINGLE LINKED LIST*/

CODING:-
#include<iostream.h>
#include<conio.h>
struct Node { int info;
Node *next;
} *start,*newptr,*save,*ptr,*rear;
Node * Create_New_Node(int);
void Insert(Node*);
void Display(Node*);
void DelNode();
void main()
{ char choice;
do{ start=rear=NULL;
int inf;
char ch='y';
while (ch=='y'||ch=='Y')
{ cout<<endl<<"Enter data for the new node ";
cin>>inf;
newptr= Create_New_Node(inf);
if(newptr==NULL)
{ goto label; }
Insert(newptr);
cout<<endl<<"Press Y to enter more nodes, N to exit "; cin>>ch;
}
do{ cout<<endl<<" the list is : ";
Display(start);
cout<<endl<<"Want to delete first node? (y/n) ";
cin>>ch;
if (ch=='y'||ch=='Y')
DelNode();
} while (ch=='y'||ch=='Y') ;
}while(choice=='Y'||choice=='y');
label:
}
Node*Create_New_Node(int n)
{ ptr= new Node;
ptr->info=n;
ptr-> next=NULL;
return ptr;
}
void Insert(Node*np)
{ if(start==NULL)
start=rear=np;
else
{ rear->next=np;
rear=np; }
}
void DelNode()
{ if(start==NULL)
cout<<endl<<"UNDERFLOW!!!"<<endl;
else
{ ptr=start;
start=start->next;
delete ptr; }
}
void Display(Node*np)
{ while(np!=NULL)
{ cout<<np->info<<" -> ";
np=np->next;
}
}
OUTPUT:-
/*QUES14:- PROGRAM TO PERFORM ADDITION AND DELETION IN A
STACK USING ARRAY*/

CODING:-
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#define n 20
#include<process.h>
class stack
{ int rollno[n];
char admno[n];
int top;
public:
stack()
{ top=-1; }
void insertion(int x, int y)
{ if( top == n-1)
cout<<"\nOVERFLOW ";
else
{ top++;
rollno[top] = x;
admno[top] = y; }
}
void deletion()
{ if(top==-1)
cout<<"\nUNDERFLOW ";
else
{ cout<<"\nDeleted data is.....";
cout<<"\nRoll number:"<<rollno[top];
cout<<"\nAdmission number:"<<admno[top];
top--; }
}
};
void main()
{ clrscr();
stack s;
char ch='y';
int c, v, w, x, y;
do
{ cout<<"\nEnter 1 for insertion";
cout<<"\nEnter 2 to deletion";
cout<<"\nEnter 3 to exit";
cout<<"\nEnter choise:";
cin>>c;
switch(c)
{ case 1 : cout<<"\nEnter roll number:"; cin>>v;
cout<<"Enter admission number:"; cin>>w;
s.insertion(v,w);
break;
case 2 : s.deletion();break;
case 3 : exit(0);break;
default : cout<<"\n ERROR ";
}
cout<<"\ndo you want to continue? ";
cin>>ch;
}while(ch=='y' || ch=='Y');
getch();
}
OUTPUT:-
/*QUES 15:- PROGRAM TO PERFORM ADDITION AND DELETION IN
STACK USING LINKED LIST*/

CODING:-
#include<iostream.h>
#include<conio.h>
#include<process.h>
#include<stdio.h>
struct node
{ int rollno;
char n;
ame[30];
node *next;
}*top;
void insertion()
{ node *temp;
temp= new node;
cout<<"\nEnter roll number:";
cin>>temp->rollno;
cout<<"Enter name:";
gets(temp->name);
temp->next=NULL;
if(top==NULL)
top=temp;
else{ temp->next=top;
top=temp; }
}
void deletion()
{ node *temp;
if(top==NULL)
cout<<"\n.......... UNDERFLOW............";
else { temp = top;
top = top->next;
cout<<"\nDeleted data is.....";
cout<<"\nRoll number:"<<temp->rollno;
cout<<"\nName:";
puts(temp->name); }
delete temp;
}
void main()
{ clrscr();
top=NULL;
char ch='y';
int c;
cout<<"\nEnter 1 for insertion";
cout<<"\nEnter 2 to deletion";
cout<<"\nEnter 3 to exit";
do{ cout<<"\nEnter choice:";
cin>>c;
switch(c)
{ case 1 : insertion();break;
case 2 : deletion();break;
case 3 : exit(0);break;
default : cout<<"\n.......ERROR.......";
}
cout<<"\ndo you want to continue? ";
cin>>ch;
}while(ch=='y' || ch=='Y');
getch();
}
OUTPUT:-
/*QUES 16:- PROGRAM TO PERFORM ADDITION AND DELETION IN
QUEUE IN ARRAY*/

CODING:-
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
#define n 20
class Queue
{ int rollno[n];
int admno[n];
int rear, front;
public: Queue()
{ rear = front = -1; }
void insertion(int x, int y)
{ if(rear==n-1)
cout<<"\n......OVERFLOW.......";
else if(front==-1)
{ front = rear = 0;
rollno[rear] = x;
admno[rear] = y;
rear = rear+1; }
else { rollno[rear] = x;
admno[rear] = y;
rear = rear + 1; }
}
void deletion()
{ if((front==-1) || (rear==front))
cout<<"\n.....UNDERFLOW.....";
else { int x = rollno[front];
int y = admno[front];
front = front + 1;
cout<<"\nDeleted data is....";
cout<<"\nRoll number: "<<x;
cout<<"\nAdmission number: "<<y;
} } };
void main()
{ clrscr();
Queue q;
int c, v, w, x, y;
char ch='y';
cout<<"\nEnter 1 for insertion";
cout<<"\nEnter 2 for deletion";
cout<<"\nEnter 3 to exit";
do{ cout<<"\nEnter choice: "; cin>>c;
switch(c)
{ case 1 : cout<<"\nEnter roll number: "; cin>>v;
cout<<"Enter admission number: "; cin>>w;
q.insertion(v,w);
break;
case 2 : q.deletion(); break;
case 3 : exit(0);
default : cout<<"\n......ERROR......"; break;
}
cout<<"\nDo you want to continue? ";
cin>>ch;
}while(ch=='y' || ch=='Y');
getch();
}
OUTPUT:-
/*QUES 17:- PROGRAM TO PERFORM ADDITION AND DELETION IN
QUEUE USING LINKED LIST*/

CODING:-
#include<iostream.h>
#include<process.h>
#include<conio.h>
#include<stdio.h>
struct node
{ int rollno;
char name[20];
node *next;
}*rear, *front;
void insertion()
{ node *temp;
temp= new node;
cout<<"Enter id=";
cin>>temp ->rollno;
cout<<"Enter name=";
gets(temp->name);temp->next=NULL;
if(front == NULL)
rear=front=temp;
else
{ rear->next=temp;
rear=temp; }
}
void deletion()
{ node *temp;
if(front==NULL)
cout<<"\n......UNDERFLOW......";
else
{ temp=front;
front=front->next;
cout<<"Deleted data is..."<<endl;
cout<<"id no:"<<temp->rollno;
cout<<"\nName:";
puts(temp->name); }
delete temp;
}
void main()
{ clrscr();
front=rear=NULL;
char ch='y';
int c;
cout<<"Enter 1 for insertion of new node";
cout<<"\nEnter 2 for deletion of node";
cout<<"\nEnter 3 to exit";
do{ cout<<"\nEnter choice:";
cin>>c;
switch(c)
{ case 1 : insertion();break;
case 2 : deletion();break;
case 3 : exit(0); break;
default : cout<<"......ERROR......";break;
}
cout<<"\ndo you want to continue?";
cin>>ch;
}while(ch=='y' || ch=='Y');
getch();
}
OUTPUT:-
/*QUES18:- PROGRAM TO PERFORM ADDITION AND TRANSVERSAL IN
A STACK USING LINKED LIST*/

CODING:-
#include<iostream.h>

#include<conio.h>

#include<process.h>

#include<stdio.h>

struct node

{ int bno;

char bname[30];

node *next;

}*top;

void insertion()

{ node *temp;

temp= new node;

cout<<"\nEnter book number:";

cin>>temp->bno;

cout<<"Enter book name:";

gets(temp->bname);

temp->next=NULL;

if(top==NULL)

top=temp;
else { temp->next=top;

top=temp; }

void display()

{ node *temp;

temp=top;

if(top==NULL)

cout<<"\n................NO DATA TO DISPLAY...............";

else { while(temp!=NULL)

{ cout<<"\nBook number:"<<temp->bno;

cout<<"\nbook name:";

puts(temp->bname);

temp=temp->next; } }

void main()

{ clrscr();

top=NULL;

char ch='y';

int c;

do{ cout<<"\nEnter 1 for insertion";

cout<<"\nEnter 2 to display";

cout<<"\nEnter 3 to exit";
cout<<"\nEnter choise:";

cin>>c;

switch(c)

{ case 1 : insertion();break;

case 2 : display();break;

case 3 : exit(0);break;

default : cout<<"\n.......................ERROR................."; }

cout<<"\ndo you want to continue?";

cin>>ch;

}while(ch=='y' || ch=='Y');

getch();

OUTPUT:-
/*QUES19:- PROGRAM TO PERFORM ADDITION AND TRANSVERSAL IN
A QUEUE USING LINKED LIST*/

CODING:-
#include<iostream.h>

#include<conio.h>

#include<process.h>

#include<stdio.h>

struct node

{ int pid;

char pname[30];

node *next;

} *front, *rear;

void insertion()

{ node *temp;

temp=new node;

cout<<"\nEnter product ID:";

cin>>temp->pid;

cout<<"Enter product name:";

gets(temp->pname);

temp->next=NULL;

if(front==NULL)

rear=front=temp;
else { rear->next=temp;

rear=temp; }

void display()

{ node *temp;

temp=front;

if(front==NULL)

cout<<"\n......................NO DATA TO DISPLAY.................";

else { while(temp!=NULL)

{ cout<<"\nProduct ID:"<<temp->pid;

cout<<"\nProduct name:";

puts(temp->pname);

temp=temp->next; } }

void main()

{ clrscr();

front=rear=NULL;

char ch='y';

int c;

do{ cout<<"\nEnter 1 for insertion";

cout<<"\nEnter 2 to display";

cout<<"\nEnter 3 to exit";
cout<<"\nEnter choise:";

cin>>c;

switch(c)

{ case 1 : insertion(); break;

case 2 : display(); break;

case 3 : exit(0); break;

default : cout<<"\n.....................ERROR..................."; }

cout<<"\nDo you want to continue?";

cin>>ch;

}while(ch=='y' || ch=='Y');

getch();

OUTPUT:-
/*QUES 20:- PROGRAM TO INSERT AND DELETE ELEMENT IN A
CIRCULAR QUEUE*/

CODING:-
#include<iostream.h>
#include<stdlib.h>
#include<conio.h>
int Insert(int[], int);
void Display(int[], int, int);
int Del(int CQueue[]);”
const int size=7;
int CQueue[size],f=-1,r=-1;
void main()
{ int Item, res, h;
clrscr();
cout<<"\t........circular queue menu........\n";
cout<<"\t\t 1. Insert\n";
cout<<"\t\t 2. Delete\n";
cout<<"\t\t 3. Display\n";
cout<<"\t\t 4. Exit\n";
do{ cout <<"\nEnter your Choice: "; cin>>ch;
switch(ch)
{ case 1: cout<<" Enter ITEM for insertion: ";
cin>>Item;
res=Insert(CQueue,Item);
if(res==1)
cout<<endl<<"OVERFLOW!!!"<<endl;
else { Display(CQueue,f,r); }
break;
case 2: Item=Del(CQueue);
cout<<"element deleted is: "<<Item<<endl;
if(Item==-1)
cout<<" No element to be deleted"<<endl;
Display(CQueue,f,r);
break;
case 3: Display(CQueue,f,r);
break;
case 4: break;
default: cout<<"Wrong choice \n";
break;
}
}while(ch!=4);
}
int Insert(int CQueue[],int ele)
{ if ((f==0&&r==size-1)||(f==r+1))
return -1;
else if (r==-1) f=r=0;
else if (r==size-1) r=0;
else r++;
CQueue[r]=ele;
}
void Display(int CQueue[],int f,int r)
{ int i=0;
cout<<"Cir_Queue is : ";
if (f==-1) return;
if (r>=f)
{ for(i=0;i<f;i++)
cout<<" - ";
cout<<" >>> ";
for(i=f;i<r;i++)
cout<<CQueue[i]<<" <- ";
cout<<CQueue[r]<<" <<< "<<endl; }
else { for(i=0;i<r;i++)
cout<<CQueue[i]<<" <- ";
cout<<CQueue[r]<<" <<< ";
for(;i<f;i++) cout<<" - "; cout<<" >>> ";
for(i=f;i<size;i++)
cout<<CQueue[i]<<" <- ";
cout<<"\t..wrap around..";
}
}
int Del(int CQueue[])
{ int ret;
if (f==-1) return -1;
else { ret=CQueue[f];
if(f==r) f=r=-1;
else if (f==size-1) f=0;
else f++;
}
return ret;
}
OUTPUT:-
SQL
QUERIES
QUERY 1:- COMMAND TO SEE THE LIST OF DATABASES

QUERY 2:- COMMAND TO CREATE DATABASE

QUERY 3:- COMMAND TO CREATE A TABLE

QUERY 4:- COMMAND TO INSERT VALUES IN A TABLE


QUERY 5:- COMMAND TO SEE TABLE STRUCTURE

QUERY 6:- COMMAND TO SEE TABLE WITH VALUES

QUERY 7:- COMMAND TO SEE THE LIST OF TABLES

QUERY 8:- COMMAND TO USE WHERE CLAUSE


QUERY 9:- COMMAND TO USE BETWEEN CLAUSE

QUERY 10:- COMMAND BASED ON PATTERN MATCHING

QUERY 11:- COMMAND TO USE ORDER BY CLAUSE

QUERY 12:- COMMAND TO USE ALGEBRAIC FUNCTIONS


QUERY 13:- COMMAND TO USE BUILT-IN FUNCTIONS

QUERY 14:- COMMAND TO USE HAVING CLAUSE

QUERY 15:- COMMAND TO USE GROUP BY CLAUSE


QUERY 16:- COMMAND TO PUT TEXT IN QUERY OUTPUT

QUERY 17:- COMMAND TO UPDATE THE RECORDS

QUERY 18:- COMMAND TO CREATE VIEW TABLE

QUERY 19:- COMMAND TO SEE THE VIEW TABLE


QUERY 20:- COMMAND TO JOIN TWO TABLES

QUERY 21:- COMMAND TO USE UNION

QUERY 22:- COMMAND TO ALTER THE STRUCTURE


QUERY 23:- COMMAND TO DELETE THE RECORDS FROM TABLE

QUERY 24:- COMMAND TO DELETE THE TABLE

You might also like