以防老师再次叫我们做这些,先写好一个在这里:
/*
* @Author:小陈
* @Date: 2019-03-17 11:04:17
* @Last by:小陈
* @Last time: 2019-03-17 11:58:40
*/
#include "pch.h"
#include <iostream>
#include <string>
#include <windows.h>
using namespace std;
const int Subjects = 3; //科目数目
const int Num = 4; //人数
string score[Num][2 + Subjects]; //score[人数][学号,名字,第几门成绩]
//成绩
void add()
{
int i = 0;
while (score[Num - 1][1 + Subjects] == "")
{
cout << "请输入第" << i + 1 << "个同学\n学号、姓名、数学分析、线性代数、大学物理成绩" << endl;
for (int j = 0; j < 2 + Subjects; j++)
{
cin >> score[i][j];
}
i++;
}
cout << "输入成绩成功...";
system("cls");
}
//所有成绩
void showAll(int num = Num)
{
cout << "学号\t姓名\t数学\t线性\t物理" << endl;
if (score[Num - 1][1 + Subjects] == "")
{
cout << "成绩单为空,是没有录入的原因...";
}
else if (num != Num)
{
for (int j = 0; j < Subjects + 2; j++)
{
cout << score[num][j] << '\t';
}
cout << endl;
}
else
{
for (int i = 0; i < num; i++)
{
for (int j = 0; j < Subjects + 2; j++)
{
cout << score[i][j] << '\t';
}
cout << endl;
}
}
}
//查找
void search()
{
string x;
cout << "请输入你要查询的学号:";
while (cin >> x)
{
for (int i = 0; i < Num; i++)
{
if (score[i][0] == x)
{
showAll(i);
return;
}
if (i == Num-1 && score[i][0] != x)
{
system("cls");
cout << "系统之中没这个人...\n请再次输入你要查询的学号:";
}
}
}
}
//排序&筛选
void showOneAll(string num)
{
//转整形
int numB = atoi(num.c_str());
string temp;
int scoreA, scoreB;
for (int j = 0; j < Num; j++)
{
scoreA = atoi(score[j][numB].c_str());
scoreB = atoi(score[j + 1][numB].c_str());
if (scoreA > scoreB)
{
temp = score[j][numB];
score[j + 1][numB] = score[j][numB];
score[j][numB] = temp;
}
}
}
//一门成绩
void showOne()
{
string x;
cout << "请输入你想要看的科目(数学、线性、物理)";
while (cin >> x)
{
system("cls");
if (x == "数学")
{
showOneAll("2");
break;
}
else if (x == "线性")
{
showOneAll("3");
break;
}
else if (x == "物理")
{
showOneAll("4");
break;
}
else
{
cout << "请按照正确格式来做...\n请输入你想要看的科目(数学、线性、物理)";
}
}
showAll();
}
//删库跑路
void clear()
{
string x;
cout << "你确定要跑路?(Y/N)";
while (cin >> x)
{
system("cls");
if (x == "Y")
{
for (int i = 0; i < Num; i++)
{
for (int j = 0; j < Subjects + 2; j++)
{
score[i][j] = "";
}
}
cout << "正在删库...";
Sleep(1000);
system("cls");
cout << "删除成功,赶紧跑路吧...";
break;
}
else if (x == "N")
{
break;
}
else
{
cout << "输入不对请继续输入..";
}
}
}
void showMenu()
{
cout << " \n";
cout << "===============================\n";
cout << " 学生成绩管理系统\n\n";
cout << " 1.显示所有学生成绩\n";
cout << " 2.添加信息\n";
cout << " 3.查询信息\n";
cout << " 4.单科成绩排序\n";
cout << " 5.删库跑路\n";
cout << " 0.退出系统\n";
cout << "===============================\n";
cout << " \n";
}
int main()
{
int h;
while (1)
{
showMenu();
cout << "请输入操作对应的序号 : ";
cin >> h;
cout << endl;
system("cls");
switch (h)
{
case 1:
showAll();
break;
case 2:
add();
break;
case 3:
search();
break;
case 4:
showOne();
break;
case 5:
clear();
break;
case 0:
cout << "\n退出成功!";
return 0;
default:
cout << "\n请注意看上面的信息喔!!!你的输入有错..." << endl;
}
//让用户能够看到上面提示的信息
Sleep(1000);
}
}