俄罗斯国防军事学院:求解一小道C语言编程

来源:百度文库 编辑:查人人中国名人网 时间:2024/04/29 20:59:10
这可是我们的上机考试题,请帮帮忙,谢谢了!我就这么多分,全给你吧!
完成一个数学运算菜单设计
1,开始画面,要求有一个动画效果的开始界面。比如:摇摆的小球,跳跃的太阳,跑动的小动物。。。。
2,主菜单画面:
MENU
ADD +
SUB -
MUL *
DIV /
QUIT
3,要求完成加法子菜单,退出子菜单设计。
4,加法子菜单:在屏幕上出一道加法题,如89+12= ,请用户输入结果,如果用户输入的答案正确,给出“you are right"的信息。然后询问用户是不是继续计算,如果用户愿意继续,则在屏幕上再出一题;如果不愿意,则返回主菜单。
如果用户的答案错误,给出”wrong"。然后将题目再给出一次,请用户重新回答。如果三次回答错误,则给出正确答案。然后问用户是不是继续。
5,退出子菜单。出现“BYE BYE ”。

根据你的要求,我帮你做了一个,已经通过tc测试,不但有加法的,连其他3个运算都有,除法是算商的,辛苦啊!不给我加分我不开心的啊~~~!:(
#include"graphics.h"
#include"conio.h"
#include"dos.h"
#include"time.h"
#include"stdlib.h"
int py;
int vs(int r1,int r2,int py,int ans)
{ int crut;static int n=1;char k;
switch(py-6)
{ case 0:crut=r1+r2;break;
case 1:crut=r1-r2;break;
case 2:crut=r1*r2;break;
case 3:crut=r1/r2;break;
}
if(ans==crut) {printf("\n");printf("you are right");}
else {printf("\n wrong");getch();clrscr();++n;if(n<=3)
count(py,r1,r2); else printf("right answer is %d\n",crut);}
n=1;
getch();printf("\n continue?");k=getch();
if(k=='y') {clrscr();return 1;}
else {clrscr();return 0;}
}
int menu()
{int py=6;char key=0;
gotoxy(1,4);
printf("MENU\n\n");
printf("ADD +\n");
printf("SUB -\n");
printf("MUL *\n");
printf("DIV /\n");
printf("QUIT");
gotoxy(10,6);printf("<-");
randomize();
while(key!=13)
{ key=getch();
switch(key)
{ case 80 : gotoxy(10,py);printf(" ");py=py%5+6;break;
case 72 : gotoxy(10,py);printf(" ");--py;if(py==5) py=10;break;
}
gotoxy(10,py);printf("<-");
}
return py;
}
int count(int fh,int r1,int r2)
{ int ans,mr;
clrscr();
switch(fh-6)
{ case 0 : printf("%d+%d=",r1,r2);break;
case 1 : printf("%d-%d=",r1,r2);break;
case 2 : printf("%d*%d=",r1,r2);break;
case 3 : printf("%d/%d=",r1,r2);break;
}
scanf("%d",&ans);
mr=vs(r1,r2,fh,ans);
return mr;
}
main()
{ int gd=DETECT,gm,x=320,y=10,i,l=10,h=10,t,co=3,v=0;
int mr,fh,x1,x2;
initgraph(&gd,&gm,"");
registerbgidriver(EGAVGA_driver);
for(i=1;i<31;co=(co++%10),v++,y+=2+v,i++)
{ delay(9e10);cleardevice();
setcolor(co);
setfillstyle(1,co);
sector(x,y,0,360,l,h);
}
for(i=1;i<300;i++)
{ setcolor(i%10);
circle(x,y,i);
delay(1000);
}
cleardevice();
closegraph();
there: py=menu();
if(py==10) {clrscr();printf("bye bye!");getch();return 0;}
here: x1=random(99)+1;x2=random(99)+1;
mr=count(py,x1,x2);if(mr) goto here;
else goto there;
}