Você está na página 1de 63

19.To Find Area of a square,a rectangle, a circle by using Function Overloading.

#include<iostream.h>
#include<conio.h>
class circle
{
public:
float p,r,a;
void input ()
{
cout<<"Ender The Value Of Radius";
cin>>r;
}
void area ()
{
p=3.15;
a=3.15*r*r;
cout<<endl<<"Area Of Circle="<<a;
}
float area (float b)
{
b=r;
a=b*b;
cout<<endl<<"Area Of Square="<<a;
return (a);
}
float area (float c,float d)
{
c=r; d=3.14;
a=2*c*d;
cout<<endl<<"Area Of Rectangle="<<a;
return (a);
}};
void main ()
{
clrscr ();
float b,c,d;
circle s;
s.input ();
s.area ();
s.area (b);
s.area (c,d);
getch ();
}
OutPut Is:-
Ender The Value Of Radius
3

Area Of Circle=28.35
Area Of Square=9
Area Of Rectangle=18.84
20.To illustrate concept Of Virtual Function.

#include<iostream.h>
#include<conio.h>
class base
{
public:
virtual void show ()
{
cout<<endl<<"Base Function";
}
virtual void display ()
{
cout<<endl<<"Base Class";
}
};
class der:public base
{
public:
virtual void display ()
{
cout<<endl<<"Derived class";
}
void show ()
{
cout<<endl<<"Derived Function";
}
};
int main ()
{
clrscr ();
base b;
der d;
base *k;
k=&b;
k->show();
k->display();
k=&d;
k->show();
k->display();
getch ();
return 0;
}
OutPut Is:-

Base Function
Base Class
Derived Function
Derived class
21.To illustrate concept Of Static Function.

#include<iostream.h>
#include<conio.h>
class stat
{
public:
int code;static int count;
void sukha ()
{
code=count++;
}
void sukha1 ()
{
cout<<endl<<"Object Number:"<<code;
}
static void display ()
{
cout<<endl<<"Count:="<<count;
}
};
int stat::count;
void main ()
{
clrscr ();
stat s,s1,s3;
s.sukha();
s1.sukha();
stat::display ();
s3.sukha ();
stat::display ();
s.sukha1 ();
s1.sukha1 ();
s3.sukha1 ();
getch ();
}

OutPut Is:-

Count:=2
Count:=3
Object Number:0
Object Number:1
Object Number:2
22.To Implement the “this” Opearator

#include<iostream.h>
#include<conio.h>
#include<string.h>
class sukha
{
public:
char n[10];
float a;
sukha (char *s,float b)
{
strcpy(n,s);
a=b;
}
sukha big (sukha x)
{
if (x.a >= a)
return (x);
else
return (*this);
}
void display ()
{
cout<<"Name:="<<n<<endl;
cout<<"Age="<<a;
}
};
void main ()
{
clrscr ();
sukha p("sukha",19.50);
sukha p1("sunny",18.00);
sukha p2("Money",19.30);
p2.big(p);
cout<<endl<<"Elder Person is=";
p.display ();
p1.big(p);
cout<<endl<<"Elder Person is=";
p.display ();
p1.big(p2);
cout<<endl<<"Elder Person is=";
p.display ();
getch ();
}
OutPut Is:-

Elder Person is=Name:=sukha


Age=19.5
Elder Person is=Name:=sukha
Age=19.5
Elder Person is=Name:=sukha
Age=19.5
23.To Write The name and roll no. of a student in a file with the concept of
Classes with objects.

#include<iostream.h>
#include<fstream.h>
#include<iomanip.h>
class sukha
{
char n[10];
int c;
float r;
public:
void input ()
{
cout<<endl<<"Enter Name";
cin>>n;
cout<<"Enter code";
cin>>c;
cout<<"Enter Cost";
cin>>r;
}
void output ()
{
cout<<endl<<"Name= "<<n;
cout<<endl<<"Code= "<<c;
cout<<endl<<"Rate= "<<r;
}
};
int main ()
{
sukha k[3]; int m;
fstream file;
file.open("Stock",ios::in|ios::out);
cout<<"Enter the No Of Items";
cin>>m;
cout<<"Enter Details for items";
for (int i=0;i<m;i++)
{
k[i].input();
file.write((char *) & k[i],sizeof (k[i]));
}
file.seekg(0);
cout<<endl<<"Output Is:-";
for (i=0;i<m;i++)
{
file.read((char *) & k[i],sizeof (k[i]));
k[i].output ();
}
file.close ();
return 0;
}

OutPut Is:-

F:\TC\BIN>fileob
Enter the No Of Items 3
Enter Details for items
Enter Name Physics
Enter code 1
Enter Cost 550

Enter Name Chemistry


Enter code 2
Enter Cost 600

Enter Name Math


Enter code 3
Enter Cost 450

Output Is:-
Name= Physics
Code= 1
Rate= 550
Name= Chemistry
Code= 2
Rate= 600
Name= Math
Code= 3
Rate= 450
24.To Insert And Delete Elements From Queue

#include<iostream.h>
#include<conio.h>
class stack
{
public:
int a[10],i,n,m;
char p;
void input ()
{
cout<<"Enter the Limit Of Array";
cin>>n;
cout<<"Enter the Elements";
for (i=0;i<n;i++)
{
cin>>a[i];
}
}
void output ()
{
cout<<"Choose The Action (I For Insertion and D For Deletion)";
cin>>p;
if (p=='d')
{
cout<<"Delete Action:-";
for (i=1;i<n;i++)
{
cout<<endl<<a[i];
}
}
else if (p=='i')
{
cout<<"Enter the Element";
cin>>m;
int k;k=n+1;
cout<<"Insert Action:-";
for (i=0;i<k;i++)
{
a[k-1]=m;
}
for (i=0;i<n+1;i++)
{
cout<<endl<<a[i];
}
}
}
};
void main ()
{
clrscr ();
stack s;
s.input ();
s.output ();
getch ();
}

