On 21 Jul 2004 06:10:20 -0700,
di*****@br.inter.net (Roberto Dias)
wrote:
Could anyone give me some tips about how to start a menu-based console
application using C++ function oriented programming techniques? I'm a
FORTRAN-based electrical engineer and a newbie on C++ style, for this,
I'm not ready for OOP techniques yet.
Thanks a lot,
Roberto Dias
Recife/PE - Brazil
// Very simple menu based console application
#include <iostream>
#include <string>
#include <cstdlib>
//-------------------------------------
char display_menu();
void sneer_at_007();
void release_bats();
void take_over_world();
void get_the_girl();
//-------------------------------------
int main() {
bool running = true;
do {
switch (display_menu()) {
case '1': case 's': case 'S':
sneer_at_007();
break;
case '2': case 'r': case 'R':
release_bats();
break;
case '3': case 't': case 'T':
take_over_world();
break;
case '4': case 'g': case 'G':
get_the_girl();
break;
case '5': case 'q': case 'Q':
running = false;
break;
default:
std::cout << "I do not recognise that selection.\n";
} // end switch
} while (running);
return EXIT_SUCCESS;
} // end main()
//-------------------------------------
char display_menu() {
using std::cout;
const char NULL_SELECTION = '\0';
cout << '\n';
cout << "Main Menu\n";
cout << "=========\n";
cout << "1 Sneer at 007\n";
cout << "2 Release the Bats\n";
cout << "3 Take over the world\n";
cout << "4 Get the girl\n";
cout << "5 Quit\n";
cout << "\n";
cout << "Enter selection: ";
std::string selection;
if (!getline(std::cin, selection)) { exit(EXIT_FAILURE); }
if (selection.length() == 0) {
return NULL_SELECTION;
}
else {
return selection[0];
} // end if
} // end display_menu()
//-------------------------------------
void sneer_at_007() {
std::cout << "That tie clashes with those socks Mr Bond.\n";
return;
} // end sneer_at_007()
//-------------------------------------
void release_bats() {
std::cout << "The bats have been released sir.\n";
return;
} // end release_bats()
//-------------------------------------
void take_over_world() {
std::cout << "The world is now yours, your Imperial Majesty.\n";
return;
} // end take_over_world()
//-------------------------------------
void get_the_girl() {
std::cout << "What's a girl like you doing in a nice place like
this?\n";
return;
} // end get_the_girl()
//-------------------------------------
--
The ultimate truth is that there is no Ultimate Truth