0% found this document useful (0 votes)
18 views

Practical File

Uploaded by

Avyaan Tiwari
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Practical File

Uploaded by

Avyaan Tiwari
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 46

DELHI PUBLIC SCHOOL

ELDECO, LUCKNOW

(SESSION 2020-21)

COMPUTER SCIENCE (083)


CLASS XII
PRACTICAL FILE

MADE BY:
FARHAN KHAN

XII-D

INDEX
SNO OBJECTIVE PAGE NO REMARKS

1
1 ACKNOWLEDGEMENT 3
2 To check whether the given number isArmstrong number 4
3 To check for a prime number 5, 6
4 To display a series and print its sum 7
5 To print Pascals Triangle 8
6 To print a diamond of Asterisks 9, 10
7 To print alphabet series 11
8 To reverse a number 12
9 To reverse a string 13
10 To calculate the distance between 2 points 14
11 To calculate the area of Square, Rectangle, Triangle and Circle 15, 16
12 To print the factorial of a number 17
13 To print the factors of a given number 18
14 To implement a 2-D array 19, 20
15 To perform binary operations 21, 22
16 To search for a character in a string 23
17 To perform insertion in an array 24, 25
18 To implement merge sort 26, 27
19 To search in a binary file 28, 29
20 To concatenate two strings 30
21 To implement Dynamic Memory Allocation of arrays 31, 32
22 To check whether the given year is Leap Year 33
23 To perform Matrix operations 34, 35, 36, 37
24 To perform insertion in the beginning of a linked list 38, 39
25 To perform insertion at the end of a linked list 40, 41
26 To read from a file and reverse a word of the user’s choice 42, 43
27 To swap two values using pointers 44
28 To add 2 time using class objects 45, 46
29 To print a ‘X’ of asterisk 47
30 To perform operations on a stack implemented through linked lists 48, 49, 50
31 To convert lowercase to uppercase 51

ACKNOWLEDGEMENT

2
I would like to express my sincere gratitude towards my computer science
teacher Mr.Rohit Chandra, for his vital support, guidance and encouragement
without which this project would not have come forth. I would also like to
express my gratitude to the school for letting me use the school’s computer
laboratory.

FARHAN KHAN

Objective: To check whether the given number is Armstrong number.

Source Code:

3
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{ clrscr();
intnum,n,a,b,c,s;
cout<<"Enter a number:";
cin>>num;
n=num;
a=num/100;
num=num%100;
b=num/10;
num=num%10;
c=num;
s=(pow(a,3)+pow(b,3)+pow(c,3));
if(s==n)
cout<<"This is an armstrong number"<<"\n";
else
cout<<"This is not a armstrong number";
getch();
return;
}

Output:

Objective: To check for a prime number.

Source Code:

4
#include<iostream.h> cout<<"Enter any number:";
#include<conio.h> cin>>n;
void main() for(i=2;i<=n/2;i++)
{ clrscr(); { if(n%i==0)
void prime(void); { flag++;
charch; }
else
do ;
{ prime(); }
cout<<"Want to continue(y/n)?"; if(flag==0)
cin>>ch; { cout<<"PRIME"<<"\n";
} }
while(ch=='Y' || ch=='y'); else
getch(); { cout<<"NOT PRIME"<<"\n";
return; }
} }
void prime()
{ intn,i,flag=0;

Output:

Objective: To display a series and print its sum

5
Source Code:

#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{ clrscr();
int s=0,i;
cout<<"TO FIND THE SUM OF THE GIVEN SERIES"<<"\n";
for(i=1;i<11;i++)
{ cout<<(i*i)<<'\t'<<"\t";
s=s+(i*i);
}
cout<<"THE SUM OF THE GIVEN SERIES IS:"<<s;
getch();
return;
}

Output:

Objective: To print Pascals Triangle

Source Code:

6
#include<iostream.h> for(m=i-1;m>=1;m--)
#include<conio.h> { cout<<m;
void main() }
{ clrscr();
inti,j,k,n,m; cout<<"\n";
cin>>n; }
for(i=1;i<=n;i++)
{ for(j=n-i;j>=1;j--)
{ cout<<' '; getch();
}
for(k=1;k<=i;k++) }
{ cout<<k;
}

Output:

Objective: To print a diamond of asterisks

7
Source Code:

#include<iostream.h> cout<<"\n"; // end of second loop