OutPut Is:-

Enter the Limit Of Array


5
Enter the Elements
1
2
3
4
5
Choose The Action (I For Insertion and D For Deletion)
i
Enter the Element
6
Insert Action:-
1
2
3
4
5
6
25.To Finds The Roots of An equation using Bisection Method.

#include<iostream.h>
#include<conio.h>
#include<process.h>
float g(float t)
{
return(t*t*t-t-4);
}
class bi
{
public:
float f,f1,f2,x,x1,x2,e;
int i;
void input ()
{
cout<<"Enter the Intial approximation x1,x2";
cin>>x>>x1;
cout<<"Enter a Very Small number epsilno:";
cin>>e;
}
void output ()
{
f=g(x);
f1=g(x1);
if (f*f1>0)
{
cout<<endl<<"Intial Approximation x= "<<x<<" x1="<<x1<<"are not proper";
exit (0);
}
i=0;
do
{
x2=(x+x1)/2;
i++;
cout<<endl<<"Next Approximation after "<<i<<" iteration is "<<x2;
f2=g(x2);
if (f2<0)
{
x=x2;
}
else
{
x1=x2;
}
}
while (((x1-x)>e) && (f2!=0));
cout<<endl<<"Root Is=="<<x2;
}
};
void main ()
{
clrscr ();
bi h;
h.input ();
h.output ();
getch ();
}

OutPut Is:-

Enter the Intial approximation x1,x2


1
2
Enter a Very Small number epsilno:
0.001

Next Approximation after 1 iteration is 1.5


Next Approximation after 2 iteration is 1.75
Next Approximation after 3 iteration is 1.875
Next Approximation after 4 iteration is 1.8125
Next Approximation after 5 iteration is 1.78125
Next Approximation after 6 iteration is 1.796875
Next Approximation after 7 iteration is 1.789062
Next Approximation after 8 iteration is 1.792969
Next Approximation after 9 iteration is 1.794922
Next Approximation after 10 iteration is 1.795898
Root Is==1.795898

26.To Finds The Roots of An equation using Regula Falsi Method


#include<iostream.h>
#include<conio.h>
#include<process.h>
float g(float t)
{
return(t*t*t-t-4);
}
class bi
{
public:
float f,f1,f2,x,x1,x2,e;
int i;
void input ()
{
cout<<"Enter the Intial approximation x1,x2";
cin>>x>>x1;
cout<<"Enter a Very Small number epsilno:";
cin>>e;
}
void output ()
{
f=g(x);
f1=g(x1);
if (f*f1>0)
{
cout<<endl<<"Intial Approximation x= "<<x<<" x1="<<x1<<"are not proper";
exit (0);
}
i=0;
do
{
x2=((f*x1)-(f1*x))/(f-f1);
i++;
cout<<endl<<"Next Approximation after "<<i<<" iteration is "<<x2;
f2=g(x2);
if (f2<0)
{
x=x2;
}
else
{
x1=x2;
}
}
while (((x1-x)>e) && (f2!=0));
cout<<endl<<"Root Is=="<<x2;
}
};
void main ()
{
clrscr ();
bi h;
h.input ();
h.output ();
getch ();
}

OutPut Is:-

Enter the Intial approximation x1,x2


1
2
Enter a Very Small number epsilno:
0.001

Next Approximation after 1 iteration is 1.666667


Next Approximation after 2 iteration is 1.888889
Next Approximation after 3 iteration is 1.814815
Next Approximation after 4 iteration is 1.765432
Next Approximation after 5 iteration is 1.798354
Next Approximation after 6 iteration is 1.78738
Next Approximation after 7 iteration is 1.794696
Next Approximation after 8 iteration is 1.797135
Next Approximation after 9 iteration is 1.796322
Root Is==1.796322

27.To Finds The Roots of An equation using Newton Raphson Method


#include<iostream.h>
#include<conio.h>
#include<process.h>
float g(float t)
{
return(t*t*t-t-4);
}
float j(float t1)
{
return(3*t1*t1-1);
}
class bi
{
public:
float f,f1,f2,x,x1,x2,e;
int i,n;
void input ()
{
cout<<"Enter the Intial approximation x1";
cin>>x;
cout<<"Enter the No. Of Iterations";
cin>>n;
}
void output ()
{
f=g(x);
f1=j(x);
i=0;
for (i=0;i<n;i++)
{
x2=(x-(f/f1));
cout<<endl<<"Next Approximation after "<<i<<" iteration is "<<x2;
f=g(x2);
f1=j(x2);
x=x2;
}
cout<<endl<<"Root Is=="<<x2;
}
};
void main ()
{
clrscr ();
bi h;
h.input ();
h.output ();
getch ();
}

OutPut Is:-

Enter the Intial approximation x1


2
Enter the No. Of Iterations
5

Next Approximation after 0 iteration is 1.818182


Next Approximation after 1 iteration is 1.796613
Next Approximation after 2 iteration is 1.796322
Next Approximation after 3 iteration is 1.796322
Next Approximation after 4 iteration is 1.796322
Root Is==1.796322

28.To Interpolate a Value Using Lagrangian Interpolation Method


