Professional Documents
Culture Documents
Comp Prac File - 1451799830267
Comp Prac File - 1451799830267
CERTFICATE
This is to certify that Harshit Raj Singh of class XIIA has submitted the Computer Science Practical
File. He has taken proper care and shown utmost
sincerity in completion of this practical file.
I certified that this practical file is upto my
expectation and as per the guidelines issued by
CBSE.
It is further certified that this practical file is an
individual work of the student.
MR.ANIL BHALOTHIA
MRS.GRACE JOSE
(PGT
Computer
(PRINCIPAL)
Science)
64
ACKNOWLEDGEMENT
64
INDEX
1) SWAPPING WITHOUT THIRD VARIABLE
Page-4
2) SIMPLE INTEREST
Page-5
3) NEGATIVE OR POSITIVE NUMBER
Page-6
4) AGE GROUP
Page-7
5) INCOME TAX CALCULATION
Page-8
6) ARITHMETIC OPERAYORS (+ - * / %)
Page-9
7) FIBONACCI SERIES
Page-11
8) SUM,PRODUCT AND REVRESE OF A NUMBER
Page-12
9) ARMSTRONG NUMBERS
Page-13
10)
HCF AND LCM
Page-14
11)
PRIME NUMBER
Page-15
12)
PATTERN TYPE-1
Page-16
13)
PATTERN TYPE-2
Page-17
14)
PATTERN TYPE-3
Page-18
15)
PATTERN TYPE-4
Page-19
16)
PATTERN TYPE-5
Page-20
17)
PATTERN TYPE-6
Page-21
18)
BINARY SEARCH
Page-22
64
19)
SELECTION SORT
Page-24
20)
BUBBLE SORT
Page-25
21)
CALL BY VALUE
Page-26
22)
CALL BY REFERENCE
Page-27
23)
STRING REVERSAL
Page-28
24)
PALLINDROME STRING
Page-29
25)
COUNT OF WORDS,CAPITAL LETERS ,ETC. IN A STRING
Page-30
26)
LEFT DIAGONAL OF 2-D ARRAY
Page-31
27)
RIGHT DIAGONAL 2-D ARRAY
Page-32
28)
TRANSPOSE OF 2-D ARRAY
Page-33
29)
FUNCTION OVERLOADING
Page-34
30)
FACTORIAL USING RECURSIVE FUNCTION
Page-36
31)
SQL
Page-37
32)
64
1.
LINEAR SEARCH
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class data
{
int empno;
static int count;
char name[50];
float sal;
public: void entry();
void disp();
int retempno();
};
int data::count=0;
void data::entry()
{
cout<<"\nEnter no, name and salary of Emp "<<++count<<endl;
cin>>empno;
gets(name);
cin>>sal;
}
void data::disp()
{
cout<<"\nData is :-\n";
cout<<empno<<endl;
cout<<name<<endl;
cout<<sal<<endl;
}
int data::retempno()
{
return empno;
}
void main()
64
clrscr();
int dl,flag=0;
data d[5];
for(int i=0;i<5;i++)
d[i].entry();
cout<<"\nEnter no to be searched\n";
cin>>dl;
for(i=0;i<5;i++)
if(d[i].retempno()==dl)
{
flag++;
d[i].disp();
}
if(flag==0)
cout<<"\nNOT FOUND\n";
getch();
64
2.
BINARY SEARCH
64
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class data
{
int empno;
static int count;
char name[50];
float sal;
public: void entry();
void disp();
int retempno();
};
int data::count=0;
void data::entry()
{
cout<<"\nEnter no(in ascending order), name and salary of Emp
"<<++count<<endl;
cin>>empno;
gets(name);
cin>>sal;
}
void data::disp()
{
cout<<"\nData is :-\n";
cout<<empno<<endl;
cout<<name<<endl;
cout<<sal<<endl;
}
int data::retempno()
{
return empno;
}
void main()
{
clrscr();
int dl,flag=0,b,l,m;
data d[5];
for(int i=0;i<5;i++)
d[i].entry();
64
cout<<"\nEnter no to be searched\n";
cin>>dl;
b=0;
l=5-1;
while(b<=l)
{
m=(b+l)/2;
if(d[m].retempno()==dl)
{
flag++;
d[m].disp();
break;
}
else if(d[m].retempno()<dl)
b=m+1;
else if(d[m].retempno()>dl)
l=m-1;
}
if(flag==0)
cout<<"\nNOT FOUND\n";
getch();
}
64
3.
SELECTION SORT
64
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class data
{
int empno;
static int count;
char name[50];
float sal;
public: void entry();
void disp();
int retempno();
};
int data::count=0;
void data::entry()
{
cout<<"\nEnter no, name and salary of Emp "<<++count<<endl;
cin>>empno;
gets(name);
cin>>sal;
}
void data::disp()
{
cout<<"\nData is :-\n";
cout<<empno<<endl;
cout<<name<<endl;
cout<<sal<<endl;
}
int data::retempno()
{
return empno;
}
void main()
{
clrscr();
int p,min,i,j;
64
data d[5],t;
for(i=0;i<5;i++)
d[i].entry();
for(i=0;i<5-1;i++)
min=d[i].retempno();
p=i;
for(j=i+1;j<5;j++)
{
if(d[j].retempno()<min)
{
p=j;
min=d[j].retempno();
}
}
t=d[i];
d[i]=d[p];
d[p]=t;
}
for(i=0;i<5;i++)
d[i].disp();
getch();
64
64
4.
BUBBLE SORT
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class data
{
int empno;
static int count;
char name[50];
float sal;
public: void entry();
void disp();
int retempno();
};
int data::count=0;
void data::entry()
{
cout<<"\nEnter no, name and salary of Emp "<<++count<<endl;
cin>>empno;
gets(name);
cin>>sal;
}
void data::disp()
{
cout<<"\nData is :-\n";
cout<<empno<<endl;
cout<<name<<endl;
cout<<sal<<endl;
}
int data::retempno()
{
return empno;
64
void main()
clrscr();
int i,j;
data d[5],t;
for(i=0;i<5;i++)
d[i].entry();
for(i=0;i<5-1;i++)
for(j=0;j<5-1-i;j++)
if(d[j].retempno()<d[j+1].retempno())
{
t=d[j];
d[j]=d[j+1];
d[j+1]=t;
}
for(i=0;i<5;i++)
d[i].disp();
getch();
64
64
5. INSERTION
SORT
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class data
{
int empno;
static int count;
char name[50];
float sal;
public: void entry();
void disp();
int retempno();
};
int data::count=0;
void data::entry()
{
cout<<"\nEnter no, name and salary of Emp "<<++count<<endl;
cin>>empno;
gets(name);
cin>>sal;
}
void data::disp()
{
cout<<"\nData is :-\n";
cout<<empno<<endl;
cout<<name<<endl;
cout<<sal<<endl;
}
int data::retempno()
{
return empno;
64
void main()
clrscr();
int i,j;
data d[5],num;
for(i=0;i<5;i++)
d[i].entry();
for(i=1;i<5;i++)
{
num=d[i];
for(j=i-1;j>=0;j--)
{
if(d[j].retempno() < num.retempno() )
d[j+1]=d[j];
else
break;
}
d[j+1]=num;
}
for(i=0;i<5;i++)
d[i].disp();
getch();
64
64
6.
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
struct stud
{
int rno;
char name[50];
stud *link;
};
class list
{
stud *start;
stud *last;
public: list()
{
start=last=NULL;
}
void insert();
void del();
void disp();
void search();
};
void main()
{
clrscr();
list s;
int ch;
do
{
cout<<"\nPress 1 to
cout<<"\nPress 2 to
cout<<"\nPress 3 to
cout<<"\nPress 4 to
cout<<"\nPress 5 to
cin>>ch;
switch(ch)
{
case 1:int ch1;
do
{
LINKED LIST
64
clrscr();
s.insert();
clrscr();
cout<<"\nNode inserted\n";
cout<<"\nWanna enter more(y/n)\n";
ch1=getch();
}while(ch1=='y' || ch1=='Y');
break;
case 2:clrscr();
s.disp();
break;
case 3:clrscr();
s.del();
clrscr();
cout<<"\nNode deleted\n";
break;
case 4:clrscr();
s.search();
break;
}
}while(ch!=5);
cout<<"\nTHANK YOU\n";
getch();
}
void list::insert()
{
stud *cpt=new stud;
cout<<"\nEnter no and name\n";
cin>>cpt->rno;
gets(cpt->name);
cpt->link=NULL;
if(start==NULL)
{
start=last=cpt;
}
else
{
last->link=cpt;
last=cpt;
}
}
void list::disp()
64
if(start==NULL)
{
cout<<"\nLIST IS EMPTY\n";
return;
}
stud *p;
for(p=start;p!=NULL;p=p->link)
{
cout<<p->rno<<endl;
cout<<p->name<<endl;
}
}
void list::search()
{
if(start==NULL)
{
cout<<"\nLIST IS EMPTY\n";
return;
}
int num,flag=0;
cout<<"\nEnter no to be searched\n";
cin>>num;
clrscr();
stud *p;
for(p=start;p!=NULL;p=p->link)
{
if(p->rno==num)
{
flag++;
cout<<p->rno<<endl;
cout<<p->name<<endl;
}
}
if(flag==0)
{
cout<<"\nNOT FOUND\n";
}
}
void list::del()
64
stud *p,*cp1,*cp2;
int num;
cout<<"\nEnter the no to be deleted\n";
cin>>num;
for(p=start;p!=NULL;p=p->link)
{
if(p->rno==num)
{
cp1=p;
break;
}
cp2=p;
}
if(cp1==start)
{
if(start==last)
{
start=last=NULL;
}
else
{
start=start->link;
}
}
else if(cp1==last)
{
last=cp2;
last->link=NULL;
}
else
{
cp2->link=cp1->link;
}
delete cp1;
}
64
64
7.
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
struct stud
{
int rno;
char name[50];
};
class stack
{
int top;
stud t[50];
public: stack()
{
top=-1;
}
void push();
void pop();
void disp();
};
void main()
{
clrscr();
stack s;
int ch;
do
{
cout<<"\nPress 1
cout<<"\nPress 2
cout<<"\nPress 3
cout<<"\nPress 4
cin>>ch;
switch(ch)
{
case 1:int ch1;
do
{
clrscr();
to
to
to
to
push in stack";
pop in stack";
display the stack";
exit\n";
64
s.push();
clrscr();
cout<<"\nPushing done";
cout<<"\nWanna push more(y/n)\n";
ch1=getch();
}while(ch1=='y' || ch1=='Y');
break;
case 2:clrscr();
s.pop();
cout<<"\nPopping done\n";
break;
case 3:clrscr();
s.disp();
break;
}
}while(ch!=4);
cout<<"\nTHANK YOU\n";
getch();
}
void stack::push()
{
if(top==49)
{
cout<<"\nSTACK OVERFLOW\n";
return;
}
stud cpt;
cout<<"\nEnter no and name\n";
cin>>cpt.rno;
gets(cpt.name);
top++;
t[top]=cpt;
}
void stack::disp()
{
if(top==-1)
{
cout<<"\nSTACK UNDERFLOW\n";
return;
}
int i;
for(i=top;i>=0;i--)
64
cout<<t[i].rno<<endl;
cout<<t[i].name<<endl;
}
}
void stack::pop()
{
if(top==-1)
{
cout<<"\nSTACK UNDERFLOW\n";
return;
}
cout<<t[top].rno<<endl;
cout<<t[top].name<<endl;
top--;
}
64
64
8.
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
struct stud
{
int rno;
char name[50];
stud *link;
};
class stack
{
stud *top;
public: stack()
{
top=NULL;
}
void push();
void pop();
void disp();
};
void main()
{
clrscr();
stack s;
int ch;
do
{
cout<<"\nPress 1
cout<<"\nPress 2
cout<<"\nPress 3
cout<<"\nPress 4
cin>>ch;
switch(ch)
{
case 1:int ch1;
do
{
to
to
to
to
push in stack";
pop in stack";
display the stack";
exit\n";
64
clrscr();
s.push();
clrscr();
cout<<"\nPushing done";
cout<<"\nWanna push more(y/n)\n";
ch1=getch();
}while(ch1!='n');
break;
case 2:clrscr();
s.pop();
cout<<"\nPopping done\n";
break;
case 3:clrscr();
s.disp();
break;
}
}while(ch!=4);
cout<<"\nTHANK YOU\n";
getch();
}
void stack::push()
{
stud *cpt=new stud;
cout<<"\nEnter no and name\n";
cin>>cpt->rno;
gets(cpt->name);
cpt->link=NULL;
if(top==NULL)
{
top=cpt;
}
else
{
cpt->link=top;
top=cpt;
}
}
64
void stack::disp()
{
if(top==NULL)
{
cout<<"\nSTACK UNDERFLOW\n";
return;
}
stud *i;
for(i=top;i!=NULL;i=i->link)
{
cout<<i->rno<<endl;
cout<<i->name<<endl;
}
}
void stack::pop()
{
if(top==NULL)
{
cout<<"\nSTACK UNDERFLOW\n";
return;
}
cout<<top->rno<<endl;
cout<<top->name<<endl;
stud *cpt;
cpt=top;
top=top->link;
delete cpt;
}
64
64
class queue
{
stud *front;
stud *rear;
public: queue()
{
front=rear=NULL;
}
void insert();
void del();
void disp();
};
void main()
{
clrscr();
queue s;
int ch;
do
{
cout<<"\nPress 1 to insert a new node";
cout<<"\nPress 2 to display all nodes";
cout<<"\nPress 3 to delete a node";
cout<<"\nPress 4 to exit\n";
cin>>ch;
switch(ch)
{
case 1:int ch1;
do
{
clrscr();
s.insert();
clrscr();
cout<<"\nNode inserted\n";
cout<<"\nWanna enter more(y/n)\n";
ch1=getch();
}while(ch1=='y' || ch1=='Y');
break;
case 2:clrscr();
s.disp();
64
break;
case 3:clrscr();
s.del();
break;
}
}while(ch!=4);
cout<<"\nTHANK YOU\n";
getch();
}
void queue::insert()
{
stud *cpt=new stud;
cout<<"\nEnter no and name\n";
cin>>cpt->rno;
gets(cpt->name);
cpt->link=NULL;
if(rear==NULL)
{
front=rear=cpt;
}
else
{
rear->link=cpt;
rear=cpt;
}
}
void queue::disp()
{
if(rear==NULL)
{
cout<<"\nQUEUE IS EMPTY\n";
return;
}
stud *p;
for(p=front;p!=NULL;p=p->link)
{
cout<<p->rno<<endl;
cout<<p->name<<endl;
}
}
64
void queue::del()
{
if(front==NULL)
{
cout<<"\nQUEUE IS EMPTY\n";
return;
}
stud *ptr;
ptr=front;
cout<<ptr->rno<<endl;
cout<<ptr->name<<endl;
if(front==rear)
{
front=rear=NULL;
}
else
{
front=front->link;
}
delete ptr;
cout<<"\nNode Deleted\n";
}
64
64
10. QUEU
E USING
ARRAY
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
struct stud
{
int rno;
char name[50];
};
class queue
{
int front,rear;
stud a[50];
public: queue()
{
front=rear=-1;
}
void insert();
void del();
void disp();
};
void main()
{
clrscr();
queue s;
int ch;
do
{
cout<<"\nPress 1 to insert a new node";
64
64
else
{
rear++;
}
a[rear]=m;
}
void queue::disp()
{
if(rear==-1)
{
cout<<"\nQUEUE IS EMPTY\n";
return;
}
int i;
for(i=front;i<=rear;i++)
{
cout<<a[i].rno<<endl;
cout<<a[i].name<<endl;
}
}
void queue::del()
{
if(front==-1)
{
cout<<"\nQUEUE IS EMPTY\n";
return;
}
cout<<a[front].rno<<endl;
cout<<a[front].name<<endl;
if(front==rear)
{
front=rear=-1;
}
else
{
front++;
}
cout<<"\nNode Deleted\n";
}
64
64
11.
CIRCULAR
QUEUE USING ARRAY
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
struct stud
{
int rno;
char name[50];
};
class cqueue
{
int front,rear;
stud a[50];
public: cqueue()
{
front=-1;
rear=-1;
}
void insert();
void del();
void disp();
};
void main()
{
clrscr();
cqueue s;
int ch;
64
do
{
64
rear=0;
}
else if(rear==49)
{
rear=0;
}
else
{
rear++;
}
cout<<front<<" "<<rear;
a[rear]=m;
}
void cqueue::disp()
{
if(rear==-1)
{
cout<<"\nQUEUE IS EMPTY\n";
return;
}
int i;
if(front<=rear)
{
for(i=front;i<=rear;i++)
{
cout<<a[i].rno<<endl;
cout<<a[i].name<<endl;
}
}
else
{
for(i=front;i<=49;i++)
{
cout<<a[i].rno<<endl;
cout<<a[i].name<<endl;
}
for(i=0;i<=rear;i++)
{
cout<<a[i].rno<<endl;
cout<<a[i].name<<endl;
}
}
}
64
void cqueue::del()
{
if(front==-1)
{
cout<<"\nQUEUE IS EMPTY\n";
return;
}
cout<<a[front].rno<<endl;
cout<<a[front].name<<endl;
if(front==rear)
{
front=rear=-1;
}
else if(front==49)
{
front=0;
}
else
{
front++;
}
cout<<"\nNode Deleted\n";
}
64
64
12.
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class employee
{
char name[70];
long eno;
public : void getdata();
void putdata();
protected: float bs,bon;
void getbsbon();
};
class manager:public employee
{
char title[75];
public: void getdata();
void putdata();
};
class clerk:public employee
{
char dept[90];
INHERITANCE
64
64
employee::getdata();
getbsbon();
cout<<"Enter dept.:-\t\t";
gets(dept);
}
void clerk::putdata()
{
employee::putdata();
cout<<"\nDept.: "<<dept;
}
void main()
{
clrscr();
manager m[2];
clerk c[1];
for(int i=0;i<2;i++)
{
cout<<"\nEnter details of manager "<<i+1;
m[i].getdata();
}
for(i=0;i<1;i++)
{
cout<<"\nEnter details of clerk "<<i+1;
c[i].getdata();
}
for(i=0;i<2;i++)
{
cout<<"\nDetails of Manager "<<i+1;
m[i].putdata();
cout<<endl;
}
for(i=0;i<1;i++)
{
cout<<"\nDetails of Clerk "<<i+1;
c[i].putdata();
cout<<endl;
}
getch();
}
64
64
64
for(j=0;j<n2;j++)
cin>>B[i][j];
void matrix::multiply()
{
int r,i,j;
if(n1!=m2)
{
cout<<"\nA x B does not exist";
getch();
exit(0);
}
for(i=0;i<m1;i++)
for(j=0;j<n2;j++)
{
int s=0;
for(r=0;r<n1;r++)
{
s=s+ A[i][r]*B[r][j];
C[i][j]=s;
}
}
}
void matrix::disp()
{
cout<<"\nAB is :\n";
for(int i=0;i<m1;i++)
{
cout<<endl;
for(int j=0;j<n2;j++)
cout<<C[i][j]<<"\t";
}
}
void main()
{
64
clrscr();
matrix M;
M.entry();
M.multiply();
M.disp();
getch();
64
64
}
void main()
{
clrscr();
chars d;
d.entry();
int flag=0;
char k[100],*p;
cout<<"\nEnter the name to be searched\n";
gets(k);
for(int i=0;i<d.retn();i++)
{
p=d.search(i);
if(strcmpi(p,k)==0)
{
cout<<"\nFOUND\n";
flag++;
}
}
if(flag==0)
cout<<"\nNOT FOUND";
getch();
}
15.
DR
ST
PALLIN
OME
RING
64
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
class rev
{
int n;
char names[100][100];
public: void input();
void output(int);
void reversal();
};
void rev::input()
{
cout<<"\nNo. of names to be entered\n";
cin>>n;
cout<<"\nEnter names to be stored\n";
for(int i=0;i<n;i++)
gets(names[i]);
}
void rev::reversal()
{
char t;
for(int i=0;i<n;i++)
{
char str[100];
strcpy(str,names[i]);
int l,k;
for(l=0;names[i][l]!='\0';l++);
k=l-1;
for(int j=0;j<l/2;j++)
{
t=names[i][j];
names[i][j]=names[i][k];
names[i][k]=t;
k--;
}
if(strcmp(names[i],str)==0)
output(i);
}
}
64
void rev::output(int i)
{
cout<<"\n"<<names[i]<<" is pallindrome\n";
}
void main()
{
clrscr();
rev r;
r.input();
r.reversal();
getch();
}
16.
NA
S
S
FIBO
CCI
ERIE
64
#include<iostream.h>
#include<conio.h>
class fibonacci
{
public: void fib1();
void fib2();
void fib3();
};
void main()
{
clrscr();
int ch;
fibonacci f;
cout<<"\nPress 1 for Fibonacci series 1 (3rd no sum of first 2)";
cout<<"\nPress 2 for Fibonacci series 2 (4th no sum of first 3)";
cout<<"\nPress 3 for Fibonacci series 3 (5th no sum of first 4)\n";
cin>>ch;
switch(ch)
{
case 1:f.fib1();
break;
case 2:f.fib2();
break;
case 3:f.fib3();
break;
}
cout<<"\nTHANK YOU\n";
getch();
}
void fibonacci::fib1()
{
long a,b,c;
cout<<"\nEnter the two numbers\n";
cin>>a>>b;
c=a+b;
cout<<"\nFirst 20 elements are\n";
cout<<a<<" "<<b<<" ";
for(int i=1;i<20-2;i++)
{
cout<<c<<" ";
a=b;
b=c;
c=a+b;
}
64
}
void fibonacci::fib2()
{
long a,b,c,d;
cout<<"\nEnter the three numbers\n";
cin>>a>>b>>c;
d=a+b+c;
cout<<"\nFirst 20 elements are\n";
cout<<a<<" "<<b<<" "<<c<<" ";
for(int i=1;i<20-3;i++)
{
cout<<d<<" ";
a=b;
b=c;
c=d;
d=a+b+c;
}
}
void fibonacci::fib3()
{
long a,b,c,d,e;
cout<<"\nEnter the four numbers\n";
cin>>a>>b>>c>>d;
e=a+b+c+d;
cout<<"\nFirst 20 elements are\n";
cout<<a<<" "<<b<<" "<<c<<" "<<d<<" ";
for(int i=1;i<20-4;i++)
{
cout<<e<<" ";
a=b;
b=c;
c=d;
d=e;
e=a+b+c+d;
}
64
17.
17.
PATTERN TYPE
64
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
class pattern
{
public: void pat();
};
void pattern::pat()
{
int j,s;
for(int i=-1;i<=3;i++)
{
cout<<endl;
for(s=1;s<=3-i;s++)
cout<<" ";
for(j=5;j>=5-i;j--)
cout<<j;
cout<<"1";
for(j=5-i;j<=5;j++)
cout<<j;
}
for(i=4;i>=1;i--)
{
cout<<endl;
for(s=4;s>=i;s--)
cout<<" ";
for(j=i;j>=1;j--)
cout<<j;
for(j=2;j<=i;j++)
cout<<j;
}
}
void main()
{
clrscr();
pattern p;
p.pat();
getch();
}
#include<iostream.h>
#include<stdio.h>
18. SERIES
64
#include<conio.h>
#include<math.h>
class series
{
public: void ser();
};
void series::ser()
{
int n,s,p,r,pw,sq;
for(n=1;n<=10000;n++)
{
s=0;
for(p=n;p!=0;p/=10)
{
s++;
}
pw=pow(10,s);
sq=n*n;
r=sq%pw;
if(r==n)
cout<<n<<" ";
}
}
void main()
{
clrscr();
series s;
cout<<"\nAutomorphic Numbers from 1 to 10000\n";
s.ser();
getch();
}
64
#include<fstream.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
class TRAIN
{
int Tno;
char From[20];
char To[20];
public: char* GetFrom();
char* GetTo();
void Input();
void Show();
};
char* TRAIN::GetFrom()
{
return From;
}
char* TRAIN::GetTo()
{
return To;
}
void TRAIN::Input()
{
cout<<"\nEnter No.:-\t";
cin>>Tno;
cout<<"Enter From:-\t";
gets(From);
cout<<"Enter To:-\t";
gets(To);
}
void TRAIN::Show()
{
cout<<"\nDetails are:\n";
cout<<"Train Num.:\t"<<Tno;
cout<<"\nFrom:"<<From<<"\tTo:"<<To;
64
void main()
{
delete("TRAIN.dat");
clrscr();
fstream f;
f.open("TRAIN.dat",ios::in|ios::out|ios::binary);
TRAIN t[4];
char str[100];
for(int i=0;i<2;i++)
{
cout<<"\nEnter Details\n";
t[i].Input();
f.write((char *) &t[i],sizeof(TRAIN));
}
cout<<"\nEnter From to be updated\n";
gets(str);
for(i=0;i<2;i++)
{
f.read((char *) &t[i],sizeof(TRAIN));
if(strcmpi(t[i].GetFrom(),str)==0)
{
cout<<"\nEnter New Details\n";
t[i].Input();
int l=f.tellg();
f.seekp(l-sizeof(TRAIN));
f.read((char *) &t[i],sizeof(TRAIN));
}
}
cout<<"\nAfter Change contents are\n";
for(i=0;i<2;i++)
{
f.read((char *) &t[i],sizeof(TRAIN));
t[i].Show();
}
getch();
}
64
64
20.
#include<fstream.h>
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
fstream f1,f2,f3,f4;
f1.open("JOKER.txt",ios::in);
f2.open("JOKER.txt",ios::in);
f3.open("TEMP.txt",ios::out);
char str1[50],ch;
cout<<"Before change the contents of file\n\n";
ch=f1.get();
while(!f1.eof())
{
cout<<ch;
ch=f1.get();
}
f1.close();
f2>>str1;
while(!f2.eof())
{
f3<<str1;
f3<<" ";
f2>>str1;
}
f2.close();
f3.close();
remove("JOKER.txt");
rename("TEMP.txt","JOKER.txt");
cout<<"\n\nChange Implemented\n\n";
f4.open("JOKER.txt",ios::in);
cout<<"\nAfter change the contents of file\n\n";
ch=f4.get();
64
while(!f4.eof())
{
cout<<ch;
ch=f4.get();
}
f4.close();
getch();
}
64
64
64
23.
STRING REVERSAL
#include<conio.h>
#include<iostream.h>
#include<stdio.h>
void main()
{
clrscr();
char A[75];
int i,j,p,l;
cout<<"\nEnter string\n";
gets(A);
cout<<"\nBefore change string is "<<A<<endl;
cout<<"\nAfter change string is ";
for(l=0;A[l]!='\0';l++);
p=l-1;
for(i=l-1;i>=0;i--)
if(A[i]==' ')
{
for(j=i+1;j<=p;j++)
cout<<A[j];
p=i-1;
cout<<" ";
}
for(i=0;i<=p;i++)
cout<<A[i];
getch();
64
24.
PALLINDROME STRING
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
int i,j;
void pall(char A[100],int l)
{
int f=0;
for(i=0,j=l-1;A[i]!='\0';i++,j--)
if(A[i]==A[j])
f++;
if(f==l)
cout<<"\nPallindrome\n";
else
cout<<"\nNot Pallindrome\n";
}
void main()
{
clrscr();
char A[100];
int l;
for(int r=1;r<=2;r++)
64
cout<<"\nEnter a string";
gets(A);
for(l=0;A[l]!='\0';l++);
pall(A,l);
}
getch();
{
clrscr();
char A[100];
int l=1,cl=0,sl=0,dig=0,spl=0;
cout<<"\nEnter a string\n";
gets(A);
for(int i=0;A[i]!
='\0';i++)
{
if(A[i]==' ')
l++;
else if(A[i]>=65
cl++;
else if(A[i]>='a'
sl++;
else if(A[i]>='0'
AND A[i]<=90)
AND A[i]<='z')
AND A[i]<='9')
64
dig++;
else
spl++;
}
cout<<"\nNumber
cout<<"\nNumber
cout<<"\nNumber
cout<<"\nNumber
cout<<"\nNumber
getch();
of
of
of
of
of
26.
LEFT DIAGONAL
#include<conio.h>
#include<iostream.h>
void main()
{
clrscr();
int A[100][100],i,j,n;
cout<<"\nEnter limit of the array\n";
cin>>n;
cout<<"\nEnter elements of 2-D array\n";
for(i=0;i<n;i++)
for(j=0;j<n;j++)
cin>>A[i][j];
for(i=0;i<n;i++)
{
cout<<endl;
for(j=0;j<n;j++)
cout<<A[i]
[j]<<"\t";
64
{
for(int s=1;s<=i;s++)
cout<<'\t';
for(j=0;j<n;j++)
if(i==j)
cout<<A[i][j]<<endl;
}
getch();
27.
RIGHT DIAGONAL
#include<conio.h>
#include<iostream.h>
void main()
{
clrscr();
int A[100]
limit of the
cin>>n;
elements of
[100],i,j,n;
cout<<"\nEnter
array\n";
cout<<"\nEnter
2-D array\n";
for(i=0;i<n;i+
+)
for(j=0;j<n;j+
+)
cin>>A[i]
+)
[j];
for(i=0;i<n;i+
64
cout<<endl;
for(j=0;j<n;j++)
cout<<A[i][j]<<"\t";
}
cout<<"\nElements of Right Diagonal Are \n\n";
for(i=0;i<n;i++)
{
for(int s=1;s<=n-1-i;s++)
cout<<'\t';
for(j=0;j<n;j++)
if(i+j==n-1)
cout<<A[i][j]<<endl;
}
getch();
28.
#include<conio.h>
for(i=0;i<n;i+
+)
64
#include<iostream.h>
int i,j,n,t,A[100][100];
cout<<endl;
void main()
for(j=0;j<n;j++)
co
ut<<A[i][j]<<'\t';
clrscr();
cout<<"\nEnter limit of array\n";
cin>>n;
cout<<"\nEnter elements of 2-D array\n";
for(i=0;i<n;i++)
for(j=0;j<n;j++)
cin>>A[i][j];
cout<<"\nOriginal Array is\n";
for(i=0;i<n;i++)
{
cout<<endl;
for(j=0;j<n;j++)
cout<<A[i][j]<<'\t';
}
for(i=0;i<n-1;i++)
for(j=i+1;j<n;j++)
{
t=A[i][j];
A[i][j]=A[j][i];
A[j][i]=t;
}
getch();
64
29.
FUNCTION OVERLOADING
64
64
30.
#include<conio.h>
#include<iostream.h>
long fact(int n)
{
if(n>1)
return n*fact(n-1);
}
void main()
{
clrscr();
int num;
for(int i=0;i<=1;i++)
{
cout<<"\nEnter a number\n";
cin>>num;
int f=fact(num);
cout<<"\nFactorial of "<<num<<" is "<<f<<endl;
}
getch();
64
31.
STRUCTURE
#include<conio.h>
#include<iostream.h>
struct Name
for(i=0;NM.lnm[i]!='\0';i++)
A[j]=' ';
j++;
char fnm[100] ;
A[j]=NM.lnm[i];
char mnm[100];
char lnm[100];
}NM;
void main()
cout<<"\nFull name is \n"<<A;
j++;
}
A[j]='\0';
getch();
char A[300];
int i,j=0;
cout<<"\nEnter first name\n";
cin>>NM.fnm;
cout<<"\nEnter middle man\n";
cin>>NM.mnm;
cout<<"\nEnter last name\n";
cin>>NM.lnm;
for(i=0;NM.fnm[i]!='\0';i++)
{
A[j]=NM.fnm[i];
j++;
}
A[j]=' ';
j++;
for(i=0;NM.mnm[i]!='\0';i++)
{
A[j]=NM.mnm[i];
j++;
64
#include<conio.h>
#include<iostream.h>
#include<stdio.h>
struct Name
{
char fnm[100],mnm[100];
char lnm[100];
};
struct Addr
{
int hno;
char area[100];
char city[100];
char state[100];
};
struct Emp
{
int empno;
Name nm;
Addr add;
float basic;
}work;
void main()
{
cout<<"\nEnter employee number\n";
cin>>work.empno;
cout<<"\nEnter first, middle and last name\n";
cin>>work.nm.fnm>>work.nm.mnm>>work.nm.lnm;
cout<<"\nEnter house no., area, city and state\n";
cin>>work.add.hno;
gets(work.add.city);
gets(work.add.area);
gets(work.add.state);
cout<<"\nEnter basic pay\n";
cin>>work.basic;
cout<<"\nEmployee No.: "<<work.empno<<"\tName : ";
cout<<work.nm.fnm<<" "<<work.nm.mnm<<" "<<work.nm.lnm;
cout<<"\nAddress : ";
cout<<work.add.hno<<", "<<work.add.city<<", ";
cout<<work.add.area<<", "<<work.add.state;
cout<<"\nBasic Pay : "<<work.basic;
64
getch();
*NESTED STRUCTURE*
64