#include<conio.h> }
for(i=n;i>=1;i--)
void main() { for(j=1;j<=n-i;j++)
{clrscr(); { cout<<' ';
inti,j,k,n,l,m; }
cout<<"\t\t\tTRIANGLE OF ASTERISK\n"; for(k=1;k<=i;k++)
cout<<"Enter the no of rows:"; { cout<<'*';
cin>>n; }
for(i=1;i<=n;i++) for(l=1;l<i;l++)
{ for(j=1;j<=n-i;j++) { cout<<'*';
{ cout<<' '; }
} // end of first loop
for(k=1;k<=i;k++)
{ cout<<'*'; cout<<"\n";
} }
for(l=1;l<i;l++) getch();
{ cout<<'*'; return;
} }

Output:

Objective: To print alphabet series

8
Source Code:

#include<iostream.h>
#include<conio.h>
void main()
{ clrscr();
inti,j,n;
charch='A';
cout<<"\t\t\tPROGRAM TO DISPLAY ALPHABETS PATTERN\n"
cout<<"Enter the no of rows:";
cin>>n;
for(i=1;i<=n;i++)
{ for(j=1;j<=i;j++)
{ cout<<ch;
}
ch++;
cout<<"\n";
}
getch();
}

Output:

Objective: To reverse a number

9
Source Code:

#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{ clrscr();
intnum,a,b,c,n;
cout<<"Enter a three digit number:";
cin>>num;
a=num/100;
num=num%100;
b=num/10;
num=num%10;
c=num;
cout<<"The sum of the digits is:"<<a+b+c<<"\n";
n=(c*100)+(b*10)+a;
cout<<"The Reverse of the number is:"<<n;

getch();
return;
}

Output:

Objective: To reverse a string

10
Source Code:

#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{ clrscr();
char a[100];
inti,j,l=0,k,m=0;
cout<<"\n\n\t\t\tPROGRAM TO FIND THE REVERSE OF A STRING\n";

cout<<"Enter any string:";


cin.getline(a,100);

l=strlen(a);
cout<<"THE REVERSE IS:";
for(i=l-1;i>=0;i--)
{ cout<<a[i];
}
getch();
return;
}

Output:

Objective: To calculate the distance between 2 points

11
Source Code:

#include<iostream.h> cin>>x2>>y2;
#include<conio.h> distance(x1,y1,x2,y2);
#include<math.h> getch();
void distance(int,int,int,int); return;
void main() }
{ clrscr(); void distance(inta,intb,intc,int d)
int x1,x2,y1,y2; { double m;
cout<<"PROGRAM TO FIND THE int s;
DISTANCE BETWEEN 2 POINTS\ s=((c-a)*(c-a))+((d-b)*(d-b));
n"; m=sqrt(s);
cout<<"THE DISTANCE IS:";
cout<<"Enter point 1:"; cout<<m;
cin>>x1>>y1; return;
cout<<"Enter point 2:"; }

Output:

Objective: To calculate area of various figures

12
Source Code:

#include<iostream.h> cout<<"The Perimeter is :";


#include<conio.h> cout<<p<<"\n";
#include<stdlib.h> cout<<"The Area is :";
#include<math.h> cout<<a;
void main() }
{ clrscr(); else if(n==3)
int n; {cout<<"Enter the sides of the
floatx,y,z,p,a,r; rectangle:";
cout<<"\t\t\tPROGRAM TO FIND AREA\n"; cin>>x;
cout<<"For Triangle Press 1\nFor Square cin>>y;
Press 2\nFor rect. press\n For circle p=2*(x+y);
press 4 :"; a=x*y;
cin>>n; cout<<"The perimeter is:";
if(n==1) cout<<p<<"\n:";
{cout<<"Enter the three sides of a triangle cout<<"The area is:";
:"; cout<<a;
cin>>x; }
cin>>y; else if(n==4)
cin>>z; {cout<<"Enter the radius of the circle:";
p=x+y+z; cin>>r;
a=sqrt(p*(p-x)*(p-y)*(p-z)); p=2*(22.0/7.0)*r;
cout<<"The perimeter is:"; a=(22.0/7.0)*r*r;
cout<<p<<"\n"; cout<<"The Circumference is:";
cout<<"The area is:"; cout<<p<<"\n";
cout<<a; cout<<"The Area is:";
} cout<<a;
else if(n==2) }
{cout<<"Enter the side of the square:";
cin>>x; getch();
p=x*4; return;
a=pow(a,2); }

Output:

Objective: To find the factorial of a number

13
Source Code:

#include<iostream.h>
#include<conio.h>
void main()
{ clrscr();
inti,n,f=1
;
cout<<"Enter a number:";
cin>>n;
for(i=1;i<=n;i++)

{
f*=i;
}

cout<<"THE FACTORIAL IS:"<<f;


getch();
return;
}

Output:

Objective: To print the factors of a given number:

14
Source Code:

#include<iostream.h>
#include<conio.h>
void main()
{ clrscr();
intn,i=1;
cout<<"ENTER AN INTEGER:";
cin>>n;
cout<<"The factors are:"<<"\n";

for(i;i<=n/2;i++)
{ n%i;
if(n%i==0)
{
cout<<i<<'\t';
}
else
{;
}
}
getch();
return;
}

Output:

Objective: To implement a 2D array

15
Source Code:

#include<iostream.h> { for(j=0;j<3;j++)
#include<conio.h> { cout<<a[i][j]<<'\t';
void main()
{ clrscr(); }
int a[3][3],i,j; //To enter 9 numbers and cout<<"\n";
display in table }
cout<<"Enter:";
for(i=0;i<3;i++)
{ for(j=0;j<3;j++)
{ cin>>a[i][j]; getch();
} }
}
for(i=0;i<3;i++)