#include<iostream.h>
#include<conio.h>
class sukha
{
public:
float a[10],b[10],i,n,m,j,x,s,t;
void input ()
{
cout<<"Enter the limit Of Series";
cin>>n;
cout<<"Enter the Elements Of x And y(x)";
for (i=0;i<n;i++)
{
cin>>a[i]>>b[i];
}
cout<<"Enter the Value Of x";
cin>>x;
};
void output ()
{
s=0;
for (j=0;j<n;j++)
{
m=1;
for (i=0;i<n;i++)
{
if (i!=j)
{
m=m*((x-a[i])/(a[j]-a[i]));
}
}
t=b[j]*m;
s=s+t;
}
cout<<endl<<"Interpolation Is=="<<s;
}
};
void main ()
{
clrscr ();
sukha g;
g.input ();
g.output ();
getch ();
}

OutPut Is:-

Enter the limit Of Series


6
Enter the Elements Of x And y(x)
16
28
3 10
4 12
5 14
6 16
Enter the Value Of x
3.5

Interpolation Is==11

29.To Interpolate a Value Using Newton Forward Difference Method.


#include<iostream.h>
#include<conio.h>
class sukha
{
public:
float a,d[10][10],x[10],y[10],i,k,j,m,l,u,s,n,p;
void input ()
{
cout<<"Enter the Value Of N";
cin>>n;
cout<<endl<<"Enter "<<n<<" Pairs of (x,y)";
for (i=0;i<n;i++)
{
cin>>x[i]>>y[i];
}
cout<<"Enter the Value Of X to interpollate the value of Y:";
cin>>a;
}
void output ()
{
i=1;
while (a<x[i])
{
i++;
}
k=i-1;
u=((a-x[k])/(x[k+1]-x[k]));
for (j=0;j<n-1;j++)
{
for (i=0;i<n-j;i++)
{
if (j==0)
{
d[i][j]=y[i+1]-y[i];
}
else
{
d[i][j]=d[i+1][j-1]-d[i][j-1];
}
}
}
s=y[k];
for (i=0;i<n-k;i++)
{
p=1;
for (j=0;j<=i;j++)
{
p=p*(u-j)/(j+1);
s=s+d[k][i]*p;
}
}
cout<<endl<< “Interpolation Is:- “<<s;
}
};
void main ()
{
sukha o;
clrscr ();
o.input ();
o.output ();
getch ();
}

OutPut Is:-

Enter the Value Of N


5

Enter 5 Pairs of (x,y)


12
34
56
78
9 10
Enter the Value Of X to interpollate the value of Y:
2.5

Interpolation Is:- 2.777778

30.To Solve Numerical Integration using Trapezodial Rule.


#include<iostream.h>
#include<conio.h>
class tpd
{
public:
float a[10],b[10],n,m,h,c,d,e,f,g,j;
float i;
void input ()
{
cout<<"Enter the Value Of a and b";
cin>>n>>m;
cout<<"Enter the Value Of n";
cin>>c;
}
void output ()
{
cout<<"xi yi";
for (i=0;i<=c;i++)
{
h=(m-n)/c;
a[i]=(1/(1+(i*i)));
cout<<endl<<"x"<<i+1<<"="<<i<<" "<<a[i];
}
e=a[0]+a[c];
cout<<endl<<"Sum Of y1 and y"<<c+1<<"="<<e<<endl;
f=0;
cout<<"Sum Of y2 to y"<<c-1<<" is:-"<<endl;
for (i=1;i<=c-1;i++)
{
f=f+a[i];
cout<<a[i]<<"+";
}
g=f*2;
j=(h/2)*(e+g);
cout<<endl<<"Answer Is:-"<<j;
}
};
void main ()
{
clrscr ();
tpd t;
t.input ();
t.output ();
getch ();
}

OutPut is:-

Enter the Value Of a and b


1
2
Enter the Value Of n
6
xi yi
x1=0 1
x2=1 0.5
x3=2 0.2
x4=3 0.1
x5=4 0.058824
x6=5 0.038462
x7=6 0.027027
Sum Of y1 and y7=1.027027
Sum Of y2 to y5 is:-
0.5+0.2+0.1+0.058824+0.038462
Answer Is:- 0.235133

31.To Find Arithmetic Mean Of N Number.


#include<iostream.h>
#include<conio.h>
class gm
{
public:
float a[10],b[10],c[10],d[10],e[10],n[10],i,m,s,z,z1,z2;
void input ()
{
cout<<"Enter the No. of Elements";
cin>>m;
cout<<"Enter the Value of X series and f";
for (i=0;i<m;i++)
{
cin>>a[i]>>b[i]>>d[i];
}
}
void output ()
{
s=0;z=0;
cout<<" X f m fm";
for (i=0;i<m;i++)
{
s=s+d[i];
c[i]=((a[i]+b[i]))/2;
e[i]=d[i]*c[i];
z=z+e[i];
cout<<endl<<a[i]<<"-"<<b[i]<<" "<<" "<<d[i]<<" "<<c[i]<<" "<<e[i];
}
z1=z/s;
cout<<endl<<"The Value of N is="<<s;
cout<<endl<<"The Sum Of fm is="<<z;
cout<<endl<<"Arithmetic Mean is="<<z1;
}
};
void main ()
{
clrscr ();
gm g;
g.input();
g.output ();
getch ();
}

OutPut is:-
Enter the No. of Elements
5
Enter the Value of X series and f
10 20 2
20 30 3
30 40 4
40 50 5
50 60 6
X f m fm
10-20 2 15 30
20-30 3 25 75
30-40 4 35 140
40-50 5 45 225
50-60 6 55 330
The Value of N is=20
The Sum Of fm is=800
Arithmetic Mean is=40

32.To Find Geometric Mean Of N Number.


#include<iostream.h>
#include<conio.h>
#include<math.h>
class gm
{
public:
float a[10],b[10],c[10],d[10],e[10],n[10],i,m,s,z,z1,z2;
void input ()
{
cout<<"Enter the No. of Elements";
cin>>m;
cout<<"Enter the Value of X series and f";
for (i=0;i<m;i++)
{
cin>>a[i]>>b[i]>>d[i];
}
}
void output ()
{
s=0;z=0;
cout<<" X f m logm flogm";
for (i=0;i<m;i++)
{
s=s+d[i];
c[i]=((a[i]+b[i]))/2;
n[i]=log10(c[i]);
e[i]=n[i]*d[i];
z=z+e[i];
cout<<endl<<a[i]<<"-"<<b[i]<<" "<<" "<<d[i]<<" "<<c[i]<<" "<<n[i]<<" "<<e[i];
}
z2=z/s;
cout<<endl<<"Value Of N="<<s;
z1=exp(z2*log(10));
cout<<endl<<"Sum Of fLog(m) is=="<<z;
cout<<endl<<"G.M is:-Antilog("<<z2<<")=="<<z1;
}
};
void main ()
{
clrscr ();
gm g;
g.input();
g.output ();
getch ();
}
OutPut Is:-

Enter the No. of Elements


5
Enter the Value of X series and f
012
123
234
345
456
X f m logm flogm
0-1 2 0.5 -0.30103 -0.60206
1-2 3 1.5 0.176091 0.528274
2-3 4 2.5 0.39794 1.59176
3-4 5 3.5 0.544068 2.72034
4-5 6 4.5 0.653212 3.919275
Value Of N=20
Sum Of fLog(m) is==8.157589
G.M is:-Antilog(0.407879)==2.557876

33.To Find Harmonic Mean Of N Number.


#include<iostream.h>
#include<conio.h>
class gm
{
public:
float a[10],b[10],c[10],d[10],e[10],n[10],i,m,s,z,z1,z2;
void input ()
{
cout<<"Enter the No. of Elements";
cin>>m;
cout<<"Enter the Value of X series and f";
for (i=0;i<m;i++)
{
cin>>a[i]>>b[i]>>d[i];
}
}
void output ()
{
s=0;z=0;
cout<<"X f m f/m";
for (i=0;i<m;i++)
{
s=s+d[i];
c[i]=((a[i]+b[i]))/2;
e[i]=d[i]/c[i];
z=z+e[i];
cout<<endl<<a[i]<<"-"<<b[i]<<" "<<" "<<d[i]<<" "<<c[i]<<" "<<e[i];
}
z1=s/z;
cout<<endl<<"The Value of N is="<<s;
cout<<endl<<"The Sum Of f/m is="<<z;
cout<<endl<<"Harmonic Mean is="<<z1;
}
};
void main ()
{
clrscr ();
gm g;
g.input();
g.output ();
getch ();
}

OutPut Is:-
Enter the No. of Elements
5
Enter the Value of X series and f

10 20 2
20 30 5
30 40 4
40 50 6
50 60 7
X f m f/m
10-20 2 15 0.133333
20-30 5 25 0.2
30-40 4 35 0.114286
40-50 6 45 0.133333
50-60 7 55 0.127273
The Value of N is=24
The Sum Of f/m is=0.708225
Harmonic Mean is=33.887531

34.To Find Median Of a list Of Elements.


#include<iostream.h>
#include<conio.h>
class sukha
{
public:
int a[20],b[20],c[20],e[10],i,n,d,g,h,z,m;
void input ()
{
cout<<"Enter the Value Of N";
cin>>n;
cout<<"Enter the Value of x and f";
for (i=0;i<n;i++)
{
cin>>a[i]>>b[i]>>c[i];
}
}
void output ()
{
d=0;e[0]=c[0];
cout<<" X f c.f";
for (i=0;i<n;i++)
{
d=d+c[i];
e[i]=e[i-1]+c[i];
cout<<endl<<a[i]<<"-"<<b[i]<<" "<<c[i]<<" "<<e[i];
}
g=d/2;
cout<<endl<<"Value of N/2 is= "<<g;
z=0;
for(i=0;e[i]<g;i++)
{
z++;
}
cout<<endl<<"Model Class Is="<<a[z]<<"-"<<b[z];
cout<<endl<<"The Value Of l is="<<a[z];
cout<<endl<<"Value Of c.f is="<<e[z-1];
cout<<endl<<"Value Of f is="<<c[z];
m=a[z]+(((g-e[z-1])*(b[z]-a[z]))/c[z]);
cout<<endl<<"Median Is=="<<m;
}
};
void main ()
{
clrscr ();
sukha s;
s.input ();
s.output ();
getch ();
}

OutPut Is:-

Enter the Value Of N


5
Enter the Value of x and f
10 20 1
20 30 2
30 40 3
40 50 4
50 60 5
X f c.f
10-20 1 1
20-30 2 3
30-40 3 6
40-50 4 10
50-60 5 15
Value of N/2 is= 7
Model Class Is=40-50
The Value Of l is=40
Value Of c.f is=6
Value Of f is=4
Median Is==42

35. To Find Mode Of a list Of Elements.


#include<iostream.h>
#include<conio.h>
class sukha
{
public:
float a[20],b[20],c[20],e[10],i,n,d,g,h,z,z1,m,h1;
void input ()
{
cout<<"Enter the Value Of N";
cin>>n;
cout<<"Enter the Value of x and f";
for (i=0;i<n;i++)
{
cin>>a[i]>>b[i]>>c[i];
}
}
void output ()
{
d=0;
cout<<" X f";
for (i=0;i<n;i++)
{
cout<<endl<<a[i]<<"-"<<b[i]<<" "<<c[i]<<" ";
}
g=n/2;
cout<<endl<<"Value of N/2 is= "<<g;
cout<<endl<<"Model Class Is="<<a[g]<<"-"<<b[g];
cout<<endl<<"The Value Of l is="<<a[g];
cout<<endl<<"Value Of f0 is="<<c[g-1];
cout<<endl<<"Value Of f1 is="<<c[g];
cout<<endl<<"Value Of f2 is="<<c[g+1];
z=(c[g]-c[g-1])+(c[g]-c[g+1]);
m=((c[g]-c[g-1])*(b[0]-a[0]));
h=m/z;
h1=a[g]+h;
cout<<endl<<"Mode Is=="<<h1;
}
};
void main ()
{
clrscr ();
sukha s;
s.input ();
s.output ();
getch ();
}
OutPut Is:-

Enter the Value of x and f


0 10 5
10 20 15
20 30 30
30 40 55
40 50 85
50 60 60
60 70 45
70 80 25
X f
0-10 5
10-20 15
20-30 30
30-40 55
40-50 85
50-60 60
60-70 45
70-80 25
Value of N/2 is= 4
Model Class Is=40-50
The Value Of l is=40
Value Of f0 is=55
Value Of f1 is=85
Value Of f2 is=60
Mode Is==45.454544

36. To Find Mean Deviation.

#include<iostream.h>
#include<conio.h>
class md
{
public:
int a[10],b[10],n,i,d,f,sum;
float s,s1;
void input ()
{
cout<<"Enter the Value of Series";
cin>>n;
cout<<"Enter the Elements of Series";
for (i=0;i<n;i++)
{
cin>>a[i];
}
}
void output ()
{
sum=0;
for (i=0;i<n;i++)
{
sum=sum+a[i];
}
d=sum/n;
cout<<endl<<"Mean "<<d;
cout<<endl<<"Deviations Taken From Mean";
for (i=0;i<n;i++)
{
b[i]=d-a[i];
if (b[i]<0)
b[i]=-b[i];
s1=s1+b[i];
cout<<endl<<b[i];
}
cout<<endl<<"Sum Of Deviations "<<s1;
s=s1/n;
cout<<endl<<"Mean Deviation=="<<s;
}
};
void main ()
{
clrscr ();
md k;
k.input ();
k.output ();
getch ();
}

OutPut Is:-

Enter the Value of Series


5
Enter the Elements of Series
1
3
4
5
6

Mean 3
Deviations Taken From Mean
2
0
1
2
3
Sum Of Deviations 8
Mean Deviation==1.6

37. To Find Standard Deviation.

#include<iostream.h>
#include<conio.h>
#include<math.h>
class md
{
public:
float a[10],b[10],n,i,d,f,sum;
float s,s1;
void input ()
{
cout<<"Enter the Value of Series";
cin>>n;
cout<<"Enter the Elements of Series";
for (i=0;i<n;i++)
{
cin>>a[i];
}
}
void output ()
{
sum=0;
for (i=0;i<n;i++)
{
sum=sum+a[i];
}
d=sum/n;
cout<<endl<<"Mean="<<d;
cout<<endl<<"Deviations Taken From Mean";
for (i=0;i<n;i++)
{
b[i]=pow(a[i]-d,2);
s1=s1+b[i];
cout<<endl<<b[i];
}
cout<<endl<<"Sum Of Deviations "<<s1;
s=sqrt(s1/n);
cout<<endl<<"Mean Deviation=="<<s;
}
};
void main ()
{
clrscr ();
md k;
k.input ();
k.output ();
getch ();
}
OutPut Is:-

Enter the Value of Series


5
Enter the Elements of Series
1
2
3
6
5

Mean=3.4
Deviations Taken From Mean
5.76
1.96
0.16
6.759999
2.56
Sum Of Deviations 17.199999
Mean Deviation==1.854724

38.To Find Coefficient Of Correlation.

#include<iostream.h>
#include<conio.h>
#include<math.h>
class cor
{
public:
float a[10],b[10],g[10],h[10],j[10],n,m,i,i1,c,c1;
float d,d1,s,s1,e[10],f[10],y,z,r;
void input ()
{
cout<<"Enter the Value For X series and Y Series";
cin>>n;
cout<<"Enter the Elements of X And Y Series";
for (i=0;i<n;i++)
{
cin>>a[i]>>b[i];
}
}
void output ()
{
s=0;
for (i=0;i<n;i++)
{
s=s+a[i];
}
d=s/n;
s1=0;
for (i=0;i<n;i++)
{
s1=s1+b[i];}
d1=s1/n;
cout<<"X Y x(square)("<<d<<")"<<" "<<"y(square)("<<d1<<")"<<" "<<"xy"<<endl;
i1=0;c1=0,m=0;
for (i=0;i<n;i++)
{
g[i]=a[i]-d;
e[i]=pow(a[i]-d,2);
i1=i1+e[i];
h[i]=b[i]-d1;
f[i]=pow(b[i]-d1,2);
c1=c1+f[i];
j[i]=g[i]*h[i];
m=m+j[i];
cout<<a[i]<<" "<<" "<<b[i]<<" "<<e[i]<<" "<<f[i]<<" "<<j[i]<<endl;
}
y=sqrt(i1);z=sqrt(c1);r=m/(y*z);
cout<<endl<<"Sum Of X Series="<<s;
cout<<endl<<"Sum Of Y Series="<<s1;
cout<<endl<<"Sum Of x(square) Series="<<i1;
cout<<endl<<"Sum Of y(square) Series="<<c1;
cout<<endl<<"Coefficient of Correlation=="<<r;
}};
void main ()
{
clrscr ();
cor f;
f.input ();
f.output ();
getch ();
}

OutPut Is:-

Enter the Value For X series and Y Series


5
Enter the Elements of X And Y Series
10 20
30 12
20 13
42 12
32 12
X Y x(square)(26.799999) y(square)(13.8) xy
10 20 282.23996 38.439999 -104.159988
30 12 10.240005 3.240001 -5.760002
20 13 46.23999 0.64 5.440001
42 12 231.040024 3.240001 -27.360004
32 12 27.040009 3.240001 -9.360003

Sum Of X Series=134
Sum Of Y Series=69
Sum Of x(square) Series=596.799927
Sum Of y(square) Series=48.800003
Coefficient of Correlation==-0.82739

39.To illustrate concept Of Polymorphism

#include<iostream.h>
#include<conio.h>
class sukha
{
public:
int a,b;
void input ()
{
cout<<"Enter the Value Of A and B";
cin>>a>>b;
}
virtual void output ()
{
cout<<endl<<"A="<<a<<endl<<"B="<<b;
}
};
class sukha1:public sukha
{
public:
int c;
void output ()
{
cout<<endl<<"In Derived Class"<<endl;
}
void sum ()
{
c=a+b;
cout<<endl<<"Sum Is="<<c;
}
};
void main ()
{
clrscr ();
sukha *s,s1;
sukha1 k;
s=&s1;
s->input();
s->output();
k.output();
((sukha1 *)s)->sum();
getch ();
}
OutPut Is:-

Enter the Value Of A and B


1
2
A=1
B=2
In Derived Class

Sum Is=3

40.To find Solution Of Simultaneous equations using Guass Elimination Method.

#include<iostream.h>
#include<conio.h>
#include<process.h>
class sukha
{
public:
float n,m,i,j,k,a[10][10],x[10],s,t,e,b,u;
void input ()
{
cout<<"Enter the No. of Equation";
cin>>n;
for (i=0;i<n;i++)
{
for (j=0;j<n+1;j++)
{
cin>>a[i][j];
}
}
}
void output ()
{
for (k=0;k<n-1;k++)
{
if(a[k][k]==0)
{
cout<<endl<<"Division by Zero";
exit (0);
}
for (i=k+1;i<n;i++)
{
u=a[i][k]/a[k][k];
for (j=0;j<n+1;j++)
a[i][j]=a[i][j]-(u*a[k][j]);
}
}
for (i=n-1;i>=0;i--)
{
s=0;
for (j=i+1;j<n;j++)
s=s+a[i][j]*x[j];
x[i]=(a[i][n]-s)/a[i][i];
}
cout<<endl<<"Solution Of System Of Linear Equation";
for (i=0;i<n;i++)
{
cout<<endl<<"x["<<i+1<<"]="<<x[i];
}
}
};
void main ()
{
clrscr ();
sukha g;
g.input ();
g.output ();
getch ();
}

OutPut Is:-

Enter the No. of Equation


3
2 -3 1 -1
1 4 5 25
3 -4 1 2

Solution Of System Of Linear Equation


x[1]=8.699999
x[2]=5.7
x[3]=-1.3

41.To find Solution Of Simultaneous equations using Guass Jorden Method.

#include<iostream.h>
#include<conio.h>
#include<process.h>
class sukha
{
public:
float n,m,i,j,k,a[10][10],x[10],s,t,e,b,u;
void input ()
{
cout<<"Enter the No. of Equation";
cin>>n;
for (i=0;i<n;i++)
{
for (j=0;j<n+1;j++)
{
cin>>a[i][j];
}
}
}
void output ()
{
for (k=0;k<n;k++)
{
if(a[k][k]==0)
{
cout<<endl<<"Division by Zero";
exit (0);
}
t=a[k][k];
for (j=k;j<n+1;j++)
a[k][j]=a[k][j]/t;
for (i=0;i<n;i++)
{
if (i!=k)
{
u=a[i][k];
for (j=k;j<n+1;j++)
a[i][j]=a[i][j]-(u*a[k][j]);
}
}
}
cout<<endl<<"Solution Of System Of Linear Equation";
for (i=0;i<n;i++)
{
x[i]=a[i][n];
cout<<endl<<"x["<<i+1<<"]="<<x[i];
}
}
};
void main ()
{
clrscr ();
sukha g;
g.input ();
g.output ();
getch ();
}

OutPut Is:-
Enter the No. of Equation
3
2 -3 1 -1
1 4 5 25
3 -4 1 2

Solution Of System Of Linear Equation


x[1]=8.7
x[2]=5.7
x[3]=-1.3

42. To find Solution Of Simultaneous equations using Guass Seidel Method.

