📄 menu.cpp
字号:
/**********************************************************************************
* *
* Henry Banking System ATM Module *
* Copyright (c) 2004 by Henry. All rights reserved. *
* *
* Permission to use, copy, modify, and distribute this software for any purpose *
* is hereby granted without fee, provided that this copyright and permissions *
* notice appear in all copies and derivatives, and that no charge may be made *
* for the software and its documentation except to cover cost of distribution. *
* *
* This software is provided "as is" without express or implied warranty. *
* *
**********************************************************************************/
/*
* Description:
*
* Generate menu in a CUI way.
*
* Notes:
*
* This code has been written to conform to standard C++ and STL. It has been
* compiled successfully using Visual C++ 7.0.
*/
#include<iostream>
#include <string>
#include <vector>
#include "cui.h"
using namespace std;
namespace cui
{
Menu::Menu()
{
onSelect = 0;
}
void Menu::showWelcome()
{
cout << endl << endl;
cout << "**********************************************************" << endl;
cout << "* *" << endl;
cout << "* Welcome to use Automatic Teller Machine of Henry Bank! *" << endl;
cout << "* *" << endl;
cout << "* 欢迎使用新利银行ATM机! *" << endl;
cout << "* *" << endl;
cout << "**********************************************************" << endl << endl;
}
void Menu::add(string text1, string text2)
{
items[0].push_back(text1);
items[1].push_back(text2);
}
void Menu::clear()
{
items[0].clear();
items[1].clear();
}
size_t Menu::show()
{
size_t choice = -1;
vector<string>::size_type size = items[language].size();
cout << items[language][0] << endl << endl;
for(size_t i = 1; i <= size - 1; i++)
{
cout << " " << i << ". " << items[language][i] << endl;
}
cout << endl;
while(choice < 1 || choice > size)
{
cin.clear();
if(language == 0)
cout << " Enter your choice (between 1 to " << size - 1 << "): ";
else
cout << "请选择 (1到" << size - 1 << "): ";
cin >> choice;
}
string str;
getline(cin, str);
cout << endl;
if(onSelect)
onSelect(choice);
return choice;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -