enum{FIRST,CALCULATE,SECOND,RESULT};
創(chuàng)新互聯(lián)建站制作網(wǎng)站網(wǎng)頁找三站合一網(wǎng)站制作公司,專注于網(wǎng)頁設(shè)計(jì),成都網(wǎng)站制作、網(wǎng)站建設(shè),網(wǎng)站設(shè)計(jì),企業(yè)網(wǎng)站搭建,網(wǎng)站開發(fā),建網(wǎng)站業(yè)務(wù),680元做網(wǎng)站,已為上千服務(wù),創(chuàng)新互聯(lián)建站網(wǎng)站建設(shè)將一如既往的為我們的客戶提供最優(yōu)質(zhì)的網(wǎng)站建設(shè)、網(wǎng)絡(luò)營銷推廣服務(wù)!
int?menu(int?status,int?result=0)
{
switch(status)
{
case?FIRST:
{
printf("請(qǐng)輸入第一個(gè)數(shù)");
int?x;
scanf("%d",x);
return?x;
break;
}
case?SECOND:
{
printf("請(qǐng)輸入第二個(gè)數(shù)");
int?x;
scanf("%d",x);
return?x;
break;
}
case?CALCULATE:
{
printf("請(qǐng)輸入運(yùn)算符號(hào)");
char?x;
scanf("%c",x);
return?x;
break;
}
case?RESULT:
{
printf("運(yùn)算結(jié)果是%d\n",result);
return?1;
break;
}
}
}
main()
{
int?x=0,y=0,status=0,result=0,calculate
x=menu(status);
status++;
while(!(calculate=='+'?|?calculate=='-'?|?calculate=='*'?|?calculate=='/'))
calculate=menu(status);
status++;
y=menu(status);
status++;
switch(calculate)
{
case?'+':result=x+y;break;
case?'-':result=x-y;break;
case?'*':result=x*y;break;
case?'/':result=x/y;break;
}
menu(status,result);
}
//求長度
int Length(char* szSrc)
{ static int nCount=0;
while(*(szSrc+nCount)!='\0')
nCount++;
return nCount;
}
//有一個(gè)字符串,包含n個(gè)字符。寫一函數(shù),將此字符串從第m個(gè)字符開始的全部字符復(fù)制成另一個(gè)字符串。
char* Mid(char* szSrc,int n1,int n2)
{
static char sz[1024];
memset(sz,0,sizeof(sz));
strncpy(sz,szSrc+n1,n2-n1+1);
return sz;
}
//逆序 數(shù)字逆序要把長度也送進(jìn)去
void changestr(char *szSrc)
{
static int nCount=0;
do(*(szSrc+nCount)!='\0')
nCount++;
for(int i=0; i=nCount/2;i++)
{
char ch;
ch =*(szSrc+i);
*(szSrc+i) = *(szSrc+nCount-i);
*(szSrc+nCount-i)=ch;
}
1、對(duì)于窗口組件菜單,需要根據(jù)不同平臺(tái),通過圖形編程接口,進(jìn)行菜單的編制。
例程:
#includestdio.h?
#includegraphics.h?
#includeconio.h?
void?main()?
{?
char?str;?
int?i,k,choice=1;?
int?gd=DETECT,gm;?
initgraph(gd,gm,"?");?
setbkcolor(2);?
settextstyle(3,0,3);?
outtextxy(140,120,"A.?The?Mock?Clock.");?
outtextxy(140,150,"B.?The?Digital?Clock.");?
outtextxy(140,180,"C.?Exit.");?
setlinestyle(0,0,3);?
rectangle(170,115,370,145);?
/*按上下鍵選擇所需選項(xiàng)*/?
for(i=1;i=100;i++)?
{?
str=getch();?
if(str==72)?
{?
--choice;?
if(choice==0)choice=3;?
}?
if(str==80)?
{?
++choice;?
if(choice==4)choice=1;?
}?
if(str==13)break;?/*按回車鍵確認(rèn)*/?
/*畫圖做菜單*/?
cleardevice();?
switch(choice)?
{?case?1:?setlinestyle(0,0,3);?
rectangle(170,115,400,145);?
settextstyle(3,0,3);?
outtextxy(140,120,"A.?The?Mock?Clock.");?
settextstyle(3,0,3);?
outtextxy(140,150,"B.?The?Digital?Clock.");?
outtextxy(140,180,"C.?Exit.");?
break;?
case?2:?setlinestyle(0,0,3);?
rectangle(170,145,400,175);?
settextstyle(3,0,3);?
outtextxy(140,120,"A.?The?Mock?Clock.");?
settextstyle(3,0,3);?
outtextxy(140,150,"B.?The?Digital?Clock.");?
settextstyle(3,0,3);?
outtextxy(140,180,"C.?Exit.");?
break;?
case?3:?settextstyle(3,0,3);?
outtextxy(140,120,"A.?The?Mock?Clock.");?
outtextxy(140,150,"B.?The?Digital?Clock.");?
settextstyle(3,0,3);?
outtextxy(140,180,"C.?Exit.");?
setlinestyle(0,0,3);?
rectangle(170,175,400,205);?
break;?
}?
}?
if(i=100)exit(0);/*如果按鍵超過100次退出*/?
switch(choice)/*這里引用函數(shù),實(shí)現(xiàn)所要的功能*/?
{?
case?1:?cleardevice();?
setbkcolor(4);?
settextstyle(3,0,4);?
outtextxy(160,120,"No.1?have?not?built.");?break;?
case?2:?cleardevice();?
setbkcolor(4);?
settextstyle(3,0,4);?
outtextxy(160,150,"No.2?have?not?built.");?
break;?
case?3:?exit(0);?
}?
getch();?
closegraph();?
}
2、對(duì)于命令行菜單,直接通過不斷刷新輸出來模擬菜單行為。
例程:
#include?stdio.h
#include?stdlib.h?
#include?string.h
int?n,t,k;
int?m;
char?s1[20],s2[20],c;
char?**l;
char?*num[]={"one","two","three","four","five","six","seven","eight","nine","ten"};
void?menu()
{
printf("\n\n\t\t*******************************************************\n");
printf("\t\t**???1.查找字符串S1中S2出現(xiàn)的次數(shù)????????????????????**\n");
printf("\t\t**???2.統(tǒng)計(jì)字符串中大小寫字母,數(shù)字出現(xiàn)的次數(shù)????????**\n");
printf("\t\t**???3.將數(shù)字翻譯成英語??????????????????????????????**\n");
printf("\t\t**???4.結(jié)束??????????????????????????????????????????**\n");
printf("\t\t*******************************************************\n");
printf("\t\t?????您的輸入:");
fflush(stdin);
scanf("%d",n);
}
void?check()
{
char?a[20],b[20];
int?j=0,k,m,l=0;
int?t=0,n=0;
printf("請(qǐng)輸入主字符串:\n");
scanf("%s",a);
k=strlen(a);
printf("請(qǐng)輸入子字符串:\n");
scanf("%s",b);
m=strlen(b);
for(n=0;nk;n++)
if(a[n]==b[0])
{
j++;?/*記錄相同的字符數(shù)*/
do
{????
if(a[++n]==b[++t])
{?
j++;
if(j==m)?
{
l++;/*子字符串相同數(shù)*/
j=0;/*判斷后相同字符數(shù)歸零*/
t=-1;/*判斷中if中++t;t將會(huì)歸零*/
}
}
else
{
j=0;
t=0;
break;/*如果不同跳出while循環(huán)讓for使n+1繼續(xù)判斷*/
}
}while(a[n]!='\0');/*查找完字符數(shù)組a結(jié)束*/
}
printf("子字符串出現(xiàn)次數(shù):\n%d\n",l);
}??????????????????????????????????
void?cout()
{
int?n=0,t=0,k=0;
printf("請(qǐng)輸入一個(gè)字符串:\n");
fflush(stdin);/*清除緩沖*/
while((c=getchar())!='\n')
{
if(c='a'c='z')
n++;
if(c='A'c='Z')
t++;
if(c='0'c='9')
k++;
}
printf("有大寫字母:\n%d\n",t);
printf("有小寫字母:\n%d\n",n);
printf("有數(shù)字:\n%d\n",k);
}
void?number()
{
l=num;
printf("請(qǐng)輸入一個(gè)數(shù)字:(0-10)\n");
fflush(stdin);
scanf("%d",m);
printf("%d對(duì)應(yīng)的英文是:\n%s\n",m,*(l+m-1));
}
void?main()
{
while(1)
{???
system("cls");
menu();
switch(n)
{
case?1:system("cls");check();system("pause");break;
case?2:system("cls");cout();system("pause");break;
case?3:system("cls");number();system("pause");break;
case?4:system("cls");break;
default:system("cls");break;?
}
if(n==4)?break;
}
printf("感謝使用\n");
}