手机版

学生管理系统设计源码C++版

发布时间:2024-11-10   来源:未知    
字号:

//c语言程序设计
//学生管理系统

#include <iostream>
#include <iomanip>
using namespace std;

struct tagSTUDENT
{
int Sno;
char Sname[10];
int Sage;
//tagSTUDENT *pPrev;
tagSTUDENT *pNext;
};

int ShowMenu();
void InputInfo();
void PrintInfo();
void DeleteInfo();
void FindName();
void FindNumber();

tagSTUDENT *pHead = NULL;
//tagSTUDENT *pEnd = NULL;

int ShowMenu()
{
int iChoose = -1;
while (1)
{
system("cls");
iChoose = -1;
cout << "******学生管理系统******" << endl;
cout << " 1. 录入学生信息" << endl;
cout << " 2. 打印所有学生" << endl;
cout << " 3. 删除一个学生" << endl;
cout << " 4. 按照姓名查询" << endl;
cout << " 5. 按照学号查询" << endl;
cout << " 0. 退出" << endl;
cout << "************************" << endl;
cout << "请选择:" ;
cin >> iChoose;
cin.sync();
cin.clear();
if (iChoose >= 0 && iChoose <= 5) break ;
}

return iChoose;
}

void InputInfo()
{
tagSTUDENT *pNew = new tagSTUDENT;

while (1)
{
cout << "请输入学号:";
cin >> pNew->Sno;
if (pNew->Sno > 0) break;
cin.sync();
cin.clear();
}
while (1)
{
cout << "请输入姓名:";
cin >> pNew->Sname;
if (pNew->Sname) break;
cin.sync();
cin.clear();
}
while (1)
{
cout << "请输入年龄:";
cin >> pNew->Sage;
if (pNew->Sage > 0) break;
cin.sync();
cin.clear();
}
if (pHead == NULL)
{
pNew->pNext = NULL;
pHead = pNew;
//pEnd = pNew;
return;
}

tagSTUDENT *p1 = NULL;
tagSTUDENT *p2 = pHead;

while (p2 != NULL && pNew->Sno >= p2->Sno)
{
if (p2->Sno == pNew->Sno)
{
cout <<"该学号已经存在!";
return;
}
else
{
p1 = p2;
p2 = p2->pNext;
}

}

if (p1 == NULL)
{
pNew->pNext = pHead;
pHead = pNew;
}
else if (p2 != NULL)
{
p1->pNext = pNew;
pNew->pNext = p2;
}
else
{
p1->pNext = pNew;
pNew->pNext = NULL;
}
}

void PrintInfo()
{
cout << setw(6) << "学号"
<< setw(8) << "姓名"
<< setw(6) << "年龄" << endl;

tagSTUDENT *p = pHead;
while (p != NULL)
{
cout << setw(6) << p->Sno
<< setw(8) << p->Sname
<< setw(6) << p->Sage << endl;
p = p->pNext;
}
}
void DeleteInfo()
{
tagSTUDENT *pNew = new tagSTUDENT;
cout << "请输入要删除学生的学号:";
cin >> pNew->Sno;

if (pHead == NULL)
{
cout << "当前系统没有数据!"<<endl;
return;
}

tagSTUDENT *p1 = NULL;
tagSTUDENT *p2 = pHead;
while (p2 != NULL && pNew->Sno != p2->Sno)
{
p1 = p2;
p2 = p2->pNext;
}
if (p2 ==NULL)
{
cout << "该学生信息不存在!" << endl;
return;
}
else if(p1 == NULL)
{
p2 = p2->pNext;
pHead = p2;
cout << "删除成功!" <<endl;
}
else
{
p2 = p2->pNext;
p
1->pNext = p2;
cout << "删除成功!" <<endl;
}
}

void FindName()
{
tagSTUDENT *pNew = new tagSTUDENT;
cout <<

"请输入要查找学生的姓名:";
cin >> pNew->Sname;

if (pHead == NULL)
{
cout << "当前系统没有数据!"<<endl;
return;
}

tagSTUDENT *p1 = NULL;
tagSTUDENT *p2 = pHead;
while (p2 != NULL && strcmp(pNew->Sname, p2->Sname) != 0)
{
p1 = p2;
p2 = p2->pNext;
}
if (p2 ==NULL)
{
cout << "该学生信息不存在!" << endl;
return;
}
else if(p1 == NULL)
{
cout << setw(6) << "学号"
<< setw(8) << "姓名"
<< setw(6) << "年龄" << endl;
cout << setw(6) << pHead->Sno
<< setw(8) << pHead->Sname
<< setw(6) << pHead->Sage << endl;

}
else
{
cout << setw(6) << "学号"
<< setw(8) << "姓名"
<< setw(6) << "年龄" << endl;
cout << setw(6) << p2->Sno
<< setw(8) << p2->Sname
<< setw(6) << p2->Sage << endl;
}
}

void FindNumber()
{
tagSTUDENT *pNew = new tagSTUDENT;
cout << "请输入要查找学生的学号:";
cin >> pNew->Sno;

if (pHead == NULL)
{
cout << "当前系统没有数据!"<<endl;
return;
}

tagSTUDENT *p1 = NULL;
tagSTUDENT *p2 = pHead;
while (p2 != NULL && pNew->Sno != p2->Sno)
{
p1 = p2;
p2 = p2->pNext;
}
if (p2 ==NULL)
{
cout << "该学生信息不存在!" << endl;
return;
}
else if(p1 == NULL)
{
cout << setw(6) << "学号"
<< setw(8) << "姓名"
<< setw(6) << "年龄" << endl;
cout << setw(6) << pHead->Sno
<< setw(8) << pHead->Sname
<< setw(6) << pHead->Sage << endl;

}
else
{
cout << setw(6) << "学号"
<< setw(8) << "姓名"
<< setw(6) << "年龄" << endl;
cout << setw(6) << p2->Sno
<< setw(8) << p2->Sname
<< setw(6) << p2->Sage << endl;
}
}


void main()
{
while (1)
{
int iChoose = ShowMenu();
switch (iChoose)
{
case 0:
return;
break;
case 1:
InputInfo();
system("pause");
break;
case 2:
PrintInfo();
system("pause");
break;
case 3:
DeleteInfo();
system("pause&qu
ot;);
break;
case 4:
FindName();
system("pause");
break;
case 5:
FindNumber();
system("pause");
break;

}
}

}

学生管理系统设计源码C++版.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
    ×
    二维码
    × 游客快捷下载通道(下载后可以自由复制和排版)
    VIP包月下载
    特价:29 元/月 原价:99元
    低至 0.3 元/份 每月下载150
    全站内容免费自由复制
    VIP包月下载
    特价:29 元/月 原价:99元
    低至 0.3 元/份 每月下载150
    全站内容免费自由复制
    注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
    × 常见问题(客服时间:周一到周五 9:30-18:00)