当前位置:首页 » 编程语言 » c语言设计一个文本菜单
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

c语言设计一个文本菜单

发布时间: 2022-06-29 07:17:18

‘壹’ 如何用c语言编写菜单项

在C语言中,通常菜单有系统菜单、弹出菜单、下拉菜单等,不知道你要做哪一种。
菜单的制作,通常需要一下几个步骤:
1、定义菜单项目数据结构;
2、定义你要做的弹出菜单或下拉菜单或...的数据结构;
3、建立菜单内容;
4、加载菜单内容;
5、在某个位置上显示(包含保存原有内容以备关闭菜单后恢复覆盖的屏幕,测试菜单显示区域根据实际情况调整显示区域);
6、光标移动,菜单项目颜色变化;
7、执行选中菜单项程序;
8、关闭菜单。
如果纯粹用C语言写,写一个通用的,估计至少要上千行程序代码,以前做过,后来不再使用C语言了,放在机器上,就找不到了。要不就放上去了。

‘贰’ 如何用c语言实现文本菜单界面

/************************************************
*函数名:Menu
*功能:绘制主菜单界面,并根据输入转跳到其它功能
************************************************/
intMenu()
{
charcScan; //cScan用于记录键盘的输入

/*┏━┓┃┛┗*/

printf(" ");
printf(" ┏━━━━━━━━━━━━━━━━━━━━━━━━━┓ ");
printf(" ┃欢迎使用员工管理系统BetaV1.0┃ ");
printf(" ┃by1500830221┃ ");
printf(" ┃1、查看所有员工信息┃ ");
printf(" ┃2、添加员工┃ ");
printf(" ┃3、查找员工┃ ");
printf(" ┃4、删除员工或修改资料┃ ");
printf(" ┃5、重设密码┃ ");
printf(" ┃6、将员工信息以文本文档输出┃ ");
printf(" ┃7、清屏┃ ");
printf(" ┃8、查看版本信息┃ ");
printf(" ┃9、退出┃ ");
printf(" ┃┃ ");
printf(" ┗━━━━━━━━━━━━━━━━━━━━━━━━━┛ ");
cScan=getch();
returncScan-48;

}

