#include<conio.h>
#include <math.h>
#include <stdio.h>
#include <graphics.h>
main()
{
float a[10][10]={{1.39,1.49,1.43,1.41,1.37,1.40,1.32,1.42,1.39,1.47},
{1.41,1.38,1.40,1.34,1.42,1.42,1.45,1.35,1.42,1.34},
{1.44,1.42,1.39,1.42,1.42,1.30,1.34,1.42,1.37,1.36},
{1.39,1.34,1.37,1.37,1.44,1.45,1.32,1.48,1.40,1.45},
{1.39,1.46,1.39,1.53,1.38,1.48,1.40,1.39,1.38,1.40},
{1.36,1.45,1.50,1.43,1.38,1.43,1.41,1.48,1.39,1.45},
{1.37,1.37,1.39,1.45,1.31,1.41,1.44,1.44,1.43,1.42},
{1.36,1.39,1.40,1.38,1.39,1.42,1.43,1.42,1.43,1.47},
{1.42,1.40,1.41,1.37,1.46,1.36,1.37,1.27,1.37,1.38},
{1.42,1.34,1.43,1.42,1.41,1.41,1.44,1.48,1.55,1.37}};
int n;
clrscr();
printf("\n");
printf("\n 0. Quit ");
printf("\n 1. Display the Data ");
printf("\n 2. Display the Max & Min Number ");
printf("\n 3. Display the Junzhi & Fangcha ");
printf("\n 4. Display the Pingshufenbutu ");
printf("\n 5. Display the Leijipingshufenbutu ");
printf("\n");
printf("\n Select the Number : ");
while(n!=0)
{
scanf("%d",&n);
if(n==1) show(a);
else if(n==2) compare(a);
else if(n==3) aver(a);
else if(n==4) huitu(a);
else if(n==5) pic(a);
};
}
show(float b[10][10])
{
int i,j;
printf("\n\n");
printf("The Data is \n");
for(i=0;i<10;i++)
for(j=0;j<10;j++)
{
if(j%10==0)
printf("\n");
printf(" %.2f",b[i][j]);
}
printf("\n\n");
printf("\n Select other Number : ");
}
compare(float c[10][10])
{
int i,j;
float m=0,n=0;
m=n=c[0][0];
for(i=1;i<10;i++)
for(j=1;j<10;j++)
{
if(c[i][j]>m) m=c[i][j];
else if(c[i][j]<n) n=c[i][j];
}
printf("\nThe Max Number is %.2f",m);
printf("\nThe Min Number is %.2f",n);
printf("\n\n");
printf("\n Select other Number : ");
}
aver(float c[10][10])
{
int i,j;
float sum,ave,sum1,q,t;
sum=sum1=0;
for(i=0;i<10;i++)
for(j=0;j<10;j++)
{
sum=sum+c[i][j];
}
ave=sum/100;
printf("The Junzhi is %.2f",ave);
for(i=0;i<10;i++)
for(j=0;j<10;j++)
{
t=(ave-c[i][j])*(ave-c[i][j]);
sum1=sum1+t;
}
q=sqrt(sum1/100);
printf("\n\nThe Fangcha is %f",q);
printf("\n\n");
printf("\n Select other Number : ");
}
huitu(float d[10][10])
{
int i,j,n1,n2,n3,n4;
int driver=DETECT,mode;
initgraph(&driver,&mode," ");
putpixel(80, 80, CYAN);
line(90,90,90,390);
line(90,390,560,390);
n1=n2=n3=n4=0;
for(i=0;i<10;i++)
for(j=0;j<10;j++)
{
if(1.20<=d[i][j] && d[i][j]<1.30) n1++;
else if(1.30<=d[i][j] && d[i][j]<1.40) n2++;
if(1.40<=d[i][j] && d[i][j]<1.50) n3++;
if(1.50<=d[i][j] && d[i][j]<=1.60) n4++;
}
setcolor(LIGHTBLUE);
line(125,390,125,390-n1*5.0);
line(125,390-n1*5.0,225,390-n1*5.0);
line(225,390-n1*5.0,225,390);
setcolor(LIGHTRED);
line(225,390,225,390-n2*5.0);
line(225,390-n2*5.0,325,390-n2*5.0);
line(325,390-n2*5.0,325,390);
setcolor(YELLOW);
line(325,390,325,390-n3*5.0);
line(325,390-n3*5.0,425,390-n3*5.0);
line(425,390-n3*5.0,425,390);
setcolor(WHITE);
line(425,390,425,390-n4*5.0);
line(425,390-n4*5.0,525,390-n4*5.0);
line(525,390-n4*5.0,525,390);
setcolor(LIGHTGREEN);
outtextxy(125,400,"1.20");
outtextxy(225,400,"1.30");
outtextxy(325,400,"1.40");
outtextxy(425,400,"1.50");
outtextxy(525,400,"1.60");
outtextxy(70,390-n1*5.0,"2");
outtextxy(70,390-n2*5.0,"47");
outtextxy(70,390-n3*5.0,"48");
outtextxy(70,390-n4*5.0,"3");
printf("\n\n");
gotoxy(90,500);
printf("\n Select other Num: ");
}
pic(float d[10][10])
{
int i,j,n1,n2,n3,n4,m1,m2,m3,m4;
int driver=DETECT,mode;
initgraph(&driver,&mode," ");
line(90,90,90,390);
line(90,390,560,390);
n1=n2=n3=n4=0;
for(i=0;i<10;i++)
for(j=0;j<10;j++)
{
if(1.20<=d[i][j] && d[i][j]<1.30) n1++;
else if(1.30<=d[i][j] && d[i][j]<1.40) n2++;
if(1.40<=d[i][j] && d[i][j]<1.50) n3++;
if(1.50<=d[i][j] && d[i][j]<=1.60) n4++;
}
m1=n1,m2=n1+n2,m3=m2+n3,m4=m3+n4;
setcolor(RED);
line(125,390,125,390-m1*2);
line(125,390-m1*2,225,390-m1*2);
line(225,390-m1*2,225,390);
setcolor(BLUE);
line(225,390,225,390-m2*2);
line(225,390-m2*2,325,390-m2*2);
line(325,390-m2*2,325,390);
setcolor(WHITE);
line(325,390,325,390-m3*2);
line(325,390-m3*2,425,390-m3*2);
line(425,390-m3*2,425,390);
setcolor(YELLOW);
line(425,390,425,390-m4*2);
line(425,390-m4*2,525,390-m4*2);
line(525,390-m4*2,525,390);
outtextxy(125,400,"1.20");
outtextxy(225,400,"1.30");
outtextxy(325,400,"1.40");
outtextxy(425,400,"1.50");
outtextxy(525,400,"1.60");
outtextxy(70,390-m1*2,"2");
outtextxy(70,390-m2*2,"4");
outtextxy(70,390-m3*2,"97");
outtextxy(70,390-m4*2,"100");
printf("\n Select other Number : ");
}
10 个解决方案
#1
没有在TC下面编过东西,也帮你顶!
#2
谢谢 我真的很急!帮帮我找人问问好吗?我都快哭了
#3
下拉式菜单。什么意思?是跟Windows的菜单一样,点了什么之后,弹出一个菜单么?
那要用C的图形编程啊
那要用C的图形编程啊
#4
你想做成什么样子的,窗口式带菜单的吗?
#5
如果是的话文字模式和图形模式都是可以做的,不过我没有现成的程序可以提供给你,如果你需要的话要临时再做,希望你可以把要求说的具体些(比如菜单中有些什么项)
#6
把上面的数字菜单改成纵向的下拉式菜单。谢谢!!
#7
你什么时候要?明天可以吗?今天太忙,没时间写了
#8
好的。最好今晚。谢谢!!!!!!
#9
#include <conio.h>
#include <math.h>
#include <stdio.h>
#include <graphics.h>
#include <string.h>
typedef struct menu {
int number;
char caption[100];
int left, top;
int width, height;
int function;
char flag;
}MENU;
typedef MENU* PMENU;
void initmenu( MENU mainmenu[7] );
void drawmenu( MENU mainmenu[7] );
void drawitem( MENU menu );
void clearmenu( MENU mainmenu[7] );
int main()
{
float a[10][10]={{1.39,1.49,1.43,1.41,1.37,1.40,1.32,1.42,1.39,1.47},
{1.41,1.38,1.40,1.34,1.42,1.42,1.45,1.35,1.42,1.34},
{1.44,1.42,1.39,1.42,1.42,1.30,1.34,1.42,1.37,1.36},
{1.39,1.34,1.37,1.37,1.44,1.45,1.32,1.48,1.40,1.45},
{1.39,1.46,1.39,1.53,1.38,1.48,1.40,1.39,1.38,1.40},
{1.36,1.45,1.50,1.43,1.38,1.43,1.41,1.48,1.39,1.45},
{1.37,1.37,1.39,1.45,1.31,1.41,1.44,1.44,1.43,1.42},
{1.36,1.39,1.40,1.38,1.39,1.42,1.43,1.42,1.43,1.47},
{1.42,1.40,1.41,1.37,1.46,1.36,1.37,1.27,1.37,1.38},
{1.42,1.34,1.43,1.42,1.41,1.41,1.44,1.48,1.55,1.37}};
int gdriver = DETECT, gmode;
int key;
int lastmenu = -1;
char flag = 1;
int fun = -1;
MENU mainmenu[7] = {
{ 6, "menu", 10, 10, 40, 16, -1, 0 },
{ 0, "quit", 10, 0, 0, 16, 0, 0 },
{ 0, "Display the Data", 10, 0, 0, 16, 1, 0 },
{ 0, "Display the Max & Min Number", 10, 0, 0, 16, 2, 0 },
{ 0, "Display the Junzhi & Fangcha", 10, 0, 0, 16, 3, 0 },
{ 0, "Display the Pingshufenbutu", 10, 0, 0, 16, 4, 0 },
{ 0, "Display the Leijipingshufenbutu", 10, 0, 0, 16, 5, 0 } };
initmenu( mainmenu );
initgraph( &gdriver, &gmode, "" );
setcolor( WHITE );
outtextxy( 100, 14, "Press F10 to start the menu" );
drawmenu( mainmenu );
while ( flag ) {
if ( kbhit() ) {
key = getch();
switch ( key ) {
case 27://ESC
if ( mainmenu[0].flag ) {
mainmenu[0].flag = 0;
mainmenu[lastmenu].flag = 0;
lastmenu = -1;
clearmenu( mainmenu );
}
else
flag = 0;
break;;
case 13://ENTER
if ( lastmenu != -1 ) {
fun = mainmenu[lastmenu].function;
mainmenu[0].flag = 0;
mainmenu[lastmenu].flag = 0;
lastmenu = -1;
clearmenu( mainmenu );
}
break;;
}
if ( key == 0 ) {
key = getch();
switch ( key ) {
case 72://up
mainmenu[lastmenu].flag = 0;
drawitem( mainmenu[lastmenu] );
lastmenu--;
if ( lastmenu < 1 )
lastmenu = 1;
mainmenu[lastmenu].flag = 1;
drawitem( mainmenu[lastmenu] );
break;
case 80://down
mainmenu[lastmenu].flag = 0;
drawitem( mainmenu[lastmenu] );
lastmenu++;
if ( lastmenu > 6 )
lastmenu = 6;
mainmenu[lastmenu].flag = 1;
drawitem( mainmenu[lastmenu] );
break;
case 68://F10
if ( mainmenu[0].flag == 0 ) {
mainmenu[0].flag = 1;
mainmenu[1].flag = 1;
lastmenu = 1;
drawmenu( mainmenu );
}
else {
mainmenu[0].flag = 0;
mainmenu[lastmenu].flag = 0;
lastmenu = -1;
clearmenu( mainmenu );
}
break;
}
}
}
switch ( fun ) {
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
default:
break;
}
}
closegraph();
return 0;
}
void initmenu( MENU mainmenu[7] ) {
int maxlength = 0;
int width;
int length;
int i;
for ( i = 1; i < 7; i++ ) {
length = strlen( mainmenu[i].caption );
if ( maxlength < length )
maxlength = length;
}
width = maxlength * 8 + 6;
for ( i = 1; i < 7; i++ ) {
mainmenu[i].top = 10 + 16 * i;
mainmenu[i].width = width;
}
}
void drawmenu( MENU mainmenu[7] ) {
drawitem( mainmenu[0] );
if ( mainmenu[0].flag ) {
int i;
for ( i = 1; i < 7; i++ )
drawitem( mainmenu[i] );
}
}
void clearmenu( MENU mainmenu[7] ) {
int left, top, right, bottom;
left = mainmenu[0].left;
top = mainmenu[1].top;
right = mainmenu[1].left + mainmenu[1].width;
bottom = mainmenu[6].top + mainmenu[6].height;
setfillstyle( SOLID_FILL, BLACK );
bar( left, top, right, bottom );
drawitem( mainmenu[0] );
}
void drawitem( MENU menu ) {
int left, top, right, bottom;
left = menu.left;
top = menu.top;
right = menu.left + menu.width - 1;
bottom = menu.top + menu.height - 1;
if ( menu.flag ) {
setfillstyle( SOLID_FILL, LIGHTBLUE );
setcolor( WHITE );
}
else {
setfillstyle( SOLID_FILL, LIGHTGRAY );
setcolor( BLACK );
}
bar( left, top, right, bottom );
outtextxy( left + 3, top + 4, menu.caption );
}
这里用图形模式写了一个简单的下拉菜单,你可以自己把相应的操作函数添加到主循环中的switch( fun )中,相信你应该能明白,注意所有的处理函数都要在图形模式下完成,你的一些子函数是在文本模式下写的,记得改掉,我就不一一做了,有什么问题可以随时问我,我的EMAIL:sekelonsa@sohu.com :-)
#include <math.h>
#include <stdio.h>
#include <graphics.h>
#include <string.h>
typedef struct menu {
int number;
char caption[100];
int left, top;
int width, height;
int function;
char flag;
}MENU;
typedef MENU* PMENU;
void initmenu( MENU mainmenu[7] );
void drawmenu( MENU mainmenu[7] );
void drawitem( MENU menu );
void clearmenu( MENU mainmenu[7] );
int main()
{
float a[10][10]={{1.39,1.49,1.43,1.41,1.37,1.40,1.32,1.42,1.39,1.47},
{1.41,1.38,1.40,1.34,1.42,1.42,1.45,1.35,1.42,1.34},
{1.44,1.42,1.39,1.42,1.42,1.30,1.34,1.42,1.37,1.36},
{1.39,1.34,1.37,1.37,1.44,1.45,1.32,1.48,1.40,1.45},
{1.39,1.46,1.39,1.53,1.38,1.48,1.40,1.39,1.38,1.40},
{1.36,1.45,1.50,1.43,1.38,1.43,1.41,1.48,1.39,1.45},
{1.37,1.37,1.39,1.45,1.31,1.41,1.44,1.44,1.43,1.42},
{1.36,1.39,1.40,1.38,1.39,1.42,1.43,1.42,1.43,1.47},
{1.42,1.40,1.41,1.37,1.46,1.36,1.37,1.27,1.37,1.38},
{1.42,1.34,1.43,1.42,1.41,1.41,1.44,1.48,1.55,1.37}};
int gdriver = DETECT, gmode;
int key;
int lastmenu = -1;
char flag = 1;
int fun = -1;
MENU mainmenu[7] = {
{ 6, "menu", 10, 10, 40, 16, -1, 0 },
{ 0, "quit", 10, 0, 0, 16, 0, 0 },
{ 0, "Display the Data", 10, 0, 0, 16, 1, 0 },
{ 0, "Display the Max & Min Number", 10, 0, 0, 16, 2, 0 },
{ 0, "Display the Junzhi & Fangcha", 10, 0, 0, 16, 3, 0 },
{ 0, "Display the Pingshufenbutu", 10, 0, 0, 16, 4, 0 },
{ 0, "Display the Leijipingshufenbutu", 10, 0, 0, 16, 5, 0 } };
initmenu( mainmenu );
initgraph( &gdriver, &gmode, "" );
setcolor( WHITE );
outtextxy( 100, 14, "Press F10 to start the menu" );
drawmenu( mainmenu );
while ( flag ) {
if ( kbhit() ) {
key = getch();
switch ( key ) {
case 27://ESC
if ( mainmenu[0].flag ) {
mainmenu[0].flag = 0;
mainmenu[lastmenu].flag = 0;
lastmenu = -1;
clearmenu( mainmenu );
}
else
flag = 0;
break;;
case 13://ENTER
if ( lastmenu != -1 ) {
fun = mainmenu[lastmenu].function;
mainmenu[0].flag = 0;
mainmenu[lastmenu].flag = 0;
lastmenu = -1;
clearmenu( mainmenu );
}
break;;
}
if ( key == 0 ) {
key = getch();
switch ( key ) {
case 72://up
mainmenu[lastmenu].flag = 0;
drawitem( mainmenu[lastmenu] );
lastmenu--;
if ( lastmenu < 1 )
lastmenu = 1;
mainmenu[lastmenu].flag = 1;
drawitem( mainmenu[lastmenu] );
break;
case 80://down
mainmenu[lastmenu].flag = 0;
drawitem( mainmenu[lastmenu] );
lastmenu++;
if ( lastmenu > 6 )
lastmenu = 6;
mainmenu[lastmenu].flag = 1;
drawitem( mainmenu[lastmenu] );
break;
case 68://F10
if ( mainmenu[0].flag == 0 ) {
mainmenu[0].flag = 1;
mainmenu[1].flag = 1;
lastmenu = 1;
drawmenu( mainmenu );
}
else {
mainmenu[0].flag = 0;
mainmenu[lastmenu].flag = 0;
lastmenu = -1;
clearmenu( mainmenu );
}
break;
}
}
}
switch ( fun ) {
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
default:
break;
}
}
closegraph();
return 0;
}
void initmenu( MENU mainmenu[7] ) {
int maxlength = 0;
int width;
int length;
int i;
for ( i = 1; i < 7; i++ ) {
length = strlen( mainmenu[i].caption );
if ( maxlength < length )
maxlength = length;
}
width = maxlength * 8 + 6;
for ( i = 1; i < 7; i++ ) {
mainmenu[i].top = 10 + 16 * i;
mainmenu[i].width = width;
}
}
void drawmenu( MENU mainmenu[7] ) {
drawitem( mainmenu[0] );
if ( mainmenu[0].flag ) {
int i;
for ( i = 1; i < 7; i++ )
drawitem( mainmenu[i] );
}
}
void clearmenu( MENU mainmenu[7] ) {
int left, top, right, bottom;
left = mainmenu[0].left;
top = mainmenu[1].top;
right = mainmenu[1].left + mainmenu[1].width;
bottom = mainmenu[6].top + mainmenu[6].height;
setfillstyle( SOLID_FILL, BLACK );
bar( left, top, right, bottom );
drawitem( mainmenu[0] );
}
void drawitem( MENU menu ) {
int left, top, right, bottom;
left = menu.left;
top = menu.top;
right = menu.left + menu.width - 1;
bottom = menu.top + menu.height - 1;
if ( menu.flag ) {
setfillstyle( SOLID_FILL, LIGHTBLUE );
setcolor( WHITE );
}
else {
setfillstyle( SOLID_FILL, LIGHTGRAY );
setcolor( BLACK );
}
bar( left, top, right, bottom );
outtextxy( left + 3, top + 4, menu.caption );
}
这里用图形模式写了一个简单的下拉菜单,你可以自己把相应的操作函数添加到主循环中的switch( fun )中,相信你应该能明白,注意所有的处理函数都要在图形模式下完成,你的一些子函数是在文本模式下写的,记得改掉,我就不一一做了,有什么问题可以随时问我,我的EMAIL:sekelonsa@sohu.com :-)
#10
页面太窄,有些东西是一行的,不要搞错了
#1
没有在TC下面编过东西,也帮你顶!
#2
谢谢 我真的很急!帮帮我找人问问好吗?我都快哭了
#3
下拉式菜单。什么意思?是跟Windows的菜单一样,点了什么之后,弹出一个菜单么?
那要用C的图形编程啊
那要用C的图形编程啊
#4
你想做成什么样子的,窗口式带菜单的吗?
#5
如果是的话文字模式和图形模式都是可以做的,不过我没有现成的程序可以提供给你,如果你需要的话要临时再做,希望你可以把要求说的具体些(比如菜单中有些什么项)
#6
把上面的数字菜单改成纵向的下拉式菜单。谢谢!!
#7
你什么时候要?明天可以吗?今天太忙,没时间写了
#8
好的。最好今晚。谢谢!!!!!!
#9
#include <conio.h>
#include <math.h>
#include <stdio.h>
#include <graphics.h>
#include <string.h>
typedef struct menu {
int number;
char caption[100];
int left, top;
int width, height;
int function;
char flag;
}MENU;
typedef MENU* PMENU;
void initmenu( MENU mainmenu[7] );
void drawmenu( MENU mainmenu[7] );
void drawitem( MENU menu );
void clearmenu( MENU mainmenu[7] );
int main()
{
float a[10][10]={{1.39,1.49,1.43,1.41,1.37,1.40,1.32,1.42,1.39,1.47},
{1.41,1.38,1.40,1.34,1.42,1.42,1.45,1.35,1.42,1.34},
{1.44,1.42,1.39,1.42,1.42,1.30,1.34,1.42,1.37,1.36},
{1.39,1.34,1.37,1.37,1.44,1.45,1.32,1.48,1.40,1.45},
{1.39,1.46,1.39,1.53,1.38,1.48,1.40,1.39,1.38,1.40},
{1.36,1.45,1.50,1.43,1.38,1.43,1.41,1.48,1.39,1.45},
{1.37,1.37,1.39,1.45,1.31,1.41,1.44,1.44,1.43,1.42},
{1.36,1.39,1.40,1.38,1.39,1.42,1.43,1.42,1.43,1.47},
{1.42,1.40,1.41,1.37,1.46,1.36,1.37,1.27,1.37,1.38},
{1.42,1.34,1.43,1.42,1.41,1.41,1.44,1.48,1.55,1.37}};
int gdriver = DETECT, gmode;
int key;
int lastmenu = -1;
char flag = 1;
int fun = -1;
MENU mainmenu[7] = {
{ 6, "menu", 10, 10, 40, 16, -1, 0 },
{ 0, "quit", 10, 0, 0, 16, 0, 0 },
{ 0, "Display the Data", 10, 0, 0, 16, 1, 0 },
{ 0, "Display the Max & Min Number", 10, 0, 0, 16, 2, 0 },
{ 0, "Display the Junzhi & Fangcha", 10, 0, 0, 16, 3, 0 },
{ 0, "Display the Pingshufenbutu", 10, 0, 0, 16, 4, 0 },
{ 0, "Display the Leijipingshufenbutu", 10, 0, 0, 16, 5, 0 } };
initmenu( mainmenu );
initgraph( &gdriver, &gmode, "" );
setcolor( WHITE );
outtextxy( 100, 14, "Press F10 to start the menu" );
drawmenu( mainmenu );
while ( flag ) {
if ( kbhit() ) {
key = getch();
switch ( key ) {
case 27://ESC
if ( mainmenu[0].flag ) {
mainmenu[0].flag = 0;
mainmenu[lastmenu].flag = 0;
lastmenu = -1;
clearmenu( mainmenu );
}
else
flag = 0;
break;;
case 13://ENTER
if ( lastmenu != -1 ) {
fun = mainmenu[lastmenu].function;
mainmenu[0].flag = 0;
mainmenu[lastmenu].flag = 0;
lastmenu = -1;
clearmenu( mainmenu );
}
break;;
}
if ( key == 0 ) {
key = getch();
switch ( key ) {
case 72://up
mainmenu[lastmenu].flag = 0;
drawitem( mainmenu[lastmenu] );
lastmenu--;
if ( lastmenu < 1 )
lastmenu = 1;
mainmenu[lastmenu].flag = 1;
drawitem( mainmenu[lastmenu] );
break;
case 80://down
mainmenu[lastmenu].flag = 0;
drawitem( mainmenu[lastmenu] );
lastmenu++;
if ( lastmenu > 6 )
lastmenu = 6;
mainmenu[lastmenu].flag = 1;
drawitem( mainmenu[lastmenu] );
break;
case 68://F10
if ( mainmenu[0].flag == 0 ) {
mainmenu[0].flag = 1;
mainmenu[1].flag = 1;
lastmenu = 1;
drawmenu( mainmenu );
}
else {
mainmenu[0].flag = 0;
mainmenu[lastmenu].flag = 0;
lastmenu = -1;
clearmenu( mainmenu );
}
break;
}
}
}
switch ( fun ) {
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
default:
break;
}
}
closegraph();
return 0;
}
void initmenu( MENU mainmenu[7] ) {
int maxlength = 0;
int width;
int length;
int i;
for ( i = 1; i < 7; i++ ) {
length = strlen( mainmenu[i].caption );
if ( maxlength < length )
maxlength = length;
}
width = maxlength * 8 + 6;
for ( i = 1; i < 7; i++ ) {
mainmenu[i].top = 10 + 16 * i;
mainmenu[i].width = width;
}
}
void drawmenu( MENU mainmenu[7] ) {
drawitem( mainmenu[0] );
if ( mainmenu[0].flag ) {
int i;
for ( i = 1; i < 7; i++ )
drawitem( mainmenu[i] );
}
}
void clearmenu( MENU mainmenu[7] ) {
int left, top, right, bottom;
left = mainmenu[0].left;
top = mainmenu[1].top;
right = mainmenu[1].left + mainmenu[1].width;
bottom = mainmenu[6].top + mainmenu[6].height;
setfillstyle( SOLID_FILL, BLACK );
bar( left, top, right, bottom );
drawitem( mainmenu[0] );
}
void drawitem( MENU menu ) {
int left, top, right, bottom;
left = menu.left;
top = menu.top;
right = menu.left + menu.width - 1;
bottom = menu.top + menu.height - 1;
if ( menu.flag ) {
setfillstyle( SOLID_FILL, LIGHTBLUE );
setcolor( WHITE );
}
else {
setfillstyle( SOLID_FILL, LIGHTGRAY );
setcolor( BLACK );
}
bar( left, top, right, bottom );
outtextxy( left + 3, top + 4, menu.caption );
}
这里用图形模式写了一个简单的下拉菜单,你可以自己把相应的操作函数添加到主循环中的switch( fun )中,相信你应该能明白,注意所有的处理函数都要在图形模式下完成,你的一些子函数是在文本模式下写的,记得改掉,我就不一一做了,有什么问题可以随时问我,我的EMAIL:sekelonsa@sohu.com :-)
#include <math.h>
#include <stdio.h>
#include <graphics.h>
#include <string.h>
typedef struct menu {
int number;
char caption[100];
int left, top;
int width, height;
int function;
char flag;
}MENU;
typedef MENU* PMENU;
void initmenu( MENU mainmenu[7] );
void drawmenu( MENU mainmenu[7] );
void drawitem( MENU menu );
void clearmenu( MENU mainmenu[7] );
int main()
{
float a[10][10]={{1.39,1.49,1.43,1.41,1.37,1.40,1.32,1.42,1.39,1.47},
{1.41,1.38,1.40,1.34,1.42,1.42,1.45,1.35,1.42,1.34},
{1.44,1.42,1.39,1.42,1.42,1.30,1.34,1.42,1.37,1.36},
{1.39,1.34,1.37,1.37,1.44,1.45,1.32,1.48,1.40,1.45},
{1.39,1.46,1.39,1.53,1.38,1.48,1.40,1.39,1.38,1.40},
{1.36,1.45,1.50,1.43,1.38,1.43,1.41,1.48,1.39,1.45},
{1.37,1.37,1.39,1.45,1.31,1.41,1.44,1.44,1.43,1.42},
{1.36,1.39,1.40,1.38,1.39,1.42,1.43,1.42,1.43,1.47},
{1.42,1.40,1.41,1.37,1.46,1.36,1.37,1.27,1.37,1.38},
{1.42,1.34,1.43,1.42,1.41,1.41,1.44,1.48,1.55,1.37}};
int gdriver = DETECT, gmode;
int key;
int lastmenu = -1;
char flag = 1;
int fun = -1;
MENU mainmenu[7] = {
{ 6, "menu", 10, 10, 40, 16, -1, 0 },
{ 0, "quit", 10, 0, 0, 16, 0, 0 },
{ 0, "Display the Data", 10, 0, 0, 16, 1, 0 },
{ 0, "Display the Max & Min Number", 10, 0, 0, 16, 2, 0 },
{ 0, "Display the Junzhi & Fangcha", 10, 0, 0, 16, 3, 0 },
{ 0, "Display the Pingshufenbutu", 10, 0, 0, 16, 4, 0 },
{ 0, "Display the Leijipingshufenbutu", 10, 0, 0, 16, 5, 0 } };
initmenu( mainmenu );
initgraph( &gdriver, &gmode, "" );
setcolor( WHITE );
outtextxy( 100, 14, "Press F10 to start the menu" );
drawmenu( mainmenu );
while ( flag ) {
if ( kbhit() ) {
key = getch();
switch ( key ) {
case 27://ESC
if ( mainmenu[0].flag ) {
mainmenu[0].flag = 0;
mainmenu[lastmenu].flag = 0;
lastmenu = -1;
clearmenu( mainmenu );
}
else
flag = 0;
break;;
case 13://ENTER
if ( lastmenu != -1 ) {
fun = mainmenu[lastmenu].function;
mainmenu[0].flag = 0;
mainmenu[lastmenu].flag = 0;
lastmenu = -1;
clearmenu( mainmenu );
}
break;;
}
if ( key == 0 ) {
key = getch();
switch ( key ) {
case 72://up
mainmenu[lastmenu].flag = 0;
drawitem( mainmenu[lastmenu] );
lastmenu--;
if ( lastmenu < 1 )
lastmenu = 1;
mainmenu[lastmenu].flag = 1;
drawitem( mainmenu[lastmenu] );
break;
case 80://down
mainmenu[lastmenu].flag = 0;
drawitem( mainmenu[lastmenu] );
lastmenu++;
if ( lastmenu > 6 )
lastmenu = 6;
mainmenu[lastmenu].flag = 1;
drawitem( mainmenu[lastmenu] );
break;
case 68://F10
if ( mainmenu[0].flag == 0 ) {
mainmenu[0].flag = 1;
mainmenu[1].flag = 1;
lastmenu = 1;
drawmenu( mainmenu );
}
else {
mainmenu[0].flag = 0;
mainmenu[lastmenu].flag = 0;
lastmenu = -1;
clearmenu( mainmenu );
}
break;
}
}
}
switch ( fun ) {
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
default:
break;
}
}
closegraph();
return 0;
}
void initmenu( MENU mainmenu[7] ) {
int maxlength = 0;
int width;
int length;
int i;
for ( i = 1; i < 7; i++ ) {
length = strlen( mainmenu[i].caption );
if ( maxlength < length )
maxlength = length;
}
width = maxlength * 8 + 6;
for ( i = 1; i < 7; i++ ) {
mainmenu[i].top = 10 + 16 * i;
mainmenu[i].width = width;
}
}
void drawmenu( MENU mainmenu[7] ) {
drawitem( mainmenu[0] );
if ( mainmenu[0].flag ) {
int i;
for ( i = 1; i < 7; i++ )
drawitem( mainmenu[i] );
}
}
void clearmenu( MENU mainmenu[7] ) {
int left, top, right, bottom;
left = mainmenu[0].left;
top = mainmenu[1].top;
right = mainmenu[1].left + mainmenu[1].width;
bottom = mainmenu[6].top + mainmenu[6].height;
setfillstyle( SOLID_FILL, BLACK );
bar( left, top, right, bottom );
drawitem( mainmenu[0] );
}
void drawitem( MENU menu ) {
int left, top, right, bottom;
left = menu.left;
top = menu.top;
right = menu.left + menu.width - 1;
bottom = menu.top + menu.height - 1;
if ( menu.flag ) {
setfillstyle( SOLID_FILL, LIGHTBLUE );
setcolor( WHITE );
}
else {
setfillstyle( SOLID_FILL, LIGHTGRAY );
setcolor( BLACK );
}
bar( left, top, right, bottom );
outtextxy( left + 3, top + 4, menu.caption );
}
这里用图形模式写了一个简单的下拉菜单,你可以自己把相应的操作函数添加到主循环中的switch( fun )中,相信你应该能明白,注意所有的处理函数都要在图形模式下完成,你的一些子函数是在文本模式下写的,记得改掉,我就不一一做了,有什么问题可以随时问我,我的EMAIL:sekelonsa@sohu.com :-)
#10
页面太窄,有些东西是一行的,不要搞错了