#include<iostream.h>
#include<conio.h>
#include<process.h>
class sukha
{
public:
float n,m,i,j,k,a[10][10],x[10],s,t,e,b;
void input ()
{
cout<<"Enter the No. of Equation";
cin>>n;
for (i=0;i<n;i++)
{
for (j=0;j<n+1;j++)
{
cin>>a[i][j];
}
}
cout<<endl<<"Enter the Max. No Iterations";
cin>>m;
cout<<endl<<"Enter the Very Small No. Of epsilon:";
cin>>e;
}
void output ()
{
for (i=0;i<n;i++)
x[i]=0;
for (k=1;k<=m;k++)
{
b=0;
for (i=0;i<n;i++)
{
s=0;
for (j=0;j<n;j++)
{
if (i!=j)
s=s+a[i][j]*x[j];
}
t=(a[i][n]-s)/a[i][i];
e=((t-x[i])/t);
if (e>b)
b=e;
x[i]=t;
}
if (b<=e)
{
cout<<endl<<"Solution Converge After "<<k<<" iteration";
for (i=0;i<n;i++)
cout<<endl<<"x["<<i+1<<"]="<<x[i];
}
}
}
};
void main ()
{
clrscr ();
sukha g;
g.input ();
g.output ();
getch ();
}

OutPut Is:-
Enter the No. of Equation
3
5 2 1 12
1 4 2 15
1 2 5 20
Enter the Max. No Iterations
15
Enter the Very Small No. Of epsilon
0.01

Solution Converge After 1 iteration


x[1]=2.4
x[2]=3.15
x[3]=2.26
Solution Converge After 2 iteration
x[1]=0.688
x[2]=2.448
x[3]=2.8832
Solution Converge After 11 iteration
x[1]=1
x[2]=2
x[3]=3
Solution Converge After 12 iteration
x[1]=1
x[2]=2
x[3]=3
Solution Converge After 14 iteration
x[1]=1
x[2]=2
x[3]=3
Solution Converge After 15 iteration
x[1]=1
x[2]=2
x[3]=3

43.To Fit A Polynomial Curve.

#include<iostream.h>
#include<conio.h>
class sukha
{
public:
float i,n,x[10],y[10],s,s1,s2,s3,d,d1,d2,a,b;
void input ()
{
cout<<"Enter the Value Of N";
cin>>n;
cout<<endl<<"Enter "<<n<<" Pairs Of x y";
s=s1=s2=s3=0;
for (i=0;i<n;i++)
{
cin>>x[i]>>y[i];
}
}
void output ()
{
for (i=0;i<n;i++)
{
s=s+x[i];
s1=s1+y[i];
s2=s2+(x[i]*x[i]);
s3=s3+(x[i]*y[i]);
}
d=(n*s2)-(s*s);
d1=(s1*s2)-(s3*s);
d2=(n*s3)-(s*s1);
a=d1/d;
b=d2/d;
cout<<endl<<"A= "<<a<<endl<<"B= "<<b;
cout<<endl<<"Straight Line Is Of Form"<<endl<<"Y= "<<a<<"+"<<b<<" X";
}
};
void main ()
{
clrscr ();
sukha h;
h.input();
h.output();
getch ();
}
OutPut Is:-

Enter the Value Of N


5

Enter 5 Pairs Of x y
19
29
3 10
4 12
5 11

A= 8.1
B= 0.7
Straight Line Is Of Form
Y= 8.1+0.7 X

44.To Illustrate The Concept Of Friend Function.

#include<iostream.h>
#include<conio.h>
class pri
{
int a,b;
public:
void input ()
{
cout<<"Enter the Value of A and B";
cin>>a>>b;
}
friend int output (pri f);
};
int output (pri f)
{
return int(f.a+f.b);
}
void main ()
{
clrscr ();
pri j;
j.input();
cout<<"Sum Is="<<output(j);
getch ();
}

OutPut Is:-

Enter the Value of A and B


5
6
Sum Is=11

45.To Insert And Delete Elements From Stack

#include<iostream.h>
#include<conio.h>
class stack
{
public:
int a[10],i,n,m;
char p;
void input ()
{
cout<<"Enter the Limit Of Array";
cin>>n;
cout<<"Enter the Elements";
for (i=0;i<n;i++)
{
cin>>a[i];
}
}
void output ()
{
cout<<"Choose The Action (I For PUSH and D For POP)";
cin>>p;
if (p=='d')
{
cout<<"POP Action:-";
for (i=0;i<n-1;i++)
{
cout<<endl<<a[i];
}
}
else if (p=='i')
{
cout<<"Enter the Element";
cin>>m;
cout<<"Push Action:-";
for (i=0;i<n;i++)
{
a[n]=m;
n=n+1;
}
for (i=0;i<n-1;i++)
{
cout<<endl<<a[i];
}
}
}
};
void main ()
{
clrscr ();
stack s;
s.input ();
s.output ();
getch ();
}

OutPut Is:-

Enter the Limit Of Array


5
Enter the Elements
1
3
6
5
4
Choose The Action (I For PUSH and D For POP)
i
Enter the Element
7
Push Action:-
1
3
6
5
4
7

46.To Solve Numarical Differentiation

#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<iomanip.h>
class sukha
{
public:
float a,d[20][20],x[20],y[20],i,k,j,m,l,u,s,n,p;
void input ()
{
cout<<"Enter the Value Of N";
cin>>n;
cout<<endl<<"Enter "<<n<<" Pairs of (x,y)";
for (i=0;i<n;i++)
{
cin>>x[i]>>y[i];
}
cout<<"Enter the Value Of X to interpollate the value of Y:";
cin>>a;
}
void output ()
{
i=1;
while (a<x[i])
{
i++;
}
k=i-1;
float h=x[1]-x[0];
double z=0;
for (j=0;j<n-1;j++)
{
for (i=0;i<n-j;i++)
{
if (j==0)
{
d[i][j]=y[i+1]-y[i];
}
else
{
d[i][j]=d[i+1][j-1]-d[i][j-1];
}
}
z+=pow(-1,j)*d[k][j];
}

double dy;
cout<<setprecision(3);
dy=z/h;
cout<<endl<<"Differentiation="<<dy;

}
};
void main ()
{
sukha o;
clrscr ();
o.input ();
o.output ();
getch ();
}

OutPut Is:-

Enter the Value Of N


3

Enter 3 Pairs of (x,y)


10 20
15 25
20 30
Enter the Value Of X to interpollate the value of Y:
15.5

Differentiation=1

47.To Show Different Error Messages By Using Error Handling Function in Files.

#include<fstream.h>
#include<stdlib.h>
int main()
{
void report(ofstream &);
ofstream file;
file.open("sample.exe",ios::noreplace);
if(!file)
{
report (file);
exit(1);
}
else
{
}
file.close();
return 0;
}
void report(ofstream &file)
{
cout<<"Unalbe to open SAMPLE.EXE"<<endl;
cout<<"good()="<<file.good()<<endl;
cout<<"bad()="<<file.bad()<<endl;
cout<<"fail()="<<file.fail()<<endl;
cout<<"eof()="<<file.eof()<<endl;
}

OutPut Is:-

F:\TC\BIN>26
Unalbe to open SAMPLE.TXT
good()=0
bad()=4
fail()=4
eof()=0

48.To Create and Implement various operations on a Linked List

#include<iostream.h>
#include<conio.h>
class linklist
{
private:
struct node
{
int info;
node *link;
}*l;
public:
linklist()
{
l=NULL;
}
void append(int num);
void addatbeg(int num);
void addafter(int c,int num);
void del(int num);
void display();
int count();
~linklist();
};
void linklist :: append(int num)
{
node *q,*t;
if (l==NULL)
{
l=new node;
l->info=num;
l->link=NULL;
}
else
{
q=l;
while(q->link!=NULL)
q=q->link;
t=new node;
t->info=num;
t->link=NULL;
q->link;
}
}
void linklist :: addatbeg(int num)
{
node *q;
q=new node;
q->info=num;
q->link=l;
l=q;
}
void linklist :: addafter(int c,int num)
{
node *q,*t;
int i;
for (i=0,q=l;i<c;i++)
{
q=q->link;
if (q==NULL)
{
cout<<"There are Less than "<<c<<"Elements"<<endl;
return;
}
}
t=new node;
t->info=num;
t->link=q->link;
q->link=t;
}
void linklist :: del(int num)
{
node *q,*r;
q=l;
if (q->info==num)
{
l=q->link;
delete q;
return;
}
r=q;
while(q!=NULL)
{
if(q->info==num)
{
r->link=q->link;
delete q;
return;
}
r=q;
q=q->link;
}
cout<<endl<<"Element"<<num<<"not found"<<endl;
}
void linklist :: display()
{
node *q;
cout<<endl;
for (q=l;q!=NULL;q=q->link)
cout<<endl<<q->info;
}
int linklist :: count()
{
node *q;int c=0;
for (q=l;q!=NULL;q=q->link)
c++;
return (c);
}
linklist :: ~linklist()
{
node *q;
if (l==NULL)
return;
while(l!=NULL)
{
q=l->link;
delete l;
l=q;
}
}
void main()
{
linklist ll;
clrscr();
cout<<" Number of Element in Linked list::::::"<<ll.count();
ll.append(1);
ll.append(2);
ll.append(3);
ll.append(4);
ll.append(5);
ll.append(6);
cout<<endl<<"Number of Element in linked list After Appending::::::"<<ll.count();
ll.display();
cout<<endl;
ll.addatbeg(10);
ll.addatbeg(20);
ll.addatbeg(30);
ll.addatbeg(40);
cout<<endl<<"Number of Element in linked list after Adding at the
Begining::::::"<<ll.count()<<endl;
ll.display();
ll.addafter(3,600);
ll.addafter(6,600);
cout<<endl<<"Number of Elements in linked list after Adding in the End:::::::"<<ll.count();
ll.display();
ll.del(30);
ll.del(6);
ll.del(0);
cout<<endl<<"Number of Elements in linked list After Deletion::::::"<<ll.count();
ll.display();
getch();
}

OutPut Is:-

Number of Element in Linked list::::::0


Number of Element in linked list After Appending::::::1

Number of Element in linked list after Adding at the Begining::::::5


40
30
20
10
1There are Less than 6Elements

Number of Elements in linked list after Adding in the End:::::::6


40
30
20
10
600
1
Element6not found

Element0not found

Number of Elements in linked list After Deletion::::::5

40
20
10
600
1
49.To Illustrate the example of New And Delete Operators.

#include<iostream.h>
#include<conio.h>
class Base
{
private:
int a,b,sum;
public:
void getdata();
void putdata();
void Sum();
};
void Base :: getdata()
{
cout<<"Enter value of A and b";
cin>>a>>b;
}
void Base :: putdata()
{
cout<<"Sum=="<<sum;
}
void Base :: Sum()
{
sum=a+b;
}
void main()
{
Base *pt;
clrscr();
pt=new Base;
pt->getdata();
pt->Sum();
pt->putdata();
delete pt;
getch();
}

OutPut Is:-
Enter value of A and b
23
20
Sum==43

Você também pode gostar