‘叁’ 怎样用C语言编写菜单

  1. 对于窗口组件菜单,需要根据不同平台,通过图形编程接口,进行菜单的编制。

    例程:

    #include<stdio.h>
    #include<graphics.h>
    #include<conio.h>
    voidmain()
    {
    charstr;
    inti,k,choice=1;
    intgd=DETECT,gm;
    initgraph(&gd,&gm,"");
    setbkcolor(2);
    settextstyle(3,0,3);
    outtextxy(140,120,"A.TheMockClock.");
    outtextxy(140,150,"B.TheDigitalClock.");
    outtextxy(140,180,"C.Exit.");
    setlinestyle(0,0,3);
    rectangle(170,115,370,145);
    /*按上下键选择所需选项*/
    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;/*按回车键确认*/
    /*画图做菜单*/
    cleardevice();
    switch(choice)
    {case1:setlinestyle(0,0,3);
    rectangle(170,115,400,145);
    settextstyle(3,0,3);
    outtextxy(140,120,"A.TheMockClock.");
    settextstyle(3,0,3);
    outtextxy(140,150,"B.TheDigitalClock.");
    outtextxy(140,180,"C.Exit.");
    break;
    case2:setlinestyle(0,0,3);
    rectangle(170,145,400,175);
    settextstyle(3,0,3);
    outtextxy(140,120,"A.TheMockClock.");
    settextstyle(3,0,3);
    outtextxy(140,150,"B.TheDigitalClock.");
    settextstyle(3,0,3);
    outtextxy(140,180,"C.Exit.");
    break;
    case3:settextstyle(3,0,3);
    outtextxy(140,120,"A.TheMockClock.");
    outtextxy(140,150,"B.TheDigitalClock.");
    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)/*这里引用函数,实现所要的功能*/
    {
    case1:cleardevice();
    setbkcolor(4);
    settextstyle(3,0,4);
    outtextxy(160,120,"No.1havenotbuilt.");break;
    case2:cleardevice();
    setbkcolor(4);
    settextstyle(3,0,4);
    outtextxy(160,150,"No.2havenotbuilt.");
    break;
    case3:exit(0);
    }
    getch();
    closegraph();
    }
  2. 对于命令行菜单,直接通过不断刷新输出来模拟菜单行为。

    例程:

    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    intn,t,k;
    intm;
    chars1[20],s2[20],c;
    char**l;
    char*num[]={"one","two","three","four","five","six","seven","eight","nine","ten"};
    voidmenu()
    {
    printf(" ******************************************************* ");
    printf(" **1.查找字符串S1中S2出现的次数** ");
    printf(" **2.统计字符串中大小写字母,数字出现的次数** ");
    printf(" **3.将数字翻译成英语** ");
    printf(" **4.结束** ");
    printf(" ******************************************************* ");
    printf(" 您的输入:");
    fflush(stdin);
    scanf("%d",&n);
    }
    voidcheck()
    {

    chara[20],b[20];
    intj=0,k,m,l=0;
    intt=0,n=0;
    printf("请输入主字符串: ");
    scanf("%s",a);
    k=strlen(a);
    printf("请输入子字符串: ");
    scanf("%s",b);
    m=strlen(b);
    for(n=0;n<k;n++)
    if(a[n]==b[0])
    {
    j++;/*记录相同的字符数*/
    do
    {
    if(a[++n]==b[++t])
    {
    j++;
    if(j==m)
    {
    l++;/*子字符串相同数*/
    j=0;/*判断后相同字符数归零*/
    t=-1;/*判断中if中++t;t将会归零*/
    }
    }
    else
    {
    j=0;
    t=0;
    break;/*如果不同跳出while循环让for使n+1继续判断*/
    }
    }while(a[n]!='');/*查找完字符数组a结束*/
    }
    printf("子字符串出现次数: %d ",l);
    }
    voidcout()
    {
    intn=0,t=0,k=0;
    printf("请输入一个字符串: ");
    fflush(stdin);/*清除缓冲*/
    while((c=getchar())!=' ')
    {
    if(c>='a'&&c<='z')
    n++;
    if(c>='A'&&c<='Z')
    t++;
    if(c>='0'&&c<='9')
    k++;
    }
    printf("有大写字母: %d ",t);
    printf("有小写字母: %d ",n);
    printf("有数字: %d ",k);
    }
    voidnumber()
    {
    l=num;
    printf("请输入一个数字:(0-10) ");
    fflush(stdin);
    scanf("%d",&m);
    printf("%d对应的英文是: %s ",m,*(l+m-1));
    }
    voidmain()
    {
    while(1)
    {
    system("cls");
    menu();
    switch(n)
    {
    case1:system("cls");check();system("pause");break;
    case2:system("cls");cout();system("pause");break;
    case3:system("cls");number();system("pause");break;
    case4:system("cls");break;
    default:system("cls");break;
    }
    if(n==4)break;
    }
    printf("感谢使用 ");
    }

‘肆’ 用C语言制作一个简单实用菜单的程序。

#include<iostream>
#include<stdlib.h>
#include<conio.h>
#include<ctype.h>
usingnamespacestd;
voidxuanzepaixu()//选择排序函数
{
printf("待添加,请按任意键继续...");
getchar();
}
voiderfenpaixu()//二分查找函数
{
printf("待添加,请按任意键继续...");
getchar();
}

