菜单编程
Ⅰ 跪求 使用C语言生成下拉菜单的编程
下拉菜单?用C来做?
可以的,这是c的高级应用。代码嘛可能超过1000行。推荐看这本书,很不错的,网上有清晰的电子版:
C高级实用程序设计(王仕元 编着 清华大学出版社)
Ⅱ 求C++编程题目【菜单】计算机菜单中有N个操作,而每个操作都会用一个或更多的单词来描述。
#include<iostream> //cin,cout,cerr
#include<cctype> //toupper
#include<string> //string
#include<vector> //vector
#include<sstream> //stringstream
#include<fstream> //ifstream,ofstream
usingnamespacestd;
boolletterExist[26]={false}; //用于查询快捷键(即字母)是否存在的标志
vector<vector<string>>menuVec; //存储所有菜单信息的二维向量(类似于二维数组)
conststringinputFile="./izbornik.in";
conststringoutputFile="./izbornik.out";
intinput()
{
ifstreamread(inputFile,ios::in);
if(!read)
{
cerr<<"[READ]Openfileerror!"<<endl;
return-1;
}
stringmenu;
while(getline(read,menu)) //从文件读取菜单信息(一行,包括空格)
{
//拆分一行的菜单,形成菜单的单词向量(数组)
stringstreamss;
ss<<menu;
stringword;
vector<string>wordVec;
while(ss>>word)
wordVec.push_back(word);
//
menuVec.push_back(wordVec);
}
read.close();
return0;
}
voidprocess()
{
//初始化标志
for(inti=0;i<26;++i)
letterExist[i]=false;
//处理每个菜单
for(inti=0;i<menuVec.size();++i)
{
boolisFind=false;
//step1:首先找同一菜单每个单词的首字母
//[0]所有单词首字母
for(intj=0;j<menuVec[i].size();++j)
{
intindex=toupper(menuVec[i][j][0])-'A';
//cout<<i<<"|"<<j<<"|"<<"0"<<endl;
if(!letterExist[index])
{
//
stringheadStr;
headStr+='[';
headStr+=menuVec[i][j][0];
headStr+=']';
menuVec[i][j]=headStr+
menuVec[i][j].substr(1,menuVec[i][j].size()-1);
//
letterExist[index]=true;
isFind=true;
break;
}
}
//![0]
//step2:让后从剩下的所有单词字母中找
//[1]除去首字母之外后的所有字母
if(!isFind)
{
for(intj=0;j<menuVec[i].size();++j)
{
for(intk=1;k<menuVec[i][j].size();++k)
{
intindex=toupper(menuVec[i][j][k])-'A';
//cout<<i<<"|"<<j<<"|"<<k<<endl;
if(!letterExist[index])
{
//
stringheadStr;
headStr+=menuVec[i][j].substr(0,k);
headStr+='[';
headStr+=menuVec[i][j][k];
headStr+=']';
menuVec[i][j]=headStr+
menuVec[i][j].substr(k+1,menuVec[i][j].size()-k-1);
//
letterExist[index]=true;
isFind=true;
break;
}
}
if(isFind)
break;
}
}
//![1]
}
}
intoutput()
{
ofstreamwrite(outputFile,ios::out);
if(!write)
{
cerr<<"[WRITE]Openfileerror!"<<endl;
return-1;
}
for(inti=0;i<menuVec.size();++i)
{
intj;
for(j=0;j<menuVec[i].size()-1;++j)
{
write<<menuVec[i][j]<<"";
}
write<<menuVec[i][j]<<endl;
}
write.close();
return0;
}
intmenu_main()
{
if(input()==0)
{
process();
if(output()==0)
{
cout<<"Allprocessdone!"<<endl;
return0;
}
else
return-1;
}
else
{
return-1;
}
}
备注:
输入文件放在当前目录下(和main文件同级),文件只存放菜单内容,如:
New
Open
Save
Save As
Save All
其他格式可按照题目要求改~
Ⅲ 如何用HTML编程实现下拉菜单
下拉菜单,其实就是使用HTML+css和一些小小的js就能很简单的实现,
首先需要你有至少有2个div然后在将第一个div作为父级元素,然后在使用position:absolut;绝对定位一下;
然后在使用JS,获取对象,然后添加一个鼠标的onmouseover事件就行了
在这里给你看下我以前的写的一个代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>简洁实用的二级下拉导航菜单</title>
<meta http-equiv="content-type" content="text/html;charset=gb2312">
<!--把下面代码加到<head>与</head>之间-->
<style type="text/css">
body,html{padding:0;margin:0;text-align:center;font:normal 14px 'arial';}
#mainNavBar{width:100%;background:#999;padding:10px 0;}
#nav{width:760px;height:30px;margin:0 auto;}
#nav ul{padding:0;margin:0;}
#nav ul li{position:relative;float:left;width:60px;height:30px;line-height:30px;overflow:hidden;list-style-type:none;}
#nav ul li a{display:block;color:#fff;text-decoration:none;}
#nav ul li a:hover{font-weight:bold;background:#666;}
#subNav{position:absolute;width:150px;top:30px;left:0px;padding:5px;background:#666;color:#fff;text-align:left;}
#subNav a{text-decoration:none;font-weight:normal;display:block;}
#subNav a:hover{color:#f00;background:#f00;}
</style>
</head>
<body>
<!--把下面代码加到<body>与</body>之间-->
<div id="mainNavBar">
<div id="nav">
<ul>
<li>
<a href="#">Add</a>
<div id="subNav">
<a href="#">写日志</a>
<a href="#">增加分类</a>
</div>
</li>
<li>
<a href="#">Edit</a>
<div id="subNav">
<a href="#">修改分类</a>
<a href="#">文章编辑</a>
</div>
</li>
<li>
<a href="#">Admin</a>
<div id="subNav">
<a href="#">文章管理</a>
<a href="#">评论管理</a>
<a href="#">留言管理</a>
<a href="#">退出</a>
</div>
</li>
</ul>
</div>
</div>
<script language="javascript">
var nav=document.getElementById("nav").getElementsByTagName("li");
for(i=0;i<nav.length;i++){
nav[i].onmouseover=function(){
this.style.fontWeight="bold";
this.style.overflow="visible";
this.style.background="#666666";
}
nav[i].onmouseout=function(){
this.style.fontWeight="normal";
this.style.background="#999999"
this.style.overflow="hidden";
}
}
</script>
</body>
</html>
#header #shousuo{
width:950px;
height:50px;
background:#f4f4f4;
margin-top:10px;
}
#shousuo ul li{
line-height:50px;
list-style-type:none;
float:left;
margin-left:5px;
font-weight:bold;
font-size:14px;
}
Ⅳ Excel 如何编程自定义多级菜单
“EXCEL中实现多级联动的 下拉菜单 ”的操作步骤是:1、以Excel 2016为例,打开Excel 工作表 ;2、在F:H列以一级菜单为标题,二级菜单纵向排列的方式建表;3、选择一级菜单设置区域,在“数据”选项下的“ 数据验证 ”(Exce 2007以下版本的“ 数据有效性 ”)中,“设置”选项选择“序列”,来源选择F1:H1单元格,确定;
4、选择F:H列,在“公式”选项下的“根据所选内容创建”,在“选定区域创建名称”对话框中,勾选“首行”,按“确定”,完成创建名称;
5、选择二级菜单设置区域,在“数据”选项下的“ 数据有效性 ”中,“设置”选项选择“序列”,来源输入=INDIRECT(A2) 确定;
6、在一级菜单设置区域,点击下拉选项按钮,选择相应的菜单内容;
7、在二级菜单设置区域,点击选项按钮,会弹出与一级菜单相对应的二级菜单,供选择。
Ⅳ 怎样用C语言编写菜单
对于窗口组件菜单,需要根据不同平台,通过图形编程接口,进行菜单的编制。
例程:
#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();
}对于命令行菜单,直接通过不断刷新输出来模拟菜单行为。
例程:
#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]!='