⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pr06012.cpp

📁 c++编程宝典源码及Quincy99编译器 是《标准C++编程宝典》电子工业出版社的光盘
💻 CPP
字号:
////////////////////////////////////////
// File Name: pr06012.cpp
////////////////////////////////////////
#include <iostream>

// A menu structure.
struct Menu
{
    char* name;
    void (*fn)();
};

// Menu selection function prototypes.
void FileFunc();
void EditFunc();
void ViewFunc();
void ExitFunc();

// The menu.
Menu menu[] = {
    { "File", FileFunc },
    { "Edit", EditFunc },
    { "View", ViewFunc },
    { "Exit", ExitFunc }
};

////////////////////////////////////////
// The main() function.
////////////////////////////////////////
main()
{
    unsigned sel = 0;

    while (sel != 4)
    {
        // Display menu choices.
        for (int i = 0; i < 4; i++)
            std::cout << i+1 << ": " << menu[i].name 
                      << std::endl;
        std::cout << "Select: ";

        // Get the menu selection from the user.
        std::cin >> sel;

        // Call the requested function through
        // a function pointer.
        if (sel < 5 && sel > 0)
            (*menu[sel-1].fn)();
    }
}

void FileFunc()
{
    std::cout << "File Function" << std::endl;
}

void EditFunc()
{
    std::cout << "Edit Function" << std::endl;
}

void ViewFunc()
{
    std::cout << "View Function" << std::endl;
}

void ExitFunc()
{
    std::cout << "Exit Function" << std::endl;
}

⌨️ 快捷键说明

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