p align="left">Рис. 11. Модифицированное приложение Для кнопки Удалить: void __fastcall TForm1::Button2Click(TObject *Sender) { if (!(ListBox1->ItemIndex == -1)) ListBox1->Items->Delete(ListBox1->ItemIndex); } Для кнопки Выход: Close(); Сохраним и скомпилируем приложение, а затем протестируем его. Итак, мы познакомились со средой разработки Borland C++ Builder и создали простое приложение. В следующих статьях этого цикла будут описаны приемы манипуляции компонентами на форме и более подробно рассмотрены особенности поведения различных компонентов в приложении Практична частина Лістінги програм#include<iostream.h> #include<graphics.h> #include<conio.h> #include<stdio.h> #include<ctype.h> #include<string.h> #include<math.h> #include<process.h> #include<complex.h> #include<conio.h> #include<stdlib.h> #include<iomanip.h> #define MAX 50 #define ARRAYMAX 10 void initialize(); void menu1(); void menu2(); void data(); void graphch(); void corre(); void mean(); void median(); void graph(); void makegraph(float p[]); void pie(); void mode(); void variance(); int input(); void correlation(); void regress(); void curvefit(); int midx = getmaxx()/2; int midy = getmaxy()/2; int choice1,choice2,choice3,choice4,choice5,choice6,choice7,choice8; int a[100],b[100],c[100],d[100],e[100],f[100],g[100]; float men,medin,mod,cxy,vx,vy; int a1,b1,c1,d1,e1,f1,g1,h1,i1,j1,k1,l1,m1,n1,o1,p1,q1; long double z1=0,z2=0,z3=0,z4=0,z5=0,z6=0,z7=0,z8=0,byx=0,bxy=0,mx=0,my=0; static int zzz; s =0; float s2 =0.0; s3 =0; s1 =0; float sum =0.0; float mean,variance,v1,v2,v3; data(); clrscr(); switch(choice5) { case 1: { cout<<" Enter the total no of individual observations"; cin>>n; for(int i=0;i<n;i++) { cout<<" X"<<i+1<< " ="; cin>>a[i]; s = s+ a[i]; } mean = s/n; for(i=0;i<n;i++) { sum = sum+ pow((a[i]-mean),2); } clrscr(); cout<<"The values of individual observations are "; for(i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl; variance = sum/n; break; } case 2: { cout<<"Enter the no of data"; cin>>nn; cout<< "Enter the class interval size"; cin>>ci; cout<<"Enter the upper most level"; cin>>up; cout<<" Enter the lowermost level"; cin>>lo; cout<<"Enter the frequency in order\n"; for(int i=0;i<nn;i++) { b[i] = ((up + ci) + up)/2; up = up + ci; cout<<" Freq"<<i+1<<" ="; cin>>c[i]; } for(i=0;i<nn;i++) { d[i] = b[i] - b[nn/2]; e[i] = d[i]/ci; } for(i=0;i<nn;i++) cout<<e[i]<<" "; cout<<endl; float sum2,sum3,sum4; sum2 = 0.0; sum3 =0.0; sum4 = 0.0; for(i=0;i<nn;i++) { sum2 = sum2 +(c[i]*e[i]); sum3 = sum3 +(c[i]*pow(e[i],2)); sum4 = sum4+ c[i]; } cout<<"The sum of f * u = "<<sum2<<endl; cout<<" The sum of f*u2 = "<<sum3<<endl; cout<<" The sum of f = "<<sum4<<endl; v1 = sum3/sum4; cout<<" The value of 1 = "<<v1<<endl; v2 = sum2/sum4; cout<<" The value of 2 = "<<v2<<endl; v3 = pow(v2,2); variance = (pow(ci,2)*(v1 -v3)); int u= up; cout<<"Class\t"<<setw(12)<<"Mid "<<setw(10)<<"Frequency\n"; cout<<"interval\t"<<setw(12)<<"value"<<endl; for( int k=0;k<nn;k++) { cout<<u<<" - "<<u+ci<<"\t"<<setw(12)<<b[k]<<setw(10)<<c[k]<<endl; u = u+ci; } break; } case 3: { cout<<"Enter the total no of data"; cin>>nn; char s[20],s4[20]; cout<<" X denotes "; cin>>s; cout<<" Frequency denotes "; cin>>s4; for(int i=0;i<nn;i++) { cout<<"X"<<i+1<<" ="; cin>>a[i]; cout<<"Freq"<<i+1<<" ="; cin>>b[i]; s3 = s3+b[i]; } cout<<"The sum of f = "<<s3<<endl; for(i=0;i<nn;i++) { s1 =s1+ (a[i]*b[i]); } cout<<"The sum of f*x = "<<s1<<endl; mean = s1/s3; for(i=0;i<nn;i++) { c[i] = pow((a[i]-mean),2); s2 = s2 +(c[i]*b[i]); } cout<<"Mean = "<<mean<<endl; cout<<"The sum of deviations = "<<s2<<endl; variance = s2/s3; cout<<setw(15)<<s<<setw(20)<<s4<<endl<<endl; for(i=0;i<nn;i++) { cout<<setw(15)<<a[i]<<setw(20)<<b[i]<<endl; } break; } default: {cout<<" Sorry wrong choice"; getch(); data(); } } cout<<" Variance ="<<variance; getch(); 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) menu2(); else if(z==2) exit(0); else cout<<"Wrong choice"; } } char s[20],s1[20]; int input() { int n; gotoxy(2,6); cout<<"Enter the total no of data"; cin>>n; cout<<"Enter the variable x and y values\n"; cout<<" X denotes "; cin>>s; cout<<" Y denotes "; cin>>s1; for(int i=0;i<n;i++) { cout<<" X"<<i+1<<" ="; cin>>f[i]; cout<<" Y"<<i+1<<" ="; cin>>g[i]; } return(n); } void correlation() { int n; corre(); initialize(); switch(choice4) { case 1: { n =input(); clrscr(); cleardevice(); initialize(); settextstyle(7,HORIZ_DIR,0); outtextxy(50,30,"SCATTER DIAGRAM"); line(50,400,600,400); line(50,400,50,50); outtextxy(556,410,s); settextstyle(7, VERT_DIR,0); outtextxy(30,375,s1); settextstyle(7, HORIZ_DIR,0); for(int i=0;i<n;i++) { int x1 = f[i]+ 50; int y1 = 400- g[i]; setfillstyle(SOLID_FILL,14); setcolor(14); circle(x1,y1,1); floodfill(x1,y1,14); } break; } case 2: {// clrscr(); // cleardevice(); float sum2,sum3,sum4,sum5,sum6; n = input(); sum2 = 0.0; sum3 =0.0; sum4 =0.0; sum5 =0.0; sum6 =0.0; clrscr(); cleardevice(); for(int i=0;i<n;i++) { sum2 = sum2 + f[i]; sum3 = sum3 + g[i]; } cout<<setw(15)<<" X "<<setw(20)<<" Y "<<endl<<endl; for(i=0;i<n;i++) { cout<<setw(15)<<f[i]<<setw(20)<<g[i]<<endl; } cout<<" The sum of X = "<<sum2<<endl; cout<<"The sum of Y = "<<sum3<<endl; float mex = sum2/n; float mey = sum3/n; cout<<" The mean of X = "<<mex<<endl; cout<<"The mean of Y = "<<mey<<endl; for(i=0;i<n;i++) { sum4 = sum4 +((f[i] -mex)*(g[i]-mey)); sum5 = sum5 + pow((f[i]-mex),2); sum6 = sum6+ pow((g[i]-mey),2); } cout<<" The sum of products of deviation from mean of X and Y = "<<sum4<<endl; cout<<"The sum of squares of deviation from mean of X = "<<sum5<<endl; cout<<" The sum fo squares of deviation from mean of Y = "<<sum6<<endl; float cov = sum4/n; float varx = sqrt(sum5/n); float vary = sqrt(sum6/n); float coeff = ((cov/varx)/vary); cout<<" THE COEFFICIENT OF CORRELATION = "<<coeff<<endl<<endl; if(coeff<=1 && coeff>= -1) { if(coeff == -1) cout<<" There is perfect negative correlation between X and Y\n"; else if(coeff ==1) cout<<"There is perfect positive correlation between X and Y\n"; 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";
Страницы: 1, 2, 3
|