Visual Sdutio C++中运用数组完成学生信息管理系统

#include<iostream>

using namespace std;

#include<string>

//独立学生成绩结构体

struct student

{

long long m_Id = 0;//学号

string m_Name;//姓名

int m_chineseScore = 0;//语文分数

int m_mathScore = 0;//数学分数

int m_englishScore = 0;//英语分数

};

#define MAX 1000//最大录入1000个学生  宏常量

//全体学生成绩结构体

struct allStudent

{

struct student studentArray[MAX];

int num = 0;//学生人数

};

//菜单界面

void studentMenu()

{

cout << "****************************" << endl;

cout << "*** 1.显示所有学生信息   ***" << endl;

cout << "*** 2.增加学生信息       ***" << endl;

cout << "*** 3.删除学生信息       ***" << endl;

cout << "*** 4.按学生姓名排序     ***" << endl;

cout << "*** 5.按学生学号排序     ***" << endl;

cout << "*** 6.按学生总分排序     ***" << endl;

cout << "*** 7.按学生姓名查找信息 ***" << endl;

cout << "*** 8.按学生学号查找信息 ***" << endl;

cout << "*** 9.清空所有学生信息   ***" << endl;

cout << "*** 0.退出               ***" << endl;

cout << "****************************" << endl;

}

//1.显示所有学生信息

void showStudent(allStudent* abs)

{

if (abs->num == 0)

{

cout << "学生信息为空" << endl;

}

else

{

for (int i = 0; i < abs->num; i++)

{

cout << "学号:" << abs->studentArray[i].m_Id<<"\t";

cout << "姓名:" << abs->studentArray[i].m_Name << "\t";

cout << "语文成绩:" << abs->studentArray[i].m_chineseScore << "\t";

cout << "数学成绩:" << abs->studentArray[i].m_mathScore<< "\t";

cout << "英语成绩:" << abs->studentArray[i].m_englishScore << "\t";

cout << "总分:" << (abs->studentArray[i].m_chineseScore + abs->studentArray[i].m_mathScore + abs->studentArray[i].m_englishScore) << endl;

}

}

system("pause");//按任意键继续

system("cls");//清屏操作

}

//2.增加学生信息

void addStudent(allStudent* abs)

{

if (abs->num == MAX)

{

cout << "文件已满,不能再添加信息" << endl;

}

else

{

//输入学号

cout << "请输入学号(20170330000 ~ 20170330999):" << endl;

long long id;

while (true)

{

cin >> id;

if (id > 20170330000 && id < 20170330999)

{

abs->studentArray[abs->num].m_Id = id;

break;

}

else

cout << "输入错误,请重新输入" << endl;

}

//输入姓名

cout << "请输入姓名:" << endl;

string name;

cin >> name;

abs->studentArray[abs->num].m_Name = name;

//输入语文成绩

cout << "请输入语文成绩:" << endl;

int chinese;

while (true)

{

cin >> chinese;

if (chinese >= 0 && chinese <= 100)

{

abs->studentArray[abs->num].m_chineseScore = chinese;

break;

}

else

cout << "输入错误,请重新输入" << endl;

}

//输入数学成绩

cout << "请输入数学成绩:" << endl;

int math;

while (true)

{

cin >> math;

if (math >= 0 && math <= 100)

{

abs->studentArray[abs->num].m_mathScore = math;

break;

}

else

cout << "输入错误,请重新输入" << endl;

}//输入英语成绩

cout << "请输入英语成绩:" << endl;

int english;

while (true)

{

cin >> english;

if (english >= 0 && english <= 100)

{

abs->studentArray[abs->num].m_englishScore = english;

break;

}

else

cout << "输入错误,请重新输入" << endl;

}

}

abs->num++;

system("pause");

system("cls");

}

//3.删除学生信息(按名字)

void deleteStudent(allStudent* abs)

{

cout << "请输入需要删除学生的名字:" << endl;

string name;

cin >> name;

for (int i = 0; i < abs->num; i++)

{

if (abs->studentArray[i].m_Name == name )

{

cout << "找到需要删除的学生信息:" << endl;

cout << "学号:" << abs->studentArray[i].m_Id << "\t";

cout << "姓名:" << abs->studentArray[i].m_Name << "\t";

cout << "语文成绩:" << abs->studentArray[i].m_chineseScore << "\t";

cout << "数学成绩:" << abs->studentArray[i].m_mathScore << "\t";

cout << "英语成绩:" << abs->studentArray[i].m_englishScore << "\t";

cout << "总分:" << (abs->studentArray[i].m_chineseScore + abs->studentArray[i].m_mathScore + abs->studentArray[i].m_englishScore) << endl;

cout << "是否删除该学生信息:1.是  2.否" << endl;

int choose = 0;

while (true)

{

cin >> choose;

if (choose == 1)

{

for (int j = i; j < abs->num; j++)

{

abs->studentArray[j] = abs->studentArray[j + 1];

}

abs->num--;

cout << "删除成功" << endl;

system("pause");

system("cls");

return;

}

else if (choose == 2)

{

system("pause");

system("cls");

return;

}

else

cout << "输入错误,请重新输入" << endl;

}

}

}

cout << "未找到需要删除的学生" << endl;

system("pause");

system("cls");

}

//4.按学生姓名排序(升序)

void amendName(allStudent* abs)

{

if (abs->num == 0)

{

cout << "学生信息为空,无法排序" << endl;

}

else

{

for (int i = 0; i < abs->num - 1; i++)

{

for (int j = 0; j < abs->num - i - 1; j++)

{

if (abs->studentArray[j].m_Name > abs->studentArray[j + 1].m_Name)

{

struct student temp = abs->studentArray[j];

abs->studentArray[j] = abs->studentArray[j + 1];

abs->studentArray[j + 1] = temp;

}

}

}

}

cout << "完成排序(名字)" << endl;

system("pause");

system("cls");

}