voidmenu()//主菜单
{
system("cls");//清屏
printf(" 菜单 ");
printf(" #***********************# ");
printf(" #1选择排序# ");
printf(" #2二分查找# ");
printf(" #3返回# ");
printf(" #4---关闭# ");
printf(" #***********************# ");
printf(" 请选择(1-4)=:");
}
voidmain()
{
charselect;
while(1)
{
menu();
system("COLOR9f");
scanf("%c",&select);
if(select=='3')
break;//返回上级菜单
else
{
getchar();//读入回车符
if(!isdigit(select))//如果不是数字字符
{
printf(" 7Yourselectmaybewrong,mustenterthedigit! ");_getch();
}
else
{

switch(select)
{
case'1':xuanzepaixu();break;
case'2':erfenpaixu();break;
case'4':exit(0);//直接退出
default:
{
printf(" 77Yourselecteddigitmaybewrong,selectagain! ");
_getch();
break;
}
}
}
}
}

}

‘伍’ 怎么用C语言编写菜单

#include "stdio.h"
#include "stdlib.h"
#include "dos.h"
#include "windows.h"
char choice1;
void main()
{
void menue1();
printf("欢迎进入Ben的作业查询系统!");
menue1();
}
void menue1()
{
void choicemenue1();
printf("\n请按照以下列表选择您想要查看的章节:");
printf("\n编号\t章节\n 1\t第一章\n 2\t第二章\n");
printf("请输入编号进行选择:");
choicemenue1();
}
void choicemenue1()
{
choice1=getch();
switch(choice1)
{
void menuechapter1();
void menuechapter2();
void menue1();
case '1':menuechapter1();break;
case '2':menuechapter2();break;
default:printf("\n输入错误!请重新选择!\n"),menue1();
}}
void menuechapter1()
{
char choiceex;
printf("\n您选择的是第%c章",choice1);
printf("\n现在请选择本章节的题目。");
printf("\n请按照以下列表选择题目:");
printf("\n编号\t题目编号\n1\t第1题\n2\t第2题\n");
printf("请选择:");
switch(choiceex=getch())
{
void c1_1();
void c1_2();
case '1':c1_1();break;
case '2':c1_2();break;
default:
printf("\n你个白痴!这也能选错!不让你重选了!");
printf("\n按任意键以退出!");
getch();
exit(0);
}
}
void menuechapter2()
{
char choiceex;
printf("\n您选择的是第%c章",choice1);
printf("\n现在请选择本章节的题目。");
printf("\n请按照以下列表选择题目:");
printf("\n编号\t题目编号\n1\t第1题\n2\t第2题\n");
printf("\n请选择:");
switch(choiceex=getch())
{
void c2_1();
void c2_2();
case '1':c2_1();break;
case '2':c2_2();break;
default:
printf("\n你个白痴!这也能选错!不让你重选了!");
printf("\n按任意键以退出!");
getch();
exit(0);
}
}
void c1_1()
{
char howtorun;
printf("现在请选择考察方式:");
printf("\n编号\t考察方式\n 1\t运行程序\n 2\t查看源代码\n 3\t返回主菜单\n 4\t退出程序\n");
printf("请选择:");
switch(howtorun=getch())
{
void runc1_1();
void menue1();
case '1':runc1_1();break;
case '2':printf("\n"),system("type \\caidan\\chapter1\\c1_1.c"),printf("\n"),getch();break;
case '3':menue1();break;
case '4':exit(0);break;
default:
printf("程序即将结束!哈哈哈……");
printf("按任意键以结束程序!");
getch();
exit(0);
}}
void c1_2()
{
printf("c1_2 is OK!");
}void c2_1()
{
printf("c2_1 is OK!");
}void c2_2()
{
printf("c2_2 is OK!");
}
void runc1_1()
{
int a,b,max;
printf("\nPlease input two integer numbers:");
printf("a=?,b=?\n");
scanf("%d,%d",&a,&b);
max=a>b?a:b;
printf("The max number is %d",max);
}
大概就是这样做的。。

‘陆’ 如何用“C语言”实现“选项有功能的文本菜单”

1、直接用输出即可实现、

2、例程:

