找回密码
 立即注册
  • QQ空间
  • 回复
  • 收藏

c++实现学生信息管理系统(内附开发文档)

admin 2019-10-10 07:11 82人围观 C++相关

    #include<iostream>#include<windows.h>#include<string>#include<iomanip>usingnamespacestd;
    #define MAX 1024
    //创建学生信息结构体structstudent{//姓名string m_Name=" ";//性别int m_Sex=0;
    //学号string m_Num=" ";
    //语文成绩int m_Chinese=0;
    //数学成绩int m_Math=0;
    //英语成绩int m_English=0;
    //总成绩int m_Score=0;};
    //创建管理系统结构体变量structManagement{//存放学生信息的数组 student stuArray[MAX];
    //学生的数量int m_Size=0;};

    //光标定位voidgotoxy(int&& x,int&& y){ COORD coord = { x, y }; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);}
    //添加学生信息voidaddStuMessage(Management* abs){ system("cls");if (abs->m_Size ==MAX) {cout << "学生信息已满,无法添加!!" << endl; }else {//姓名cout << "请输入学生姓名" << endl;string name;cin >> name;abs->stuArray[abs->m_Size].m_Name = name;
    //性别int sex;while (1) {cout << "请输入性别:" << endl;cout << "1 --- 男" << endl;cout << "2 --- 女" << endl;cin >> sex;if (sex == 1 || sex == 2) {abs->stuArray[abs->m_Size].m_Sex = sex;break; }else {cout << "输入有误请重新输入" << endl; } }
    //学号cout << "请输入学号" << endl;string num;cin >> num;abs->stuArray[abs->m_Size].m_Num = num;
    //语文int chinese;while (1) {cout << "请输入语文成绩" << endl;cin >> chinese;if ( chinese>=0&&chinese <= 100) {abs->stuArray[abs->m_Size].m_Chinese = chinese;break; }else {cout << "您的输入有误,请重新输入!" << endl; } }//数学int math;while (1) {cout << "请输入数学成绩" << endl;cin >> math;if (math >= 0 && math <= 100) {abs->stuArray[abs->m_Size].m_Math = math;break; }else {cout<< "您的输入有误,请重新输入!" << endl; } }//英语int english;while (1) {cout << "请输入英语成绩" << endl;cin >> english;if (english >= 0 && english <= 100) {abs->stuArray[abs->m_Size].m_English = english;break; }else {cout << "您的输入有误,请重新输入!" << endl; } }//总成绩int score; score = chinese + math + english;abs->stuArray[abs->m_Size].m_Score = score;//更新系统记录人数abs->m_Size++;
    cout << "添加成功!!!" << endl; } system("pause"); system("cls");}
    //显示学生信息voidshowStuMessage(Management*abs){ system("cls");if (abs->m_Size == 0) {cout << "当前记录为空" << endl; }else {for (int i = 0;i <abs->m_Size ;i++) {cout << "姓名:" << abs->stuArray[i].m_Name << "\t" << "性别:" << (abs->stuArray[i].m_Sex == 1 ? "男" : "女") << "\t" << "学号:" << abs->stuArray[i].m_Num << "\t" << "语文:" << abs->stuArray[i].m_Chinese << "\t" << "数学:" << abs->stuArray[i].m_Math << "\t" << "英语:" << abs->stuArray[i].m_English << "\t" << "总分:" << abs->stuArray[i].m_Score << endl; } } system("pause"); system("cls");}
    //加载动画voidshowLoadProgess(){cout << "Loading>>>>>>>>>>>";for (int i = 0;i < 25;i++) {cout << ">>>"; Sleep(100); }cout << endl;}
    //判断该学生是否存在intIsExit(Management*abs,string name){for (int i = 0;i < abs->m_Size;i++) {if (abs->stuArray[i].m_Name == name)//遍历数组,查找该学生是否存在,存在返回1,不存在返回-1 {return i; } }return-1;}
    //删除学生信息voiddeleteStuMessage(Management*abs){ system("cls");cout << "请输入要删除的学生的名字:" << endl;string name;cin >> name;
    int ret = IsExit(abs,name);
    if (ret != -1) // 找到了 {cout << "正在查询"; showLoadProgess();for (int i = ret;i <abs->m_Size;i++) {abs->stuArray[i] = abs->stuArray[i + 1];abs->m_Size--;cout << "删除成功!!!" << endl; } }else {cout << "查无此人" << endl; } system("pause"); system("cls");}
    //查找学生voidfindStu(Management*abs){ system("cls");cout << "请输入要查询的学生:" << endl;string name;cin >> name;
    int ret = IsExit(abs,name);
    if (ret != -1) {cout << "正在查找...." << endl; showLoadProgess();cout << "姓名:" << abs->stuArray[ret].m_Name << "\t" << "性别:" << (abs->stuArray[ret].m_Sex == 1 ? "男" : "女") << "\t" << "学号:" << abs->stuArray[ret].m_Num << "\t" << "语文:" << abs->stuArray[ret].m_Chinese << "\t" << "数学:" << abs->stuArray[ret].m_Math << "\t" << "英语:" << abs->stuArray[ret].m_English << "\t" << "总分:" << abs->stuArray[ret].m_Score << endl; }else {cout << "查无此人" << endl; } system("pause"); system("cls");}
    //修改学生信息voidrWriteStuMessage(Management *abs){ system("cls");cout << "请输入要修改信息的学生的姓名:" << endl;string name;cin >> name;
    int ret = IsExit(abs,name);
    if (ret != -1) {//姓名cout << "请输入学生姓名:" << endl;string name;cin >> name;abs->stuArray[ret].m_Name = name;
    //性别int sex = 0;while (1) {cout << "请输入性别:" << endl;cout << "1 --- 男" << endl;cout << "2 --- 女" << endl;cin >> sex;if (sex == 1 || sex == 2) {abs->stuArray[ret].m_Sex = sex;break; }else {cout << "您的输入有误,请重新输入!" << endl; } }
    //学号cout << "请输入学号:" << endl;string num;cin >> num;abs->stuArray[ret].m_Num = num;//语文int chinese;while (1) {cout << "请输入语文成绩:" << endl;cin >> chinese;if (chinese >= 0 && chinese <= 100) {abs->stuArray[ret].m_Chinese = chinese;break; }else {cout << "您的输入有误,请重新输入!" << endl; } }//数学int math;while (1) {cout << "请输入数学成绩:" << endl;cin >> math;if (math >= 0 && math <= 100) {abs->stuArray[ret].m_Math = math;break; }else {cout << "您的输入有误,请重新输入!" << endl; } }//英语int english;while (1) {cout << "请输入英语成绩:" << endl;cin >> english;if (english >= 0 && english<= 100) {abs->stuArray[ret].m_English = english;break; }else {cout << "您的输入有误,请重新输入!" << endl; } }//总分数int score; score = chinese + math + english;abs->stuArray[ret].m_Score = score; showLoadProgess();cout << "修改成功!!!" << endl; }else {cout << "查无此人" << endl; } system("pause"); system("cls");}
    //清空学生信息voidcleanStuMessage(Management*abs){ system("cls");abs->m_Size = 0;cout << "正在删除..." << endl; showLoadProgess();cout << "删除成功!!!" << endl; system("pause"); system("cls");}
    //冒泡排序voidbubbleSort(Management*abs){for (int i = 0;i < abs->m_Size-1;i++) {for (int j = 0;j < abs->m_Size - 1 - i;j++) {if (abs->stuArray[j].m_Score < abs->stuArray[j + 1].m_Score) { student temp = abs->stuArray[j];abs->stuArray[j] = abs->stuArray[j + 1];abs->stuArray[j + 1] = temp; } } }}
    //打印排序后的信息voidprintBubbleSort(Management*abs){ system("cls"); bubbleSort(abs);for (int i = 0;i < abs->m_Size;i++) {cout<<"第"<<i+1<<"名"<<"\t" << "姓名:" << abs->stuArray[i].m_Name << "\t" << "性别:" << (abs->stuArray[i].m_Sex == 1 ? "男" : "女") << "\t" << "学号:" << abs->stuArray[i].m_Num << "\t" << "语文:" << abs->stuArray[i].m_Chinese << "\t" << "数学:" << abs->stuArray[i].m_Math << "\t" << "英语:" << abs->stuArray[i].m_English << "\t" << "总分:" << abs->stuArray[i].m_Score << endl; } system("pause"); system("cls");}
    //界面实现voidshowMenu(){for (int i = 0;i < 7;i++) {cout << endl; } gotoxy(25,6);cout << "********** 欢迎使用 *********" << endl; gotoxy(25, 8);cout << "******* 1、添加学生信息 *******" << endl; gotoxy(25, 10);cout << "******* 2、显示学生信息 *******" << endl; gotoxy(25, 12);cout << "******* 3、删除学生信息 *******" << endl; gotoxy(25, 14);cout << "******* 4、查找学生信息 *******" << endl; gotoxy(25, 16);cout << "******* 5、修改学生信息 *******" << endl; gotoxy(25, 18);cout << "******* 6、清空学生信息 *******" << endl; gotoxy(25, 20);cout << "******* 7、分析学生成绩 *******" << endl; gotoxy(25, 22);cout << "******* 0、退出管理系统 *******" << endl; gotoxy(25,24);cout << "*******************************" << endl;
    }


    intmain(){//创建管理系统变量 Management abs;
    //初始化系统中学生信息的个数abs.m_Size = 0;
    //主菜单显示int select = 0;while (1) { showMenu();cout << "请输入您的操作......";cin >> select;switch (select) {case1: //添加学生信息 addStuMessage(&abs);break;case2: //显示学生信息//showLoadProgess(); showStuMessage(&abs);break;case3: //删除学生信息 deleteStuMessage(&abs);break;case4: //查找学生信息 findStu(&abs);break;case5: //修改学生信息 rWriteStuMessage(&abs);break;case6: //清空学生信息 cleanStuMessage(&abs);break;case7: //排序 printBubbleSort(&abs);break;case0: //退出程序cout << "欢迎下次使用" << endl; system("pause");exit(0);break; } } system("pause");return0;}
    ----------------------------------------------------------------------------------------------------------------------
    我们尊重原创,也注重分享,文章来源于微信公众号:SUPER CODING,建议关注公众号查看原文。如若侵权请联系qter@qter.org。
    ----------------------------------------------------------------------------------------------------------------------

    鲜花

    握手

    雷人

    路过

    鸡蛋

    yafeilinux和他的朋友们微信公众号二维码

    微信公众号

    专注于Qt嵌入式Linux开发等。扫一扫立即关注。

    Qt开源社区官方QQ群二维码

    QQ交流群

    欢迎加入QQ群大家庭,一起讨论学习!

    我有话说......