else if(coeff ==0)
cout<<" There is no correlation between X and Y\n";
else if (coeff<0)
cout<<" There is negative correlation between X and Y\n";
else if (coeff>0)
cout<<"There is positive correlation between X and Y\n";
}
else
cout<<"There seems to be a mistake in the data provided since the value of coefficient of correlation does not lie between -1 and 1";
break;
}
default:
{ outtextxy(30,midy +100," Sorry, you have entered the wrong choice");
getch();
cleardevice();
corre();
break;
}
}
getch();
cleardevice();
int z=1;
while(z==1||z==2)
{
cout<<"\n\n\n\n\nPress 1 to return to previos menu";
cout<<"\nPress 2 to exit";
cin>>z;
if(z==1)
menu1();
else if(z==2)
exit(0);
else cout<<"Wrong choice";
}
}
void regress()
{ int n;
float cxy;
initialize();
settextstyle(5, HORIZ_DIR, 0);
setusercharsize(1, 1, 1, 1);
outtextxy(10,midy,"What type of data do you want to enter");
outtextxy(20,midy+30,"1.Discrete data of x and y values\n");
outtextxy(20,midy+60,"2.Data of all summations\n");
cin>>choice7;
// return (choice5);
closegraph();
switch(choice7)
{
case 1:
{
cout<<" Enter the total no of data";
cin>>n;
for(int i=0;i<n;i++)
{ cout<<"X"<<i+1<<" ";
cin>>a[i];
cout<<"Y"<<i+1<<" ";
cin>>b[i];
}
clrscr();
for(i=0;i<n;i++)
{
z1 +=a[i];
z2 +=b[i];
}
mx = z1/n;
my = z2/n;
for( i=0;i<n;i++)
{
z3 += ((a[i]-mx)*(b[i]-my));
z4 += pow((a[i]-mx),2);
z5 += pow((b[i]-my),2);
}
cxy = z3/n;
vx = z4/n;
vy = z5/n;
byx = cxy/vx;
bxy = cxy/vy;
cout<<setw(5)<<"X"<<setw(5)<<" Y"<<endl;
for(i=0;i<n;i++)
{
cout<<setw(5)<<a[i]<<setw(5)<<b[i]<<endl;
}
cout<<"The Line Of Regression of Y on X is \n";
cout<<"\t Y - "<<my<<" = "<<byx<<"( X -"<<mx<<" )";
cout<<endl;
cout<<"The Line Of Regression of X on Y is \n";
cout<<"\t X - "<<mx<<" = "<<bxy<<"( Y -"<<my<<" )";
cout<<endl;
cout<<"\n\nWould you like to estimate values of y or x based on the above equations\n";
cout<<"1. to estimate Y press 1\n";
cout<<"2. To estimate X press 2\n";
cout<<"3. Exit and return to previous menu press 3\n";
cout<<"enter choice?";
cin>>choice8;
clrscr();
float ex,ey;
if(choice8 == 1)
{ char ch = 'y';
while(ch=='y')
{
cout<<" enter the value of X";
cin>>ex;
ey = (byx*(ex- mx)) + my;
cout<<" The estimated value of Y = "<<ey<<endl;
cout<<" do you want to continue";
cin>>ch;
}
}
else if(choice8 == 2)
{ char ch = 'y';
while(ch=='y')
{
cout<<" enter the value of Y";
cin>>ey;
ey = (bxy*(ey- my)) + mx;
cout<<" The estimated value of X = "<<ey<<endl;
cout<<" do you want to continue";
cin>>ch;
}
}
else
break;
break;
}
case 2:
{
cout<<"Enter the total no of data ";
cin>>n;
cout<<" Enter the value of sum of x ";
cin>>z1;
cout<<" Enter the value of sum of y ";
cin>>z2;
cout<<"Enter the value of sum of products of x znd y ";
cin>>z3;
cout<<" Enter the value of sum of squares of x ";
cin>>z4;
cout<<"Enter the values of sum of squares of y ";
cin>>z5;
byx = (n*z3-z1*z2)/(n*z4 - pow(z1,2));
bxy = (n*z3-z1*z2)/(n*z5 - pow(z2,2));
mx = z1/n;
my = z2/n;
clrscr();
cout<<"The sum of x = "<<z1<<endl;
cout<<" The sum of y = "<<z2<<endl;
cout<<" The sum of product of x and y = "<<z3<<endl;
cout<<" The sum of squares of x = "<<z4<<endl;
cout<<" The sum of squares of y = "<<z5<<endl;
cout<<"\n\nThe Line Of Regression of Y on X is \n";
cout<<"\t Y - "<<my<<" = "<<byx<<"( X -"<<mx<<" )";
cout<<endl;
cout<<"The Line Of Regression of X on Y is \n";
cout<<"\t X - "<<mx<<" = "<<bxy<<"( Y -"<<my<<" )";
cout<<endl;
cout<<"\n\nWould you like to estimate values of y or x based on the above equations\n";
cout<<"1. to estimate Y press 1\n";
cout<<"2. To estimate X press 2\n";
cout<<"3. Exit and return to previous menu press 3\n";
cout<<"enter choice?";
cin>>choice8;
clrscr();
float ex,ey;
if(choice8 == 1)
{ char ch = 'y';
while(ch=='y')
{
cout<<" enter the value of X";
cin>>ex;
ey = (byx*(ex- mx)) + my;
cout<<" The estimated value of Y = "<<ey<<endl;
cout<<" do you want to continue";
cin>>ch;
}
}
else if(choice8 == 2)
{ char ch = 'y';
while(ch=='y')
{
cout<<" enter the value of Y";
cin>>ey;
ey = (bxy*(ey- my)) + mx;
cout<<" The estimated value of X = "<<ey<<endl;
cout<<" do you want to continue";
cin>>ch;
}
}
else
break;
break;
}
default:
{
cout<<" Sorry wrong choice";
clrscr();
getch();
regress();
break;
}
}
int z=1;
while(z==1||z==2)
{
cout<<"\n\n\n\n\nPress 1 to return to previos menu";
cout<<"\nPress 2 to exit";
cin>>z;
if(z==1)
menu1();
else if(z==2)
exit(0);
else cout<<"Wrong choice";
}
}
void curvefit()
{ int n;
cout<<" Enter the total no of points ";
cin>>n;
cout<<"Enter the values of x and y coordinates of the points\n";
float a[100],b[100];
for( int i=0;i<n;i++)
{
cout<<" X"<<i+1<<" = ";
cin>>a[i];
cout<<" Y"<<i+1<<" = ";
cin>>b[i];
}
long float aa,bb;
cout<<"\nENTER THE TYPE EQUATION YOU WISH TO CURVE FIT";
cout<<"\nFOR LINEAR FORM, y = ax + b,INPUT 2";
cout<<"\nFOR QUADRATIC FORM, y= ax^2 + bx + c,INPUT 3";
cout<<" \nENTER TYPE ?";
cin>>choice6;
switch(choice6)
{
case 2:
{
for(i=0;i<n;i++)
{
z1 += a[i];
z2 += b[i];
z3 += a[i]*b[i];
z4 += pow(a[i],2);
z5 += pow(b[i],2);
}
float mex = z1/n;
float mey = z2/n;
float cyx = ((z3/n) - mex*mey);
float vx = ((z4/n) - pow(mex,2));
float vy = ((z5/n) - pow(mey,2));
aa = cyx/vx;
bb = mey - mex*aa;
cout<<"\n\n\n a = "<<aa<<"\t b ="<<bb<<endl;
getch();
clrscr();
initialize();
settextstyle(7,HORIZ_DIR,0);
outtextxy(50,30,"BEST CURVE FIT DIAGRAM");
line(50,400,600,400);
line(50,400,50,50);
outtextxy(556,410,"x");
settextstyle(7, VERT_DIR,0);
outtextxy(10,375,"y");
settextstyle(7, HORIZ_DIR,0);
for(i=0;i<n;i++)
{ int x1 = a[i]+50;
int y1 = 400 - b[i];
setfillstyle(SOLID_FILL,14);
setcolor(14);
circle(x1,y1,2);
floodfill(x1,y1,14);
}
setcolor(WHITE);
int x2,y2;
line(50,400,600,400);
line(50,50,50,400);
moveto(50,400);
float y;
for( int i=0;i<198;i++)
{
y = bb + aa*i;
x2 = i+50;
y2 = 400-y;
lineto(x2,y2);
}
break;
}
case 3:
{
for(i=0;i<n;i++)
{
z1 += a[i];
z2 += b[i];
z3 += a[i]*b[i];
z4 += pow(a[i],2)*b[i];
z5 += pow(a[i],2);
z6 += pow(a[i],3);
z7 += pow(a[i],4);
}
long double dx1 = z4*((n*z5)-pow(z1,2));
long double dx2 = z6*((n*z3)-(z1*z2));
long double dx3 = z5*((z3*z1)- (z5 *z2));
long double dx = dx1 - dx2 + dx3;
long double d1 = z7*((n* z5)- pow(z1,2));
long double d2 = z6 *((n*z6)- (z1*z5));
long double d3 = z5*((z6*z1) - pow(z5,2));
long double d = d1-d2 +d3;
long double dy1 = z7*((n*z3) - (z1*z2));
long double dy2 = z6*((n*z6) - (z1*z5));
long double dy3 = z5*((z6*z1)- pow(z5,2));
long double dy = dy1-dy2+dy3;
long double dz1 = z7*((z2*z5) - (z1*z3));
long double dz2 = z6*((z2*z6)- (z1*z3));
long double dz3 = z4*((z6*z1)- pow(z5,2));
long double dz = dz1-dz2+dz3;
long double aa = dx/d;
long double bb = dy/d;
long double cc = dz/d;
cout<<"\n\n\n a = "<<aa<<"\t b = "<<bb<<"\t c = "<<cc<<endl;
getch();
clrscr();
initialize();
settextstyle(7,HORIZ_DIR,0);
outtextxy(50,30,"BEST CURVE FIT DIAGRAM");
line(50,400,600,400);
line(50,400,50,50);
outtextxy(556,410,"x");
settextstyle(7, VERT_DIR,0);
outtextxy(10,375,"y");
settextstyle(7, HORIZ_DIR,0);
for(i=0;i<n;i++)
{ int x1 = a[i]+50;
int y1 = 400 - b[i];
setfillstyle(SOLID_FILL,14);
setcolor(14);
circle(x1,y1,1);
floodfill(x1,y1,14);
}
setcolor(WHITE);
int x2,y2;
line(50,400,600,400);
line(50,50,50,400);
moveto(50,400);
float y;
for( int i=0;i<198;i++)
{
y = (aa*pow(i,2)) +(bb*i) + cc;
x2 = i+50;
y2 = 400-y;
lineto(x2,y2);
}
break;
}
default:
{cout<<"Sorry wrong choice";
getch();
clrscr();
break;
}
// getch();
// closegraph();
}
getch();
closegraph();
//cleardevice();
clrscr();
int z=1;
while(z==1||z==2)
{
cout<<"\n\n\n\n\nPress 1 to return to previos menu";
cout<<"\nPress 2 to exit";
cin>>z;
if(z==1)
menu1();
else if(z==2)
exit(0);
else cout<<"Wrong choice";
}
getch();
}
Робота з програмою
Робота з програмою починається із стану вибору операції
Наступний крок вибору операції з даними
Висновки
Була розроблена комп’ютерна програма для простої обробки даних з можливістю її графічної інтерпретації При розробці програми використовувався пакет BORLANDC++ Bilder та бібліотека BGI.
Відмітимо лише в порівнянні з іншими подібними програмними продуктами – дана програма має простий командний інтерфейс (це в значний мірі спростило етап розробки даної програми).
Література
1. Касаткин А.И., Вальвачев А.Н. Профессиональное прогрпммирование на языке Си. Мн., 1992. 240 С.
2. Нейбауэр А. Моя первая программа на С/С++. П., 1995. 368 С.
3. Бруно Бабэ. Просто и ясно о Borland C++. М., 1996. 400 С.
4. Шамас Н.К. Основы С++ и обьектно-ориентированного программирования. К., 1996. 448 С.
5. Справочник по классам Borland C++ 4.0. К., 1994. 256 С.