#include<stdio.h>
#include<stdlib.h>
voidhello()
{
printf("helloworld ");
}
intmain()
{
intx;
while(1)
{
printf("-------------操作选项----------- ");
printf("1:返回菜单 ");
printf("2:退出程序 ");
printf("3:执行操作 ");
printf("-------------------------------- ");

printf("按数字键选择要执行的操作:");
scanf("%d",&x);
printf(" ");
//输入2跳出循环,退出程序
if(x==2)
break;

switch(x)
{
case1:break;//输入1,跳出switch语句,进入下一次循环
case3:hello();break;
default://数字输入错误,跳出siwtch语句,进入下一次循环
printf("输入的数字不正确 ");
break;
}
}
return0;
}

‘柒’ C语言编写菜单

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
//值传递
voidfun1(chara)
{
a='b';
}
//地址传递
charfun2(char*a)
{
*a='a';
return*a;
}
//动态分配数组
voidfun3(char*&a)
{
a=(char*)malloc(sizeof(char));
}
charcaidan()
{
charchoose[5];
printf(" *************************************** ");
printf("┌──────┐ ");
printf("│菜单│ ");
printf("__________________________________ ");
printf("│1,按值传递| ");
printf("│2,按地址传递| ");
printf("│3,动态数组演示| ");
printf("│4,退出| ");
printf("└────────────────┙ ");
printf("************************************** ");
do
{
printf("请输入您的选择(1-4):");
scanf("%s",choose);
}while(strcmp(choose,"1")&&strcmp(choose,"2")&&strcmp(choose,"3")&&strcmp(choose,"4"));
//返回选择的菜单,注意如果输入太长这里会异常,因为choose[5],只申请了5个字节。
returnchoose[0];
}
voidmain()
{
//执行菜单的选择
while(1)
{
switch(caidan())
{
case'1':
{
chara='a';
fun1(a);
//按值传递内容不变
break;
}
case'2':
{
charb='b';
chara=fun2(&b);
//按地址传递内容会变
break;
}
case'3':
{
char*p=NULL;
fun3(p);
//动态数组分配成功
break;
}
case'4':exit(0);
}
}

}

‘捌’ 用c语言编写一个菜单!

程序如下:

#include<stdio.h>
#include<string.h>


intMENU_Print(ints32QuerNum)
{
switch(s32QuerNum)
{
case1:
printf("您选择的题目如下: ");
printf("1、以下可以正确表示标识符的是:() ");
printf("A、Data,Double ");
printf("B、case,Big ");
printf("C、2011A,hi_ok ");
printf("D、_2011,year-month-data ");
break;
case2:
printf("您选择的题目如下: ");
printf("2、以下运算符优先级最低的是:() ");
printf("A、?: ");
printf("B、++ ");
printf("C、&& ");
printf("D、+= ");
break;
case3:
printf("您选择的题目如下: ");
printf("2、以下选项中不能正确赋值的是:() ");
printf("A、chars[20];s="ABCDE" ");
printf("B、chars[]="ABCDE" ");
printf("C、chars[20]={"ABCDE"} ");
printf("D、chars[20]={'A','B','C'} ");
break;
default:
break;
}

return0;
}

intmain()
{
ints32ChooseNum=0;
while(1)
{
printf(" 题号范围为1-3,请输入题号: ");
scanf("%d",&s32ChooseNum);

if(s32ChooseNum<1||s32ChooseNum>3)
{
printf("题号范围为1-3,您是输入超出的范围,请重新输入 ");
continue;
}

MENU_Print(s32ChooseNum);

}

return0;
}


运行结果:


我也不知道有没有理解你的意思,你看看是否合适。。。,我没有做选择输入和结果的判断,如果需要的话可以加上去,你可以告诉我你的具体要求

以上

‘玖’ C语言程序设计 编制程序:编制一个文本菜单 用来对学生信息进行输入、修改、删除和显示 谁帮忙改下

LZ,你这个是C++风格的代码。代码已经改好了,可以运行,请采纳我的答案吧,谢谢!

#include<IOSTREAM>

#include<string>

#include<CSTDLIB>

usingnamespacestd;