Output:

Objective: To perform binary operations:

16
Source Code:

#include<iostream.h> { switch(c)
#include<conio.h> { case '+': cout<<"Added Values
void main() is:"<<a+b<<"\n";
{ clrscr(); break;
voidcal(int,int,char); case '-': cout<<"Subtracted Values
intx,y; is:"<<a-b<<"\n";
charch,m; break;
do case '*': cout<<"Product
{ cout<<"Enter any 2 numbers and is:"<<a*b<<"\n";
operator of your choice(+,-,*,/,%):"; break;
cin>>x>>y>>ch; case '/': cout<<"Division
cal(x,y,ch); is:"<<a/b<<"\n";
cout<<"WANT TO break;
CONTINUE(Y/N)?"; case '%': cout<<"Remainder is:"<<a
cin>>m; %b<<"\n";
} break;
while(m=='Y' || m=='y'); default: cout<<"INVALID
getch(); OPERATOR"<<"\n";
return; break;
} }
voidcal(inta,intb,char c) }

Output:

Objective: To search for a character in a string

17
Source Code:

#include<iostream.h> for(i=0
#include<conio.h> ;a[i]!='\0';i++)
void main() {
{ clrscr(); if(a[i]==ch)
inti; { cout<<i+1<<"\n";
char a[50],ch; }
cout<<"Enter any word"<<"\n"; else
cin.getline(a,50); {;
}
cout<<"Enter the charater to be searched }
for:"<<"\n"; getch();
cin>>ch; return;
cout<<"Character found at following }
positions:"<<"\n";

Output:

Objective: To perform insertion in an array

18
Source Code:

#include<iostream.h> }
#include<conio.h> else
void main() {;
{ clrscr(); }
int a[20],i,j,n,p; }
cout<<"Enter array"; for(i=9;i>=p;i--)
{a[i+1]=a[i];
for(i=0;i<10;i++) }
{ cin>>a[i]; a[p]=n;
} for(i=0;i<11;i++)
cout<<"Enter the item to be added"; { cout<<a[i]<<'\t';
cin>>n; }
for(i=0;i<10;i++) getch();
{ if(a[i]<n && a[i+1]>n) }
{ p=i+1;

Output:

Objective: To implement merge sort

19
Source Code:

#include<iostream.h> if(i>=5)
#include<conio.h> { while(j>=0)
void main() {c[k]=b[j];
{ clrscr(); k--;
int a[5],b[5],c[100],i=0,j=0,k; j--;
cout<<"Enter array 1 in ao"; }
for(i=0;i<5;i++) }
{ cin>>a[i]; if(j<0)
} { while(i<5)
cout<<"Enter array 2 in descending order"; { c[k]=a[i];
for(i=0;i<5;i++) k--;
{ cin>>b[i]; i++;
} }
i=0,j=4,k=9; }
while(i<5 && j>=0) }
{ if(a[i]<=b[j])
{c[k]=a[i];
i++;
k--; cout<<"THE NEW ARRAY IS:"<<"\n";
} for(k=0;k<10;k++)
else { cout<<c[k]<<'\t';
{ c[k]=b[j]; }
k--; getch();
j--; return;
} }

Output:

20
Objective: To search in a binary file

Source Code:

#include<fstream.h> {cout<<"Enter the record you want to


#include<conio.h> search for";
#include<stdio.h> cin>>no;
#include<string.h> while(!file.eof())
classstu
{ int roll; { file.read((char*)&s,sizeof(s));
char name[20]; if(s.getroll()==no)
public: { cout<<"Record Found!!!"<<"\n";
voidshowdata(); s.showdata();
intgetroll() }
{ return roll;} else
}s; {;
voidstu::showdata() }
{ cout<<"ROLL NO:"<<roll<<'\t';
puts(name); }
return; cout<<"Do you want to search for more
} records";
void main() cin>>ch;
{ clrscr(); }while(ch=='y');
ifstream file("student.dat",ios::in|ios::binary); file.close();
int no; getch();
charch; }
do

Output:

Objective: To concatenate 2 strings

21
Source Code:

#include<iostream.h> n++;
#include<conio.h> }
void main()
{ clrscr(); for(i=0;s2[i]!='\0';i++)
char s1[100],s2[100],s3[200],i,j; { s3[n+i]=s2[i];
int n=0; }
cout<<"THIS IS A PROGRAM TO JOIN 2 s3[n+i]='\0';
STRINGS"<<"\n"; for(i=0;s3[i]!='\0';i++)
cout<<"Enter Sting 1:"; { cout<<s3[i];
cin.getline(s1,40); }
cout<<"\n"<<"Enter String 2:"; getch();
cin.getline(s2,40); return;
for(i=0;s1[i]!='\0';i++) }
{ s3[i]=s1[i];

Output:

Objective: To implement Dynamic memory allocation of arrays

22
Source Code:

#include<iostream.h> p2=ptr2;
#include<conio.h> for(i=0;i<size;i++)
void main() { cout<<"Enter roll and marks";
{ clrscr(); cin>>roll>>marks;
intsize,roll,marks,*p1,*p2,i; *ptr1=roll;
for(i=0;i<20;i++) *ptr2=marks;
{ cout<<" "; ptr1++;
} ptr2++;
cout<<"\n\n\t\tDYNAMIC ALLOCATION OF }
ARRAYS USING POINTERS\n"<<"\ ptr1=p1;
n"; ptr2=p2;
for(i=0;i<4;i++) for(i=0;i<size;i++)
{ cout<<"\n"; { cout<<"Roll is:"<<*ptr1<<'\t'<<"Marks
} is:"<<*ptr2<<"\n";
cout<<"Enter the size of the arrays"; ptr1++;
cin>>size; ptr2++;
int *ptr1=new int[size]; }
int *ptr2=new int[size]; delete[]ptr1;
cout<<"Enter the details"; delete[]ptr2;
p1=ptr1; getch();}

Output:

Objective: To check for a leap year

23
Source Code:

#include<iostream.h>
#include<conio.h>
#include<math.h>
int main()
{ clrscr();
int y;
cout<<"Enter the year:";
cin>>y;
if(y%100==0)
{if(y%400==0)
cout<<"This is leap year";
else
cout<<"This is not a leap year";
}
else
{if(y%4==0)
cout<<"This is a leap year";
else
cout<<"This is not a leap year";
}
getch();
return 0;
}

Output:

Objective: To perform matrix operations

24
Source Code:

#include<iostream.h>
#include<conio.h> case 3 : cout<<"Enter the no of rows in
void input(int [][4],int); matrix 1 and 2:";
void print(int [][4],int); cin>>r1>>r2;
void add(int [][4],int [][4],int [][4],int); if(r2==4)
void subtract(int [][4],int [][4], int [][4],int); { cout<<"Enter matrix 1:";
voidmult(int [][4],int [][4],int [][4],int); input(a,r1);
int i,j,k,r1,r2; cout<<"Enter matrix 2:";
void main() input(b,r2);
{ clrscr();
int a[10][4],b[10][4], c[10][4]; print(a,r1);
int n;
print(b,r2);
mult(a,b,c,r1);
cout<<"1 ADDITION"<<"\n"<<"2
SUBTRACTION"<<"\n"<<"3
MULTIPLICATION"<<"\n"; print(c,r1);
cin>>n; }
switch(n) else
{ case 1 : cout<<"Enter the no of rows in { cout<<"Multiplication not
matrix 1 and matrix 2 "; possible";
cin>>r1>>r2; }
cout<<"Enter matirx 1:"; break;
input(a,r1);
cout<<"Enter matrix 2:"; } \
input(b,r2);
print(a,r1);
print(b,r2); getch();
add(a,b,c,r1); return;
print(c,r1); }
break; void input(int x[][4],int y)
{

case 2 : cout<<"Enter thr no of rows in for(i=0;i<y;i++)


matrix 1 and 2:"; { for(j=0;j<4;j++)
cin>>r1>>r2; { cin>>x[i][j];
cout<<"Enter matrix 1:"; }
input(a,r1); }
cout<<"ENter matrix 2:"; return;
input(a,r2); }
print(a,r1); void print(int y[][4],int x)
print(a,r2); {
subtract(a,b,c,r1);
print(c,r1); for(i=0;i<x;i++)
break; { for(j=0;j<4;j++)
{ cout<<y[i][j]<<'\t';
}

25
cout<<"\n"; { for(j=0;j<4;j++)
} { z[i][j]=0;
cout<<"\n"; z[i][j]=x[i][j]-y[i][j];
return; }
} }
void add(int x[][4],int y[][4], int z[][4],int m) return;
{ }
for(i=0;i<m;i++) void mult(int x[][4],int y[][4],int z[][4],int m)
{ for(j=0;j<4;j++) {
{ z[i][j]=0; for(i=0;i<m;i++)
z[i][j]=x[i][j]+y[i][j]; { for(j=0;j<4;j++)
} { z[i][j]=0;
} for(k=0;k<4;k++)
return; { z[i][j]+=x[i][k]*y[k][j];
} }
void subtract(int x[][4],int y[][4],int z[][4],int }
m) }
{ return;
for(i=0;i<m;i++) }

Output:

26
Objective: To perform insertion in the beginning of Linked List

27
Source Code:

#include<iostream.h> cout<<"Inserting the node in the


#include<conio.h> beginning..."<<"\n";
struct node insertbeg(p1);
{ int info;
node *next; display(start);
}*p1,*start,*p2,*p3; cout<<"Do you wish to add more
node * newnode(int); nodes(y/n)?";
voidinsertbeg(node*); cin>>ch;
void display(node*); cout<<"\n";
void main() }
{ clrscr(); }while(ch=='y' || ch=='Y');
cout<<"\n\n\t\tPROGRAM TO IMPLEMENT display(start);
INSERTION IN BEGINNING OF getch();
LINKED LIST\n"; }
start=NULL; node * newnode(int n)
intinf,i; { p2=new node;
charch; p2->info=n;
for(i=0;i<8;i++) p2->next=NULL;
{ cout<<" "; return p2;
} }
voidinsertbeg(node *p)
do { if(start==NULL)
{ cout<<"Enter the info for new node"; { start=p;
cin>>inf; }
p1=newnode(inf); else
if(p1==NULL) { p3=start;
{ cout<<"Node not created"; start=p;
} p->next=p3;
else }
{ cout<<"Node successfully created!!!"<<"\
n";

28
Output:

29
Objective: To perform insertion at the end of a Linked List

Source Code:

#include<iostream.h> else
#include<conio.h> { cout<<"Node created successfully!!!"<<"\
struct node n";
{ int info; cout<<"Inserting node in the end"<<"\n";
node *next; insertend(p2);
}*p2,*start,*rear; display(start);
voidnewnode(int); cout<<"Do you wish to enter more
voidinsertend(node*); nodes(y/n)?";
void display(node*); cin>>ch;
void main() }
{ clrscr(); }while(ch=='y' || ch=='Y');
intinf,i; getch();
charch; }
cout<<"\n\n\t\t\tPROGRAM TO voidnewnode(int n)
IMPLEMENT INSERTION IN A { p2=new node;
LINKED LIST AT THE END\n"; p2->info=n;
start=rear=NULL; p2->next=NULL;
for(i=0;i<12;i++) return ;
{ cout<<" "; }
} voidinsertend(node* p)
{ if(start==NULL)
do { start=rear=p;
{ cout<<"Enter the new node"; }
cin>>inf; else
newnode(inf); { rear->next=p;
if(p2==NULL) rear=p;
{ cout<<"Node not created"<<"\n"; }
} return;

30
Output:

Objective: To read from a file and reverse a word

31
Source Code:

#include<fstream.h> { file>>a;
#include<conio.h> cout<<a<<'\t';
#include<string.h>
#include<stdio.h> if(strcmp(a,b)==0)
void main() { for(inti=len-1;i>=0;i--)
{ clrscr(); { fil<<b[i];
ifstream file("bs.txt");
ofstream fil("new.txt"); }
char a[20],b[20]; fil<<' ';
intlen; }
if(!file) else
{ cout<<"File not opened"; {fil<<a<<' ';
} }
else }
{ cout<<"Enter the word you want to fil.close();
reverse:"; file.close();
gets(b); }
len=strlen(b); getch();
while(!file.eof()) }

Output:

Objective: To swap two values

32
Source Code:

#include<iostream.h>
#include<conio.h>
void swap(int *,int *);
void main()
{ clrscr();
int x=10,y=15;
int *p1,*p2;
p1=&x;
p2=&y;
cout<<"THE VALUES ARE:"<<*p1<<'\t'<<*p2<<"\n";
swap(p1,p2);
cout<<"THE NEW VALUES ARE:";
cout<<x<<'\t'<<y;
getch();
}
void swap(int *a,int*b)
{ int temp;
temp=*a;
*a=*b;
*b=temp;
return;
}

Output:

Objective: To add 2 times

33
Source Code:

#include<iostream.h>
#include<conio.h> c.ss=a.ss+b.ss;
class time{ inthh,mm,ss; if(c.ss>59)
public: { c.ss=c.ss-60;
void get(); c.mm+=1;
void show(); }
timeaddtime(time,time); c.mm=a.mm+b.mm;
time() if(c.mm>59)
{ hh=0; { c.mm=c.mm-60;
mm=0; c.hh+=1;
ss=0; }
c.hh=a.hh+b.hh;
} return c;
}; }
void time::get() void main()
{ cout<<"Enter the time"; { clrscr();
cin>>hh>>mm>>ss; time t1,t2,t3;
return; t1.get();
} t1.show();
void time::show() t2.get();
{ cout<<"The time is:"; t2.show();
cout<<hh<<":"<<mm<<":"<<ss<<"\n"; t3=t3.addtime(t1,t2);
} t3.show();
time time::addtime(time a,time b) getch();}
{ time c;

Output:

Objective: To print ‘X’ of asterisk

34
Source Code:

#include<iostream.h>
#include<conio.h> cout<<"\n";
void main() }
{ clrscr(); for(i=1;i<=n;i++)
inti,j,k,l,m,n; { for(j=1;j<=n-i;j++)
cout<<"Enter the Number of rows:"; { cout<<' ';
cin>>n; }
for(i=1;i<=n;i++) cout<<'*';
{ for(j=1;j<i;j++) for(int m=1;m<i;m++)
{ cout<<' '; { cout<<' ';
} }
cout<<'*';
for(k=1;k<=n-i;k++) for(k=1;k<i;k++)
{ cout<<' '; { cout<<' ';
} }
for(l=1;l<=n-i;l++) cout<<'*';
{ cout<<' '; cout<<"\n";
} }
cout<<'*'; getch();
}

Output:

Objective: To perform operations on a Stack by implementing Linked Lists

35
Source Code:
#include<iostream.h>
#include<conio.h>
#include<process.h> getch();
void push(int[],int&,int); }
void display(int[],int); void push(int stack[],int&top,int item)
void pop(int [],int&); { if(top==size-1)
constint size=50; { cout<<"Overflow";
int m; exit(0);
void main() }
{ clrscr(); else
int stack[size],top=-1,n; { top++;
charch='y',c; stack[top]=item;
while(ch=='y' || ch=='Y') }
{ return;
cout<<"Enter the element to push: "; }
cin>>n; void display(int stack[],int top)
{ cout<<"\n"<<"The Stack Is:"<<"\n";
push(stack,top,n); cout<<stack[top]<<"<--"<<"\n";
display(stack,top); top--;
cout<<"\n"; for(inti=top;i>=0;i--)
cout<<"Want to enter more elements(y/n)?"; { cout<<stack[i]<<"\n";
ch=getche(); }
cout<<"\n"; return;
} }
clrscr(); void pop(int stack[],int&top)
cout<<"Now the deletion begins"<<"\n"; { if(top==-1)
c='y'; { cout<<"Underflow";
while(c=='y' || c=='Y') }
{ pop(stack,top); else
display(stack,top); {m=stack[top];
cout<<"The deleted item is: "<<m<<"\n"; top--;
cout<<"Want to delete more }
elements(y/n)?"; return;
c=getche(); }
}

36
Output:

Objective: To convert lowercase to uppercase

37
Source Code:

#include<iostream.h>
#include<conio.h>
#include<ctype.h>
#include<string.h>
void main()
{ clrscr();
char a[30],b[30];
cout<<"Enter any lowercase word:";
cin.getline(a,30);
for(inti=0;a[i]!='\0';i++)
{ b[i]=toupper(a[i]);
cout<<b[i];
}
getch();
}

Output:

STRUCTURED QUERY LANGUAGE (SQL)


Table 1: EMPLOYEE

38
EMP_ID NAME DEPARTMENT AGE GENDER EXPERIENCE
101 ARUN KUMAR IT 33 MALE 8
102 DIVYA MEHTA SALES 28 FEMALE 4
103 DEEPAK SALES 35 MALE 12
KUMAR
104 HAMID ALI TRANSPORT 28 MALE 8
105 NISHA ARORA FINANCE 38 FEMALE 15
106 AJAY RAO IT 42 MALE 20

Table 2: SALARY

EMP_ID BASIC ALLOWANCE WORK_BONUS


101 60000 9500 5000
102 90000 27000 15000
103 35000 11000 5000
104 35000 6000 4000
105 120000 32000 25000
106 155000 47000 30000

Query 01: To display EMP_ID, Department and experience from employees table.

SQL:

SELECT EMP_ID,DEPARTMENT,EXPERIENCE FROM EMPLOYEES;

Snapshot:

DEPARTMEN
EMP_ID T EXPERIENCE
101 IT 8
102 SALES 4
103 SALES 12
104 TRANSPORT 8
105 FINANCE 15
106 IT 20

Query 02: To display all records from EMPLOYEES

SQL:

SELECT *FROM EMPLOYEES;

Snapshot:

39
EMP_ID NAME DEPARTMENT AGE GENDER EXPERIENCE
101 ARUN KUMAR IT 33 MALE 8
102 DIVYA MEHTA SALES 28 FEMALE 4
103 DEEPAK KUMAR SALES 35 MALE 12
104 HAMID ALI TRANSPORT 28 MALE 8
105 NISHA ARORA FINANCE 38 FEMALE 15
106 AJAY RAO IT 42 MALE 20

Query 03: To display records of employees with experience between 8 and 15 years

SQL: SELECT * FROM EMPLOYEES WHERE EXPERIENCE BETWEEN 8 AND 15;

Snapshot:

EMP_ID NAME DEPARTMENT AGE GENDER EXPERIENCE


101 ARUN KUMAR IT 33 MALE 8
103 DEEPAK KUMAR SALES 35 MALE 12
104 HAMID ALI TRANSPORT 28 MALE 8
105 NISHA ARORA FINANCE 38 FEMALE 15

Query 04: To display name, department and experience in increasing order of experience

SQL: SELECT EMP_ID,NAME,DEPARTMENT,EXPERIENCE FROM EMPLOYEES

ORDER BY EXPERIENCE;

Snapshot:

EMP_ID NAME DEPARTMENT EXPERIENCE


102 DIVYA MEHTA SALES 4
101 ARUN KUMAR IT 8
104 HAMID ALI TRANSPORT 8
103 DEEPAK KUMAR SALES 12
105 NISHA ARORA FINANCE 15
106 AJAY RAO IT 20

Query 05: To display records of employees with experience greater than avg. experience

SQL: SELECT * FROM EMPLOYEES WHERE EXPERIENCE> (SELECTAVG(EXPERIENCE)


FROM EMPLOYEES);

Snapshot:

EMP_ID NAME DEPARTMENT AGE GENDER EXPERIENCE


103 DEEPAK KUMAR SALES 35 MALE 12
105 NISHA ARORA FINANCE 38 FEMALE 15

40
106 AJAY RAO IT 42 MALE 20

Query 06: To insert a row into table EMPLOYEES

SQL: INSERT INTO EMPLOYEES VALUES(107,'NITESH SINGH','TRANSPORT',35,'MALE',14);

Snapshot:

3
107 NITESH SINGH TRANSPORT MALE 14
5

Query 07: To insert a row into table salary

SQL: INSERT INTO SALARY VALUES(107,47000,22000,12000);

Snapshot:

107 47000 22000 12000

Query 08: To display records of salary

SQL: SELECT *FROM SALARY;

Snapshot:

EMP_ID BASIC ALLOWANCE WORK_BONUS


101 60000 9500 5000
103 90000 27000 15000
104 35000 11000 5000
102 35000 6000 4000
12000
105 32000 25000
0
15500
106 47000 30000
0
107 47000 22000 12000

Query 09: To display Emp_id, basic, allowance from SALARY whoseWork_bonus>=8000

SQL: SELECT EMP_ID,BASIC,ALLOWANCE FROM SALARY WHERE WORK_BONUS>8000;

Snapshot:

EMP_ID BASIC ALLOWANCE


103 90000 27000
105 120000 32000
106 155000 47000
107 47000 22000

41
Query 10: To display the records of table SALARY in increasing order of ‘basic’

SQL: SELECT *FROM SALARY ORDER BY BASIC;

Snapshot:

EMP_ID BASIC ALLOWANCE WORK_BONUS


102 35000 6000 4000
104 35000 11000 5000
107 47000 22000 12000
101 60000 9500 5000
103 90000 27000 15000
12000
105 32000 25000
0
15500
106 47000 30000
0

Query 11: To display the records of table Salary where allowance is between 20,000 and 1,00,000

SQL: SELECT *FROM SALARY WHERE ALLOWANCE BETWEEN 20000 AND 100000;

Snapshot:

EMP_ID BASIC ALLOWANCE WORK_BONUS


103 90000 27000 15000
12000
105 32000 25000
0
15500
106 47000 30000
0
107 47000 22000 12000

Query 12: To display details from EMPLOYEES and SALARY whose ‘Basic’>=50,000

SQL: SELECT E.EMP_ID,E.NAME,E.DEPARTMENT,S.BASIC,S.ALLOWANCE FROM EMPLOYEES


E,SALARY S WHERE E.EMP_ID=S.EMP_ID AND S.BASIC>50;

Snapshot:

DEPARTMEN
EMP_ID NAME T BASIC ALLOWANCE
101 ARUN KUMAR IT 60000 9500
103 DEEPAK KUMAR SALES 90000 27000
105 NISHA ARORA FINANCE 120000 32000
106 AJAY RAO IT 155000 47000

Query 13: To display distinct columns of tables EMPLOYEES and SALARY

SQL: SELECT *FROM EMPLOYEES NATURAL JOIN SALARY;

42
Snapshot:

Query 14: To display the total basic of all employees

SQL: SELECT SUM(BASIC) AS "TOTAL BASIC" FROM SALARY;

Snapshot:

TOTAL BASIC
542000

Query 15: To display EMP_ID,Name,Department and total salary of all employees

SQL: SELECT E.EMP_ID,E.NAME,E.DEPARTMENT,S.BASIC+S.ALLOWANCE+S.WORK_BONUS


AS"TOTAL SALARY" FROM EMPLOYEES E,SALARY S WHERE
E.EMP_ID=S.EMP_ID;

Snapshot:

EMP_ID NAME DEPARTMENT TOTAL SALARY


101 ARUN KUMAR IT 74500
103 DEEPAK KUMAR SALES 132000
104 HAMID ALI TRANSPORT 51000
102 DIVYA MEHTA SALES 45000
105 NISHA ARORA FINANCE 177000
106 AJAY RAO IT 232000
107 NITESH SINGH TRANSPORT 81000

Query 16: To display total salary of all employees

SQL: SELECT S.EMP_ID,S.BASIC+S.ALLOWANCE+S.WORK_BONUS AS"TOTAL SALARY"

FROM SALARY S;

Snapshot:

43
Query 17: To display details of those employees whose Department is ‘IT’

SQL: SELECT
E.EMP_ID,E.NAME,E.DEPARTMENT,E.AGE,E.GENDER,E.EXPERIENCE,S.BASIC+S.ALLOWANCE+S.WO
RK_BONUS AS"TOTAL SALARY" FROM E

Snapshot:

Query 18: To insert a row into EMPLOYEES

SQL: INSERT INTO EMPLOYEES VALUES(108,'ARJUN','FINANCE',34,'MALE',11);

Snapshot:

Query 19: To insert row into SALARY

SQL: INSERT INTO SALARY VALUES(108,53000,23000,7800);

Snapshot:

Query 20: To increment basic by 20,000 allowance by 2000

SQL UPDATE SALARY SET BASIC=BASIC+10000,ALLOWANCE=ALLOWANCE+2000;

Snapshot:

44
Query 21: To count the total experience of all the employees

SQL: SELECT SUM(EXPERIENCE) AS"TOTAL EXPERIENCE" FROM EMPLOYEES;

Snapshot:

Query 22: To display the records of those employees whose age>=30 years

SQL: SELECT * FROM EMPLOYEES WHERE AGE>=30;

Snapshot:

Query 23: To delete a row of table EMPLOYEES

SQL: DELETE FROM SALARY WHERE EMP_ID=108;

Snapshot:

45
Query 24: To display records to employees with EMP_ID between 102 and 107

SQL: SELECT *FROM EMPLOYEES WHERE EMP_ID BETWEEN 102 AND 107;

Snapshot:

Query 25: To delete a column

SQL: ALTER TABLE SALARY DROP COLUMN WORK_BONUS;

Snapshot:

46

You might also like