菜單編程
Ⅰ 跪求 使用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]!='