📄 11.cpp
字号:
/*========================================================
* 文件名:student.cpp
* 描 述:学生成绩管理系统
* 初始密码:administrator
* 主菜单:╔══════ 学生成绩管理系统 ══════╗
║ ║
║ >> 输入学生信息 << 学号排序输出 ║
║ ║
║ 查询学生信息 总分排序输出 ║
║ ║
║ 修改学生信息 90分以上的 ║
║ ║
║ 删除学生信息 平均分以下的 ║
║ ║
║ 保存学生信息 不及格的学生 ║
║ ║
║ 修改登录密码 退出管理系统 ║
║ ║
╚═════════════════════╝
使用说明:小键盘区:[1]-左 [2]-下 [3]-右 [5]-上
回车键 - 确认 空格键 - 右 [ESC]-返回
==========================================================*/
#include <iostream.h>
#include <iomanip.h> //设置字宽
#include <fstream.h> //文件存取
#include <stdlib.h> //调用DOS命令
#include <conio.h> //按键检测
#include <string.h> //字符串处理
typedef char string[80]; //定义字符串类型
string password;
//----------- 定义学生类 ----------------
class Student
{
public:
Student() {next=0;}
void Set(); //输入学生信息
void Set(ifstream &f); //导入学生信息
void Set(Student *p); //拷贝学生信息
void Print(); //输出学生信息
void Print(ofstream &f);//保存学生信息
friend class School;
private:
string num; //学号
string name; //姓名
string sex; //性别
float sx,yy,wl,cpp,ks; //课程
float sum,ave; //总分、平均分
int rank; //名次
Student *next; //链表指针
};
//输入学生信息
void Student::Set()
{
cout<<"\t\t 请输入学号:"; cin>>num;
cout<<"\t\t 请输入姓名:"; cin>>name;
cout<<"\t\t 请输入性别:"; cin>>sex;
cout<<"\t\t 请输入数学成绩:"; cin>>sx;
cout<<"\t\t 请输入英语成绩:"; cin>>yy;
cout<<"\t\t 请输入物理成绩:"; cin>>wl;
cout<<"\t\t 请输入C++成绩:"; cin>>cpp;
cout<<"\t\t 请输入课设成绩:"; cin>>ks;
sum=sx+yy+wl+cpp+ks;
ave=sum/5;
}
//导入学生信息
void Student::Set(ifstream &f)
{
f>>num>>name>>sex;
f>>sx>>yy>>wl>>cpp>>ks;
f>>sum>>ave>>rank;
}
//拷贝学生信息
void Student::Set(Student *p)
{
strcpy(num,p->num);
strcpy(name,p->name);
strcpy(sex,p->sex);
sx=p->sx;
yy=p->yy;
wl=p->wl;
cpp=p->cpp;
ks=p->ks;
sum=p->sum;
ave=p->ave;
rank=p->rank;
}
//输出学生信息
void Student::Print()
{
cout<<"║"<<setw(15)<<num<<setw(10)<<name<<setw(5)<<sex<<"┆";
cout<<setw(5)<<sx<<setw(5)<<yy<<setw(5)<<wl<<setw(5)<<cpp<<setw(5)<<ks<<"┆";
cout<<setw(6)<<sum<<setw(5)<<ave<<setw(4)<<rank<<"║"<<endl;
}
//保存学生信息
void Student::Print(ofstream &f)
{
f<<endl<<setw(15)<<num<<setw(10)<<name<<setw(5)<<sex;
f<<setw(5)<<sx<<setw(5)<<yy<<setw(5)<<wl<<setw(5)<<cpp<<setw(5)<<ks;
f<<setw(6)<<sum<<setw(5)<<ave<<setw(4)<<rank;
}
//-------------- 定义学校类 -----------------
class School
{
public:
School() {ps=0;}
~School();
void Input(); //批量输入、增加学生信息
void Output(int x); //输出全体学生信息
void Load(); //载入学生信息
void Save(); //保存学生信息
Student * School::Search(); //搜索学生信息
void Find(); //查找学生信息
void Edit(); //修改学生信息
void Delete(); //删除学生信息
void Numsort(); //按照学号排序
void Sumsort(); //按照总分排序
void OutputT(char *);//输出表格头部
void OutputL(); //输出表格尾部
void Jsys(); //90分以上的
void Jfyx(); //平均分以下的
void Bjg(); //不及格的学生
void Setpass(); //修改登录密码
private:
Student *p,*ps; //定义动态指针和表头指针
};
School::~School()
{
p=ps;
while(p!=0)
{
ps=p->next;
delete p;
p=ps;
}
}
//批量输入、增加学生信息
void School::Input()
{
do{
system("cls");
cout<<endl<<endl<<endl<<endl;
cout<<"\t\t >>>>>>>>>>>> 输入学生信息 <<<<<<<<<<<<"<<endl<<endl;
if(ps==0)
{
ps=new Student;
ps->Set();
}
else
{
p=ps;
while(p->next!=0)
p=p->next;
p->next=new Student;
p->next->Set();
}
cout<<endl<<"\t\t [任意键]-继续添加 [ESC]-返回上层"<<endl;
}while(getch()!=27);
Sumsort();
}
//输出表格头部
void School::OutputT(char *title)
{
system("cls");
cout<<endl;
cout<<"╔════════════ "<< title <<" ════════════╗"<<endl;
cout<<"╟───────────────┬─────────────────────╢"<<endl;
cout<<"║学号 姓名 性别 ┆数学 英语 物理 C++ 课设 ┆总分 均分 名次║"<<endl;
}
//输出表格尾部
void School::OutputL()
{
cout<<"╚═══════════════╧═════════════════════╝"<<endl;
}
//输出全体学生信息
void School::Output(int x)
{
if(ps==0)
{
system("cls");
cout<<endl<<endl<<endl<<endl;
cout<<"\t\t╔═════════════════════╗"<<endl;
cout<<"\t\t║ ║"<<endl;
cout<<"\t\t║ 无学生信息记录! ║"<<endl;
cout<<"\t\t║ ║"<<endl;
cout<<"\t\t╚═════════════════════╝"<<endl;
cout<<endl<<endl<<endl<<endl;
}
else
{
system("cls");
cout<<endl;
string title[2]={"按 照 学 号 排 序 输 出","按 照 总 分 排 序 输 出"};
OutputT(title[x]);
for(p=ps;p!=0;p=p->next) p->Print();
OutputL();
}
getch();
}
//载入学生信息
void School::Load()
{
ifstream infile("student.dat");
infile>>password;
if(strcmp(password,"")==0) //判断文件是否为空
{
infile.close();
ofstream outfile("student.dat");
outfile<<"administrator";
outfile.close();
infile.open("student.dat");
infile>>password;
}
while(!infile.eof())
{
p=ps=new Student;
p->Set(infile);
while(!infile.eof())
{
p=p->next=new Student;
p->Set(infile);
}
}
infile.close();
}
//保存学生信息
void School::Save()
{
ofstream outfile("student.dat");
outfile<<password;
for(p=ps;p!=0;p=p->next) p->Print(outfile);
outfile.close();
system("cls");
cout<<endl<<endl<<endl<<endl;
cout<<"\t\t╔═════════════════════╗"<<endl;
cout<<"\t\t║ ║"<<endl;
cout<<"\t\t║ 学生信息保存成功! ║"<<endl;
cout<<"\t\t║ ║"<<endl;
cout<<"\t\t╚═════════════════════╝"<<endl;
cout<<endl<<endl<<endl<<endl;
getch();
}
//搜索学生信息
Student * School::Search()
{
int m=0;
string l[2];
while(1)
{
strcpy(l[m]," → ");
strcpy(l[(m+1)%2]," ");
system("cls");
cout<<endl<<endl<<endl<<endl;
cout<<"\t\t╔═════════════════════╗"<<endl;
cout<<"\t\t║ ║"<<endl;
cout<<"\t\t║ "<<l[0]<<"按照学号查询 ║"<<endl;
cout<<"\t\t║ ║"<<endl;
cout<<"\t\t║ "<<l[1]<<"按照姓名查询 ║"<<endl;
cout<<"\t\t║ ║"<<endl;
cout<<"\t\t╚═════════════════════╝"<<endl;
cout<<endl<<endl<<endl<<endl;
switch(getch())
{
case '1':
case '2':
case '3':
case '5':
case 32:m==0? m=1:m=0; break;
case '\r':
switch(m)
{
case 0: string num;
cout<<endl<<"\t\t 请输入学号:";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -