pr04007.cpp

来自「c++编程宝典源码及Quincy99编译器 是《标准C++编程宝典》电子工业出」· C++ 代码 · 共 71 行

CPP
71
字号
////////////////////////////////////////
// File Name: pr04007.cpp
////////////////////////////////////////
#include <iostream>

// Prototypes
void DisplayMenu();
int GetSelection();

////////////////////////////////////////
// The main() function.
////////////////////////////////////////
int main()
{
    int selection = 0;
    while (selection != 3)
    {
        // Display the menu.
        DisplayMenu();

        // Get menu selection.
        selection = GetSelection();

        // Select matching process
        switch (selection)
        {
            case 1:
                std::cout << "Processing Receivables" 
                          << std::endl;
                break;
            case 2:
                std::cout << "Processing Payables" 
                          << std::endl;
                break;
            case 3:
                std::cout << "Quitting" << std::endl;
                break;
            default:
                std::cout << "\aInvalid selection" 
                          << std::endl;
                break;
        }
    }

    return 0;
}

////////////////////////////////////////
// Display a menu.
////////////////////////////////////////
void DisplayMenu()
{
    std::cout << "--- Menu ---" << endl;
    std::cout << "1=Receivables" << endl;
    std::cout << "2=Payables" << endl;
    std::cout << "3=Quit" << endl;
}

////////////////////////////////////////
// Read a menu selection from the
// keyboard.
////////////////////////////////////////
int GetSelection()
{
    int selection;
    std::cout << "Enter Selection: ";
    std::cin >> selection;

    return selection;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?