[C] 菜单 →→→→→进入此内容的聊天室

来自 , 2020-06-08, 写在 C, 查看 110 次.
URL http://www.code666.cn/view/b06b5541
  1. #include "conio.h"
  2. #include "windows.h"
  3. #include "iostream"
  4. #include "string"
  5. #include "ctime"
  6. #include <sstream>
  7. using namespace std;
  8. void delay(int tm)// 延时函数:毫秒
  9.         {long t0=clock(); while(clock()-t0<tm); }
  10. string int2string(int k)//整数转成字符串
  11.         {stringstream ss;ss<<k;return ss.str(); }
  12. void  Fsorry(string st)
  13.         {       for(int i=0;i<st.length();i++)
  14.                 {cout<<st[i];delay(100);} cout<<endl;
  15.         }
  16. void Fmem(string st="")
  17.         {st="系统功能通过对应的字母选择,大小写均可!";
  18.                 for(int i=0;i<st.length();i++)
  19.                 {cout<<st[i];delay(100);} cout<<endl;   }
  20. void Fnow(string st="")
  21.         {long now=time(NULL);string stw="日一二三四五六";
  22.          struct tm *t=localtime(&now);
  23.          st="现在是"+int2string(1900+t->tm_year)+"-"+
  24.                 int2string(t->tm_mon+1)+"-"+int2string(t->tm_mday)+
  25.                 "  "+int2string(t->tm_hour)+":"+
  26.                 int2string(t->tm_min)+":"+int2string(t->tm_sec)+
  27.                 "   星期"+stw.substr(t->tm_wday*2,2);
  28.                 for(int i=0;i<st.length();i++)
  29.                 {cout<<st[i];delay(100);} cout<<endl;   }
  30. void Fabout(string st)
  31.         {st="Copyright   gxx@69222.hbuas.cn   2017-1-15   ";
  32.                 for(int i=0;i<st.length();i++)
  33.                 {cout<<st[i];delay(100);} cout<<endl;
  34.         }
  35. char getMenuK(int n)//返回指定范围内的选择字符
  36.         {string st="0ABCDEFGHIJKLMNOPQRST";st=st.substr(0,n);
  37.          char ch;
  38.          do { ch=getch();if(ch=='0') return ch;
  39.                  if((int)st.find(ch)==-1) ch-='a'-'A';  }
  40.         while ((int)st.find(ch)==-1);
  41.          return ch;     }
  42. void showMenu(string menu[],int n)//显示主菜单
  43.         {system("cls");int i;
  44.            cout<<"                     欢迎使用【*****】系统\n";
  45.          for(i=1;i<n;i++) cout<<menu[i];
  46.          cout<<menu[0]; }
  47. void main()
  48.         { string  menu[6]={
  49.                 "退出(0)\n                       (Press:A/B/.../0)\n",
  50.                 "文件>   menu1(A)      menu2(B)      menu3(C)      menu4(D)\n",
  51.                 "编辑>   menu5(E)      menu6(F)      menu7(G)\n",
  52.                 "运行>   menu8(H)      menu9(I)      menu10(J)     menu11(K)     menu12(L)\n",
  53.                 "工具>   menu13(M)     现在时间(N)\n",
  54.                 "帮助>   使用说明(O)   关于(P)\n"};
  55.         void (*pfun[17])(string);//使用函数指针(数组)指向特定的函数
  56.         for(int i=1;i<17;i++) pfun[i]=&Fsorry;
  57.         pfun[14]=&Fnow; pfun[15]=&Fmem; pfun[16]=&Fabout;
  58.          while(1)
  59.            {char y;showMenu(menu,6);
  60.                   y=getMenuK(17);
  61.                   if(y=='0') {cout<<"\tThank You...Bye...";return;}
  62.               string st;
  63.               st="^_^抱谦,menu"+int2string(y-'A'+1)+"对应的模块还在创建中^_^";
  64.               pfun[y-'A'+1](st);delay(1000);
  65.                 }
  66.         }

回复 "菜单"

这儿你可以回复上面这条便签

captcha