成绩管理系统

本来是学校的作业,放在这里应该不会给同学看见吧,233333

// 学籍管理系统.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>
using namespace std;
struct CHAINLIST
{
CHAINLIST* m_NextNode;
CHAINLIST* m_HeadNode;
char m_Name[32] = {};
int m_Score;
int m_Id;
};
CHAINLIST* add(CHAINLIST* node, int id, char* name, int score) {
CHAINLIST* NextNode = new CHAINLIST;
node->m_NextNode = NextNode;
NextNode->m_HeadNode = node->m_HeadNode;
NextNode->m_NextNode = 0;
NextNode->m_Id = id;
NextNode->m_Score = score;
strcat_s(NextNode->m_Name, 32, name);
return NextNode;
}
void update(CHAINLIST* stu) {
int id, score;
char name[32];
cout << "学号:"; cin >> id; cout << "姓名:"; cin >> name; cout << "成绩:"; cin >> score;
stu->m_Id = id;
strcpy_s(stu->m_Name, 32, name);
stu->m_Score = score;
}
void delete_(int id, CHAINLIST* head) {
CHAINLIST* tmp = head->m_HeadNode, *up = head->m_HeadNode;
while ((tmp = tmp->m_NextNode) != 0) {
if (tmp->m_Id == id) {
if (tmp->m_NextNode != 0) {
up->m_NextNode = tmp->m_NextNode;
}
else {
up->m_NextNode = 0;
}
delete tmp;
return;
}
up = tmp;
}
cout << "没有此学生n"; /*stu->m_Id = tmp->m_Id;
stu->m_NextNode = tmp->m_NextNode;
stu->m_Score = tmp->m_Score;
strcat_s(stu->m_Name, 32, tmp->m_Name);
delete tmp;*/
}
CHAINLIST* select(int id, CHAINLIST* head) {
CHAINLIST* tmp = head;
while ((tmp = tmp->m_NextNode) != 0) {
if (tmp->m_Id == id) {
return tmp;
}
}
return 0;
}
CHAINLIST* getnext(CHAINLIST* node) {
return node->m_NextNode;
}
void prtExcellent(CHAINLIST* head) {
int n = 0;
cout << "-------优秀-------n"; CHAINLIST* tmp = head; while ((tmp = tmp->m_NextNode) != 0) {
if (tmp->m_Score >= 80) {
n++;
cout << tmp->m_Id << "tt" << tmp->m_Name << "tt" << tmp->m_Score << endl;
}
}
cout << "优秀人数为:" << n << "人n";
}
void prtQualified(CHAINLIST* head) {
int n = 0;
cout << "-------合格-------n"; CHAINLIST* tmp = head; while ((tmp = tmp->m_NextNode) != 0) {
if (tmp->m_Score >= 60 && tmp->m_Score < 80) {
n++;
cout << tmp->m_Id << "tt" << tmp->m_Name << "tt" << tmp->m_Score << endl;
}
}
cout << "合格人数为:" << n << "人n";
}
void prtUnQualified(CHAINLIST* head) {
int n = 0;
cout << "-------不合格-------n"; CHAINLIST* tmp = head; while ((tmp = tmp->m_NextNode) != 0) {
if (tmp->m_Score < 60) {
n++;
cout << tmp->m_Id << "tt" << tmp->m_Name << "tt" << tmp->m_Score << endl;
}
}
cout << "不合格人数为:" << n << "人n"; } int main() { CHAINLIST* tmp = new CHAINLIST; int n = 1; tmp->m_HeadNode = tmp;
tmp = add(tmp, 1, "张三", 100);
tmp = add(tmp, 2, "李四", 60);
tmp = add(tmp, 3, "王五", 50);
while (n > 0)
{
system("cls");
cout << "tttt欢迎进入学生成绩管理系统!nttt1 : 查询nttt2 : 统计nttt3 : 添加nttt4 : 删除nttt5 : 修改nttt6 : 打印nttt0 : 退出系统n"; cin >> n;
switch (n)
{
case 1: {
char isYN = 'Y';
while (isYN == 'Y') {
cout << "请输入学号:"; int id; cin >> id;
CHAINLIST* stu = select(id, tmp->m_HeadNode);
if (!stu) {
cout << "学生不存在n";
}
else {
cout << "学号:" << stu->m_Id << "n姓名:" << stu->m_Name << "n成绩:" << stu->m_Score << endl << endl;
}
cout << "是否继续 Y/Nn"; cin >> isYN;
isYN ^= 32;
}
break;
}
case 2: {
prtExcellent(tmp->m_HeadNode);
prtQualified(tmp->m_HeadNode);
prtUnQualified(tmp->m_HeadNode);
char isYN;
cout << "是否继续 Y/Nn"; cin >> isYN;
isYN ^= 32;
if (isYN == 'N')n = 0;
break;
}
case 3: {//添加
char isYN = 'y';
while (isYN != 'N') {
int id, score;
char name[32];
cout << "学号:"; cin >> id; cout << "姓名:"; cin >> name; cout << "成绩:"; cin >> score;
tmp = add(tmp, id, name, score);
cout << "是否继续 Y/Nn"; cin >> isYN;
isYN ^= 32;
}
break;
}
case 4: {//删除
char isYN = 'y';
while (isYN != 'N') {
cout << "请输入删除学生idn"; int id = 0; cin >> id;
tmp = tmp->m_HeadNode;
delete_(id, tmp->m_HeadNode);
cout << "是否继续 Y/Nn"; cin >> isYN;
isYN ^= 32;
}
break;
}
case 5: {//修改
char isYN = 'Y';
while (isYN != 'N') {
cout << "请输入修改学生idn"; int id = 0; cin >> id;
CHAINLIST* stu = select(id, tmp->m_HeadNode);
tmp->m_HeadNode;
if (!stu) {
cout << "学生不存在n";
}
else {
update(stu);
}
cout << "是否继续 Y/Nn"; cin >> isYN;
isYN ^= 32;
}
break;
}
case 6: {
tmp = tmp->m_HeadNode;
while (true)
{
tmp = getnext(tmp);
cout << "学号:" << tmp->m_Id << "n姓名:" << tmp->m_Name << "n成绩:" << tmp->m_Score << endl << endl; if (tmp->m_NextNode == 0)break;
}
cout << "是否继续使用系统 Y/Nn"; char c; cin >> c; c ^= 32;
if (c != 'Y')n = 0;
break;
}
default:
break;
}
}
cout << "感谢您的使用n";
return 0;
}
点赞

发表评论

电子邮件地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据