//5.按学生学号排序(升序)

void amendId(allStudent* abs)

{

if (abs->num == 0)

{

cout << "学生信息为空,无法排序" << endl;

}

else

{

for (int i = 0; i < abs->num - 1; i++)

{

for (int j = 0; j < abs->num - i - 1; j++)

{

if (abs->studentArray[j].m_Id > abs->studentArray[j + 1].m_Id)

{

struct student temp = abs->studentArray[j];

abs->studentArray[j] = abs->studentArray[j + 1];

abs->studentArray[j + 1] = temp;

}

}

}

}

cout << "完成排序(学号)" << endl;

system("pause");

system("cls");

}

//6.按学生总分排序(升序)

void amendAllscore(allStudent* abs)

{

if (abs->num == 0)

{

cout << "学生信息为空,无法排序" << endl;

}

else

{

for (int i = 0; i < abs->num - 1; i++)

{

for (int j = 0; j < abs->num - i - 1; j++)

{

if ((abs->studentArray[j].m_chineseScore+ abs->studentArray[j].m_mathScore+ abs->studentArray[j].m_englishScore)> (abs->studentArray[j + 1].m_chineseScore+ abs->studentArray[j + 1].m_mathScore+ abs->studentArray[j + 1].m_englishScore))

{

struct student temp = abs->studentArray[j];

abs->studentArray[j] = abs->studentArray[j + 1];

abs->studentArray[j + 1] = temp;

}

}

}

}

cout << "完成排序(总分)" << endl;

system("pause");

system("cls");

}

//7.按学生姓名查找信息

void findName(allStudent* abs)

{

cout << "请输入需要查找学生的名字:" << endl;

string name;

cin >> name;

for (int i = 0; i < abs->num; i++)

{

if (abs->studentArray[i].m_Name == name)

{

cout << "找到该学生的信息:" << endl;

cout << "学号:" << abs->studentArray[i].m_Id << "\t";

cout << "姓名:" << abs->studentArray[i].m_Name << "\t";

cout << "语文成绩:" << abs->studentArray[i].m_chineseScore << "\t";

cout << "数学成绩:" << abs->studentArray[i].m_mathScore << "\t";

cout << "英语成绩:" << abs->studentArray[i].m_englishScore << "\t";

cout << "总分:" << (abs->studentArray[i].m_chineseScore + abs->studentArray[i].m_mathScore + abs->studentArray[i].m_englishScore) << endl;

system("pause");

system("cls");

return;

}

}

cout << "未找到该学生" << endl;

system("pause");

system("cls");

}

//8.按学生学号查找信息

void findId(allStudent* abs)

{

cout << "请输入需要查找学生的名字:" << endl;

long long id;

cin >> id;

for (int i = 0; i < abs->num; i++)

{

if (abs->studentArray[i].m_Id == id)

{

cout << "找到该学生的信息:" << endl;

cout << "学号:" << abs->studentArray[i].m_Id << "\t";

cout << "姓名:" << abs->studentArray[i].m_Name << "\t";

cout << "语文成绩:" << abs->studentArray[i].m_chineseScore << "\t";

cout << "数学成绩:" << abs->studentArray[i].m_mathScore << "\t";

cout << "英语成绩:" << abs->studentArray[i].m_englishScore << "\t";

cout << "总分:" << (abs->studentArray[i].m_chineseScore + abs->studentArray[i].m_mathScore + abs->studentArray[i].m_englishScore) << endl;

system("pause");

system("cls");

return;

}

}

cout << "未找到该学生" << endl;

system("pause");

system("cls");

}

//9.清空所有学生信息

void emptyStudent(allStudent* abs)

{

cout << "是否清空所有学生信息:1.是  2.否" << endl;

int choose = 0;

while (true)

{

cin >> choose;

if (choose == 1)

{

abs->num = 0;

cout << "已清空所有学生信息" << endl;

break;

}

else if (choose == 2)

{

break;

}

else

cout << "输入错误,请重新输入" << endl;

}

system("pause");

system("cls");

}

int main()

{

//创建全体学生成绩结构变量

allStudent abs;

//初始化学生数量

abs.num = 4;

abs.studentArray[0] = { 20170330422,"张三",75,86,96 };

abs.studentArray[1] = { 20170330442,"李四",34,67,78 };

abs.studentArray[2] = { 20170330411,"王五",89,91,99 };

abs.studentArray[3] = { 20170330456,"黄六",74,52,63 };

while (true)

{

//输出菜单界面

studentMenu();

int select = 0;

cout << "请输入你要使用的功能:" << endl;

cin >> select;

switch (select)

{

case 1://1.显示所有学生信息

showStudent(&abs);

break;

case 2://2.增加学生信息

addStudent(&abs);

break;

case 3://3.删除学生信息

deleteStudent(&abs);

break;

case 4://4.按学生姓名排序

amendName(&abs);

break;

case 5://5.按学生学号排序

amendId(&abs);

break;

case 6://6.按学生成绩排序

amendAllscore(&abs);

break;

case 7://7.按学生姓名查找信息

findName(&abs);

break;

case 8://8.按学生学号查找信息

findId(&abs);

break;

case 9://9.清空所有学生信息

emptyStudent(&abs);

break;

case 0://0.退出

cout << "欢迎下次使用" << endl;

system("pause");

return 0;

break;

default:

cout << "输入错误,请重新输入" << endl;

system("pause");

system("cls");

break;

}

}

system("pause");

return 0;

}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

boss_in_boss

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值