#defineN4

structSTUDENT

{

charnum[20];

charname[20];

charsex;

intage;

floatscore;

}st[N];

voidins()

{

intc=0;

cout<<endl<<"请输入一个学生的数据";

cin>>st[c].num>>st[c].name>>st[c].sex>>st[c].age;

c++;

}

voiddel()

{

st[0];st[1];st[2];st[3];st[4];

intx,i,c=0;

cout<<"请输入删除的学生下标";

cin>>x;

if(x<c&&x>=0)

{

for(i=x;i<c-1;i++)

{

strcpy(st[i].num,st[i+1].num);

strcpy(st[i].name,st[i+1].name);

st[i].sex=st[i+1].sex;

st[i].age=st[i+1].age;

st[i].score=st[i+1].score;

}

c--;

}

else

cout<<endl<<"没有此人";

}

voidcha()

{

intx,c;

cout<<endl<<"请输入修改的学生下标";

cin>>x;

if(x<c&&x>=0)

{

cout<<endl<<"请输入一个学生的数据";

cin>>st[c].num>>st[c].name>>st[c].sex>>st[c].age;

}

else

cout<<endl<<"没有此人";

}

voidsort()

{

intp,c;

STUDENTmin;

for(inti=0;i<c;i++)

{

min=st[i];p=i;

for(intj=i+1;j<c+1;j++)

if(strcmp(st[j].num,min.num)<0)

{

min=st[j];

p=j;

}

st[p]=st[i];

st[i]=min;

}

}

voiddisp()

{

inti,c;

for(i=0;i<c;i++)

cout<<st[c].num<<st[c].name<<st[c].sex<<st[c].age<<st[c].score;

}

intmain()

{

STUDENTone;

intchoice=0;

do

{

cout<<"1-----insert"<<endl;

cout<<"2-----delete"<<endl;

cout<<"3-----change"<<endl;

cout<<"4-----sort"<<endl;

cout<<"5-----display"<<endl;

cout<<"6-----exit"<<endl;

cout<<"请选择:";

cin>>choice;

switch(choice)

{

case1:

ins();

break;

case2:

del();

break;

case3:

cha();

break;

case4:

disp();

break;

case5:

sort();

break;

case6:

exit(0);

break;

default:

return1;

}

}while(1);

return0;

}

改了好久,现在可以运行了,请采纳我的答案吧,谢谢!

‘拾’ C语言 编写菜单

#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出现的次数 **\n");
printf("\t\t** 2.统计字符串中大小写字母,数字出现的次数 **\n");
printf("\t\t** 3.将数字翻译成英语 **\n");
printf("\t\t** 4.结束 **\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("请输入主字符串:\n");
scanf("%s",a);
k=strlen(a);
printf("请输入子字符串:\n");
scanf("%s",b);
m=strlen(b);
for(n=0;n<k;n++)
if(a[n]==b[0])
{
j++; /*记录相同的字符数*/
do
{
if(a[++n]==b[++t])
{
j++;
if(j==m)
{
l++;/*子字符串相同数*/
j=0;/*判断后相同字符数归零*/
t=-1;/*判断中if中++t;t将会归零*/
}
}
else
{
j=0;
t=0;
break;/*如果不同跳出while循环让for使n+1继续判断*/
}
}while(a[n]!='\0');/*查找完字符数组a结束*/
}
printf("子字符串出现次数:\n%d\n",l);
}

void cout()
{
int n=0,t=0,k=0;
printf("请输入一个字符串:\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("有数字:\n%d\n",k);
}

void number()
{
l=num;
printf("请输入一个数字:(0-10)\n");
fflush(stdin);
scanf("%d",&m);
printf("%d对应的英文是:\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");
}

楼主,终于帮你写完了,完美测试成功,第一功能因为学艺未精写了两个小时,艾,呵呵,不过我还是很开心,如果你有什么不懂可以HI我,我会帮你解答,呵呵,真的好开心,终于写出来了
哈哈。。。。