Practical File
Practical File
ELDECO, LUCKNOW
(SESSION 2020-21)
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
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:
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:
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:
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:
7
Source Code:
Output:
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:
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:
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";
l=strlen(a);
cout<<"THE REVERSE IS:";
for(i=l-1;i>=0;i--)
{ cout<<a[i];
}
getch();
return;
}
Output:
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:
12
Source Code:
Output:
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;
}
Output:
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:
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:
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:
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:
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:
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:
Output:
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:
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:
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:
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)
{
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:
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:
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:
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:
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:
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:
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:
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:
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
Query 01: To display EMP_ID, Department and experience from employees table.
SQL:
Snapshot:
DEPARTMEN
EMP_ID T EXPERIENCE
101 IT 8
102 SALES 4
103 SALES 12
104 TRANSPORT 8
105 FINANCE 15
106 IT 20
SQL:
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
Snapshot:
Query 04: To display name, department and experience in increasing order of experience
ORDER BY EXPERIENCE;
Snapshot:
Query 05: To display records of employees with experience greater than avg. experience
Snapshot:
40
106 AJAY RAO IT 42 MALE 20
Snapshot:
3
107 NITESH SINGH TRANSPORT MALE 14
5
Snapshot:
Snapshot:
Snapshot:
41
Query 10: To display the records of table SALARY in increasing order of ‘basic’
Snapshot:
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:
Query 12: To display details from EMPLOYEES and SALARY whose ‘Basic’>=50,000
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
42
Snapshot:
Snapshot:
TOTAL BASIC
542000
Snapshot:
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:
Snapshot:
Snapshot:
Snapshot:
44
Query 21: To count the total experience of all the employees
Snapshot:
Query 22: To display the records of those employees whose age>=30 years
Snapshot:
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:
Snapshot:
46