【C++】学习笔记(三)----学生管理系统中输入数字的操作替换为为WS上下移动光标

学生管理系统主菜单的操作优化,该优化后的区别在于可以通过键盘上的w和s键来控制程序中的<<的移动。
其中_getch()函数功能为获取键盘输入,不同于cin的是cin只能输入一次而_getch()能够输入多次。若键盘没有输入则没有返回值,其头文件为conio.h。

#include<iostream>
#include <conio.h>
using namespace std;
void system_menu(int choice)
{
    cout << "* * * * * * * * * * * * * * * * *" << endl;
    cout << "*\t  学生管理系统  \t*" << endl;
    cout << "*\t\t\t\t*" << endl;
    cout << "*\t    主菜单\t\t*" << endl;
    cout << "*\t\t\t\t*" << endl;
    cout << "*\t 添加学生信息    ";
    if (choice == 1)cout << " <<\t*" << endl;
    else cout << "  \t*" << endl;
    cout << "*\t\t\t\t*" << endl;
    cout << "*\t 删除学生信息    ";
    if (choice == 2)cout << " <<\t*" << endl;
    else cout << "  \t*" << endl;
    cout << "*\t\t\t\t*" << endl;
    cout << "*\t 修改学生信息    ";
    if (choice == 3)cout << " <<\t*" << endl;
    else cout << "  \t*" << endl;
    cout << "*\t\t\t\t*" << endl;
    cout << "*\t 查找学生信息    ";
    if (choice == 4)cout << " <<\t*" << endl;
    else cout << "  \t*" << endl;
    cout << "*\t\t\t\t*" << endl;
    cout << "*\t 显示学生信息    ";
    if (choice == 5)cout << " <<\t*" << endl;
    else cout << "  \t*" << endl;
    cout << "*\t\t\t\t*" << endl;
    cout << "*\t 退出系统      ";
    if (choice == 6)cout << "   <<\t*" << endl;
    else cout << "  \t*" << endl;
    cout << "*\t\t\t\t*" << endl;
    cout << "*\t\t\t\t*" << endl;
    cout << "*\t系统版本:1.0\t\t*" << endl;
    cout << "*\t\t\t\t*" << endl;
    cout << "* * * * * * * * * * * * * * * * *" << endl;
}
int main()
{
    int choice = 1;
    while (1)
    {
        system("cls");//清屏
        system_menu(choice);
        int move = _getch();
        if (move != 13)
        {
            switch (move)//判断上下移动
            {
            case 'w':choice -= 1; if (choice < 1)choice = 6; break;
            case 's':choice += 1; if (choice > 6)choice = 1; break;
            case 'W':choice -= 1; if (choice < 1)choice = 6; break;
            case 'S':choice += 1; if (choice > 6)choice = 1; break;
            default:break;
            }
            continue;
        }
        //按了回车确定模式后进行以下内容
        if (choice == 1)
        {
            system("cls");//清屏
            cout << "暂无此功能" << endl;
            system("pause");
        }
        else if (choice == 2)
        {
            system("cls");//清屏
            cout << "暂无此功能" << endl;
            system("pause");
        }
        else if (choice == 3)
        {
            system("cls");//清屏
            cout << "暂无此功能" << endl;
            system("pause");
        }
        else if (choice == 4)
        {
            system("cls");//清屏
            cout << "暂无此功能" << endl;
            system("pause");
        }
        else if (choice == 5)
        {
            system("cls");//清屏
            cout << "暂无此功能" << endl;
            system("pause");
        }
        else if (choice == 6)
        {
            exit(0);
        }
    }
    return 0;
}

以下是程序运行效果图:
在这里插入图片描述

在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值