Возврат в меню после окончания работы в графическом режиме - C (СИ)
Формулировка задачи:
#include <stdio.h> #include <graphics.h> #include <conio.h> #include <math.h> #include <stdlib.h> struct toch {int x,y;}; const int n=20; void zavdanya() { system("cls"); printf("Student grupy KM-145, LOPATIN VLADISLAV STANISLAVOVICH"); printf("\nKursova robota"); printf("\nStvorenya programnogo kompleksu movamy programuvanya Pascal ta C"); printf("\nIndividualne zavdanya #6"); getch(); } void umova1() { system("cls"); printf("Vikonati tabuliaciy parametrichni zadanoi funkcii"); printf("\n(Ravlik Paskalya(kardioida)), zapisati ii u fail ta vivesti iogo na ekran."); printf("\nPobuduvati i vivesty na ekran monitora graphik ciei funkcii:"); printf("\nx=a*sqr(cos(t))+b*cos(t)"); printf("\ny=cos(t)*sin(t)+b*sin(t)"); printf("a,b >0; t (0;2*pi)"); getch(); } void umova2() { system("cls"); printf("' U file zadano koordinaty tochok. Kilkist yakih"); printf("\nbilsha desati. Vivesti na ekran 10 tochok, u yakih vodstan"); printf("\n'vid centra ekranu naymensha. Provesti cherez ci tichki lamanu"); printf("\nliniyu. Okremim kolorom vidility naykorotshiy ta"); printf("\nTretim kolorom vidility ti trikutniki, shcho znahodyatca v"); printf("\nnaydovshiy vidrizki lamanoi"); getch(); } void menugolovne() { system("cls"); printf("1-Zavdanya"); printf("\n2-Zavdanya #1"); printf("\n3-Zavdanya #2"); printf("\n4-Exit"); printf("\n\nZrobit budi-lasca sviy vibir: "); } void menuzavdanya1() { system("cls"); printf("1-Umova zavdanya"); printf("\n2-Tabulyacia functcii"); printf("\n3-Vivedennia tabuliacii na ekran"); printf("\n4-Grafik functcii"); printf("\n5-Nazad"); printf("\n\nZrobit budi-lasca sviy vibir: "); } void menuzavdanya2() { system("cls"); printf("1-Umova zavdanya"); printf("\n2-Vmist faily"); printf("\n3-Vivedennia tochok"); printf("\n4-Nazad"); printf("\n\nZrobit budi-lasca sviy vibir: "); } void vvod(int a,int b, int n) { float t,c,tabx,taby; FILE *fil; fil=fopen("tabulyacia.txt","wt"); system("cls"); c=fabs((2*M_PI)/(n-1)); t=0; fprintf(fil,"|---------------|-------------|"); fprintf(fil,"\n| x | y |"); fprintf(fil,"\n|---------------|-------------|"); while (t<=2*M_PI) { tabx=a*pow(cos(t),2)+b*cos(t); taby=cos(t)*sin(t)+b*sin(t); fprintf(fil,"\n| x=%7.3f | y=%7.3f |",tabx,taby); fprintf(fil,"\n|---------------|-------------|"); t = t + c; } printf("Tabulyacia i zapis u file zaversheno"); getch(); fclose(fil); } void vivod() { FILE *fil; char s[30]; system("cls"); fil=fopen("tabulyacia.txt","r"); while (!feof(fil)) { fgets(s,30,fil); printf("%s",s); } getch(); fclose(fil); } void graphik(int a,int b) { float tabx,taby,t,y; int k; system("cls"); int gd=DETECT,gm; initgraph(&gd,&gm," "); t=0; setcolor(2); line(320,0,320,480); line(0,240,640,240); k=0; while (k<=640) { line(k,237,k,243); k=k+10; } k=0; while (k<=480) { line(318,k,322,k); k=k+10; } while (t<2*M_PI) { tabx=a*pow(cos(t),2)+b*cos(t); taby=cos(t)*sin(t)+b*sin(t); putpixel(tabx*10+320,taby*10+240,2); t=t+0.01; } getch(); closegraph(); } void vmistft() { system("cls"); FILE *f; int l; struct toch at; f=fopen("koord.txt","r"); l=1; while (!feof(f)) { fscanf(f,"%d %d",&at.x,&at.y); printf("Tochka %d: (%d;%d)\n",l,at.x,at.y); l++; } getch(); } void tochka() { struct toch at; float vid,min,mint,maxt; int l,k,t,i,j,x,y; FILE *f; float vids[99],vidst[99],rezul[9]; int koordx[99],koordy[99],koordx1[9],koordy1[9]; k=0; f=fopen("koord.txt","r"); while (!feof(f)) { fscanf(f,"%d %d",&at.x,&at.y); vid=sqrt(at.x*at.x+at.y*at.y); vids[k]=vid; koordx[k]=at.x; koordy[k]=at.y; k++; } l=0; while (l<k) { vidst[l]=vids[l]; l++; } t=0; while (t<10) { l=0; min=9999; while (l<k) { if (min>vidst[l]) min=vidst[l]; l++; } l=0; while (l<k) { if (vidst[l]==min) vidst[l]=9999; l++; } rezul[t]=min; t++; } int gd=DETECT,gm; initgraph(&gd,&gm," "); j=0; setcolor(2); line(320,0,320,480); line(0,240,640,240); while (j<10) { l=0; while (l<k) { if (vids[l]==rezul[j]) { koordx1[j]=koordx[j]; koordy1[j]=koordy[j]; circle(koordx[j]*20+320,abs(koordy[j]*20-240),2); } l++; } j++; } j=0; while (j<=640) { line(317,j,323,j); line(j,237,j,243); j=j+20; } j=0; while (j<10) { if (j==9) line(koordx1[j]*20+320,abs(koordy1[j]*20-240),koordx1[0]*20+320,abs(koordy1[0]*20-240)); else line(koordx1[j]*20+320,abs(koordy1[j]*20-240),koordx1[j+1]*20+320,abs(koordy1[j+1]*20-240)); j++; } getch(); fclose(f); closegraph(); } int main(void) { int a,b,p,n; poch: system("cls"); menugolovne(); scanf("%d",&p); switch(p) { case 1: { zavdanya(); goto poch; } case 2: { m1: menuzavdanya1(); scanf("%d",&p); switch(p) { case 1: { umova1(); goto m1; } case 2: {system("cls"); printf("Vvedite a="); scanf("%d",&a); printf("Vvedite b="); scanf("%d",&b); printf("Vvedite kilkist n="); scanf("%d",&n); vvod(a,b,n); goto m1; } case 3: { vivod(); goto m1; } case 4: {system("cls"); printf("Vvedite a="); scanf("%d",&a); printf("Vvedite b="); scanf("%d",&b); graphik(a,b); goto m1; } case 5: { goto poch; } } } case 3: { m2: menuzavdanya2(); scanf("%d",&p); switch(p) { case 1: { umova2(); goto m2; } case 2: { vmistft(); goto m2; } case 3: { tochka(); goto m2; } case 4: { goto poch; } } } case 4: { exit(1); } } getch(); }
Решение задачи: «Возврат в меню после окончания работы в графическом режиме»
textual
Листинг программы
#include <stdio.h> #include <graphics.h> #include <conio.h> #include <math.h> #include <stdlib.h> struct toch {int x,y;}; const int n=20; void zavdanya() { system("cls"); printf("Student grupy KM-145, LOPATIN VLADISLAV STANISLAVOVICH"); printf("\nKursova robota"); printf("\nStvorenya programnogo kompleksu movamy programuvanya Pascal ta C"); printf("\nIndividualne zavdanya #6"); getch(); } void umova1() { system("cls"); printf("Vikonati tabuliaciy parametrichni zadanoi funkcii"); printf("\n(Ravlik Paskalya(kardioida)), zapisati ii u fail ta vivesti iogo na ekran."); printf("\nPobuduvati i vivesty na ekran monitora graphik ciei funkcii:"); printf("\nx=a*sqr(cos(t))+b*cos(t)"); printf("\ny=cos(t)*sin(t)+b*sin(t)"); printf("a,b >0; t (0;2*pi)"); getch(); } void umova2() { system("cls"); printf("' U file zadano koordinaty tochok. Kilkist yakih"); printf("\nbilsha desati. Vivesti na ekran 10 tochok, u yakih vodstan"); printf("\n'vid centra ekranu naymensha. Provesti cherez ci tichki lamanu"); printf("\nliniyu. Okremim kolorom vidility naykorotshiy ta"); printf("\nTretim kolorom vidility ti trikutniki, shcho znahodyatca v"); printf("\nnaydovshiy vidrizki lamanoi"); getch(); } void menugolovne() { system("cls"); printf("1-Zavdanya"); printf("\n2-Zavdanya #1"); printf("\n3-Zavdanya #2"); printf("\n4-Exit"); printf("\n\nZrobit budi-lasca sviy vibir: "); } void menuzavdanya1() { system("cls"); printf("1-Umova zavdanya"); printf("\n2-Tabulyacia functcii"); printf("\n3-Vivedennia tabuliacii na ekran"); printf("\n4-Grafik functcii"); printf("\n5-Nazad"); printf("\n\nZrobit budi-lasca sviy vibir: "); } void menuzavdanya2() { system("cls"); printf("1-Umova zavdanya"); printf("\n2-Vmist faily"); printf("\n3-Vivedennia tochok"); printf("\n4-Nazad"); printf("\n\nZrobit budi-lasca sviy vibir: "); } void vvod(int a,int b, int n) { float t,c,tabx,taby; FILE *fil; fil=fopen("tabulyacia.txt","wt"); system("cls"); c=fabs((2*M_PI)/(n-1)); t=0; fprintf(fil,"|---------------|-------------|"); fprintf(fil,"\n| x | y |"); fprintf(fil,"\n|---------------|-------------|"); while (t<=2*M_PI) { tabx=a*pow(cos(t),2)+b*cos(t); taby=cos(t)*sin(t)+b*sin(t); fprintf(fil,"\n| x=%7.3f | y=%7.3f |",tabx,taby); fprintf(fil,"\n|---------------|-------------|"); t = t + c; } printf("Tabulyacia i zapis u file zaversheno"); getch(); fclose(fil); } void vivod() { FILE *fil; char s[30]; system("cls"); fil=fopen("tabulyacia.txt","r"); while (!feof(fil)) { fgets(s,30,fil); printf("%s",s); } getch(); fclose(fil); } void graphik(int a,int b) { float tabx,taby,t,y; int k; system("cls"); int gd=DETECT,gm; initgraph(&gd,&gm," "); t=0; setcolor(2); line(320,0,320,480); line(0,240,640,240); k=0; while (k<=640) { line(k,237,k,243); k=k+10; } k=0; while (k<=480) { line(318,k,322,k); k=k+10; } while (t<2*M_PI) { tabx=a*pow(cos(t),2)+b*cos(t); taby=cos(t)*sin(t)+b*sin(t); putpixel(tabx*10+320,taby*10+240,2); t=t+0.01; } getch(); closegraph(); } void vmistft() { system("cls"); FILE *f; int l; struct toch at; f=fopen("koord.txt","r"); l=1; while (!feof(f)) { fscanf(f,"%d %d",&at.x,&at.y); printf("Tochka %d: (%d;%d)\n",l,at.x,at.y); l++; } getch(); } void tochka() { struct toch at; float vid,min,mint,maxt; int l,k,t,i,j,x,y; FILE *f; float vids[99],vidst[99],rezul[9]; int koordx[99],koordy[99],koordx1[9],koordy1[9]; k=0; f=fopen("koord.txt","r"); while (!feof(f)) { fscanf(f,"%d %d",&at.x,&at.y); vid=sqrt(at.x*at.x+at.y*at.y); vids[k]=vid; koordx[k]=at.x; koordy[k]=at.y; k++; } l=0; while (l<k) { vidst[l]=vids[l]; l++; } t=0; while (t<10) { l=0; min=9999; while (l<k) { if (min>vidst[l]) min=vidst[l]; l++; } l=0; while (l<k) { if (vidst[l]==min) vidst[l]=9999; l++; } rezul[t]=min; t++; } int gd=DETECT,gm; initgraph(&gd,&gm," "); j=0; setcolor(2); line(320,0,320,480); line(0,240,640,240); while (j<10) { l=0; while (l<k) { if (vids[l]==rezul[j]) { koordx1[j]=koordx[j]; koordy1[j]=koordy[j]; circle(koordx[j]*20+320,abs(koordy[j]*20-240),2); } l++; } j++; } j=0; while (j<=640) { line(317,j,323,j); line(j,237,j,243); j=j+20; } j=0; while (j<10) { if (j==9) line(koordx1[j]*20+320,abs(koordy1[j]*20-240),koordx1[0]*20+320,abs(koordy1[0]*20-240)); else line(koordx1[j]*20+320,abs(koordy1[j]*20-240),koordx1[j+1]*20+320,abs(koordy1[j+1]*20-240)); j++; } getch(); fclose(f); closegraph(); } int main(void) { int a,b,p,n; poch: system("cls"); menugolovne(); scanf("%d",&p); switch(p) { case 1: { zavdanya(); goto nazad; } case 2: { m1: menuzavdanya1(); scanf("%d",&p); switch(p) { case 1: { umova1(); goto m1; } case 2: {system("cls"); printf("Vvedite a="); scanf("%d",&a); printf("Vvedite b="); scanf("%d",&b); printf("Vvedite kilkist n="); scanf("%d",&n); vvod(a,b,n); goto m1; } case 3: { vivod(); goto m1; } case 4: {system("cls"); printf("Vvedite a="); scanf("%d",&a); printf("Vvedite b="); scanf("%d",&b); graphik(a,b); goto m1; } case 5: { goto poch; } } } case 3: { m2: menuzavdanya2(); scanf("%d",&p); switch(p) { case 1: { umova2(); goto m2; } case 2: { vmistft(); goto m2; } case 3: { tochka(); goto m2; } case 4: { goto poch; } } } return (0); }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д