哈尔滨理工大学
软件与微电子学院
《面型对象程序设计(vc++)》
项目实践报告
题 目: | 学生学籍管理系统 |
班 级: | 软件18- 1 班 |
专 业: | 软件工程 |
姓 名: | 张立辉 |
学 号: | 1814010130 |
指导教师: | 高龙 |
日 期: | 2019年6月18日 |
哈尔滨理工大学软件与微电子学院
目录
一、系统需求分析--------------------------------------------------------2
二、系统结构设计--------------------------------------------------------3
三、系统实现-------------------------------------------------------------4
1、核心代码---------------------------------------------------------------4
2、实现效果---------------------------------------------------------------4
四、系统测试-------------------------------------------------------------6
五、项目实践总结--------------------------------------------------------6
一、系统需求分析
本系统为学生学籍信息管理系统,主要实现的功能包括:
数据的输入,输出,查询,增加,修改,排序,删除,以及保存到txt文件中方便下次使用,
1. 菜单功能
简洁明了的列出程序所能执行的所有功能,并给人提示如何进行下一步,快速根据使用者的需求,选择所需要的功能。
2. 数据输入功能
实现了数据的输入功能,依次提示使用者所需要输入的数据。
3. 数据输出功能
依次输出使用者所录入的全部数据,以及原本文件内所预设的全部数据,并进行一定程度的整理,使使用者可以更方便的读取。
4. 数据查询功能
使用者根据提示,可以自由选择所向要查询的数据种类,例如根据学号查询还是根据被查询人其他信息查询,其中除学号查询外,其他查询输出均为同一类型所有学生的信息。
5. 数据添加功能
标准的数据增加功能,给录入提供了更多更方便的选择,而不需要一次性录入所有学生,解决了一次性录入麻烦而又枯燥的问题。
6. 数据修改功能
针对录入学生信息的修改,可以单独选择修改某一学生的某一特定信息,而不需要对学生的信息进行整体的修改,比录入出错后需要删除后重新录入减少了工作量。
7. 数据删除功能
对于不需要的学生信息可以进行一次性的全部删除某一学生的所有信息,方便快捷,省时省力。
8. 数据保存功能
将数据保存为txt文档,方便了下一次实用程序是的读取和调用,同样的使用txt文档也可以直接对数据进行读取,增加了数据的适用范围。
二、系统结构设计
按照系统需求分析结果,采用模块化程序设计思想,系统的整体结构设计如下:
1. 系统中的数据定义
(1)定义基类student类,用于储存学生数据
class student //学生类
{
public:
string xm, kc[5], xb, sheng, shi, xi, zy, mz;
int bj, xh, nl, ll;
float cj[5];
string dhh, sfzh;
sj time;
void srxhh();//输入学号
void sr();//初始化输入学生信息
void chengji();//录入/修改成绩
void chengjisc();//显示成绩
private:
};
(2)定义友源类gn类,用于更好的使用针对基类student类的操作函数
class gn :public student
{
public:
void duqu(int n);//读取数据
void bangzhu();//操作指令提示
int shuru(int n);//1:输入
void xianshi(int n);//2:显示
student xiugai(int n); //3:信息修改
void chazhao(int n);//4:查找
void paixu(int n);//5:排序
void cxkb(int n);//6:显示课程
void cj(int n);//7:成绩
void jigelv(int n);//8:及格率
void bcxx(int n); //9:保存信息
int shanchu(int n);//11:删除
};
(2)定义时间结构体sj,用于显示当前时间以及储存学生入学时间,
struct sj
{
int year, month, day; //时间结构体
void shuru() { cin >> year >> month >> day; }
void dqsj() //输出现在时间以及当前月份日历
{
struct tm t;
time_t now;
time(&now);
localtime_s(&t, &now);
int year = t.tm_year + 1900;
int month = t.tm_mon + 1;
int day = t.tm_mday;
int hour = t.tm_hour;
int minute = t.tm_min;
int second = t.tm_sec;
cout << "当前时间: " << year << "年" << month << "月" << day << "日" << ' '
<< hour << ":" << minute << ":" << second << endl << endl;
}
- 主程序(main函数)流程设计
3.登录流程设计
4.添加学生信息流程设计
5.显示学生信息流程设计
6.修改学生信息流程设计
7.查找学生信息流程设计
8.学生信息排序流程设计
9.课程查询流程设计
10.成绩查询流程设计
11.及格率查询流程设计
12.保存学生信息流程设计
13.修改密码流程设计
14.删除学生信息流程设计
三、系统实现
- 核心代码
Student.h文件:
#pragma once
#include <iostream>
#include <string>
#include<ctime>
using namespace std;
struct sj
{
int year, month, day; //时间结构体
void shuru() { cin >> year >> month >> day; }
void dqsj() //输出现在时间以及当前月份日历
{
struct tm t;
time_t now;
time(&now);
localtime_s(&t, &now);
int year = t.tm_year + 1900;
int month = t.tm_mon + 1;
int day = t.tm_mday;
int hour = t.tm_hour;
int minute = t.tm_min;
int second = t.tm_sec;
cout << "当前时间: " << year << "年" << month << "月" << day << "日" << ' '
<< hour << ":" << minute << ":" << second << endl << endl;
}
};
class student //学生类
{
public:
string xm, kc[5], xb, sheng, shi, xi, zy, mz;
int bj, xh, nl, ll;
float cj[5];
string dhh, sfzh;
sj time;
void srxhh();//输入学号
void sr();//初始化输入学生信息
void chengji();//录入/修改成绩
void chengjisc();//显示成绩
private:
};
ms.h文件:
#pragma once
#include "pch.h"
#include "student.h"
#include <iostream>
#include <string>
#include<conio.h>
#include<ctime>
#include<iomanip>
# include<fstream>
using namespace std;
sj sjj;
void mima()//10:初始化设置密码
{
sjj.dqsj();
cout << "**********************学籍管理系统************************" << endl;
cout << "请设置密码:" << endl;
string mm1, mm2;
char ch;
while ((ch = _getch()) != 13)
{
mm1 += ch;
cout << "*";
}
cout << endl;
cout << "请再次确认密码:" << endl;
while ((ch = _getch()) != 13)
{
mm2 += ch;
cout << "*";
}
if (mm1 == mm2)
{
ofstream mi;
mi.open("密码.txt");
string mimi;
mimi = mm1;
mi << mimi;
mi.close();
cout << endl;
cout << "密码修改成功!" << endl;
}
else
{
cout << endl << "错误!" << endl << "请重新设置" << endl;
mima();
}
}
int denglu(string mm)//登陆程序
{
sjj.dqsj();
cout << "**********************学籍管理系统************************" << endl;
cout << "请输入登陆密码:" << endl;
string mm1, mm2, mm3;
char ch;
while ((ch = _getch()) != 13)
{
mm1 += ch;
cout << "*";
}
system("cls");
sjj.dqsj();
cout << "**********************学籍管理系统************************" << endl;
if (mm == mm1)
return 1;
else
{
cout << "密码错误,您还有两次机会,请重试" << endl << "请重新输入密码" << endl;
while ((ch = _getch()) != 13)
{
mm2 += ch;
cout << "*";
}
system("cls");
if (mm == mm2)
return 1;
else
{
cout << "密码错误,您还有一次机会,请重试" << endl << "请重新输入密码" << endl;
while ((ch = _getch()) != 13)
{
mm3 += ch;
cout << "*";
}
system("cls");
if (mm == mm3)
return 1;
else
{
cout << "密码错误,请明天再试" << endl;
return 0;
}
}
}
}
gn.h文件:
#pragma once
#include"student.h"
#include <iostream>
#include <string>
using namespace std;
class gn :public student
{
public:
void duqu(int n);//读取数据
void bangzhu();//操作指令提示
int shuru(int n);//1:输入
void xianshi(int n);//2:显示
student xiugai(int n); //3:信息修改
void chazhao(int n);//4:查找
void paixu(int n);//5:排序
void cxkb(int n);//6:显示课程
void cj(int n);//7:成绩
void jigelv(int n);//8:及格率
void bcxx(int n); //9:保存信息
int shanchu(int n);//11:删除
};
student.cpp文件:
#include "pch.h"
#include "student.h"
#include <iostream>
using namespace std;
int shurupanduan(int, int, int);//输入判断
int runnian(int);//判断是是否为闰年
void student::srxhh()
{
cout << "**********************************************************" << endl;
cout << "* *" << endl;
cout << "* 《使用说明》 *" << endl;
cout << "* *" << endl;
cout << "*========================================================*" << endl;
cout << "* 依次按提示输入学生学籍信息 *" << endl;
cout << "* *" << endl;
cout << "*========================================================*" << endl;
cout << "请输入学号" << endl;
cin >> xh;
}
void student::sr() //////初始化输入学生信息
{
cout << "请输入姓名" << endl;
cin >> xm;
cout << "请输入性别" << endl;
cin >> xb;
cout << "请输入年龄" << endl;
cin >> nl;
cout << "请输入民族" << endl;
cin >> mz;
cout << "请输入电话号" << endl;
cin >> dhh;
cout << "请输入身份证号码" << endl;
cin >> sfzh;
cout << "请输入请输入籍贯中间用空格隔开" << endl;
cin >> sheng >> shi;
cout << "请输入入学日期中间用空格隔开" << endl;
time.shuru();
ll = shurupanduan(time.year, time.month, time.day);
if (ll == 0)
{
time.shuru();
}
cout << "请输入学院" << endl;
cin >> xi;
cout << "请输入专业" << endl;
cin >> zy;
cout << "请输入班级" << endl;
cin >> bj;
cout << "请输入课程(5门)中间用空格隔开" << endl;
for (int i = 0; i < 5; i++)
{
cin >> kc[i];
for (int j = 0; j < i; j++)
{
while (kc[i] == kc[j])
{
cout << "您已经选过该课程请重新输入" << endl;
cin >> kc[i];
}
}
}
chengji();
system("pause");
}
void student::chengji()//成绩录入
{
int i;
for (i = 0; i < 5; i++)
{
cout << "请输入" << kc[i] << "的成绩" << endl;
cin >> cj[i];
}
}
void student::chengjisc()//7:成绩输出
{
int i;
cout << "姓名" << xm << endl;
for (i = 0; i < 5; i++)
{
cout << "课程:" << kc[i] << endl;
cout << "成绩:" << cj[i] << endl << endl;
}
}
int shurupanduan(int a, int b, int c = 1) //判断输入年月日是否正确
{
int l = 1, q, ll;
if (a <= 0 || b <= 0 || b > 12 || c < 0)
{
l = 0;
cout << "您的输入有误请重新输入" << endl;
}
switch (b)
{
case 1:q = 31; break;
case 2:q = 28; break;
case 3:q = 31; break;
case 5:q = 31; break;
case 7:q = 31; break;
case 8:q = 31; break;
case 10:q = 31; break;
case 12:q = 31; break;
case 4:q = 30; break;
case 6:q = 30; break;
case 9:q = 30; break;
case 11:q = 30; break;
}
ll = runnian(a);
if (ll)
q++;
if (c > q)
{
l = 0;
cout << "您的输入有误请重新输入" << endl;
}
return l;
}
int runnian(int a) //判断是是否为闰年
{
int l = 0;
if ((a % 4 == 0 && a % 100 != 0) || (a % 400 == 0))
l = 1;
return l;
}
gn.cpp文件:
#include "pch.h"
#include "gn.h"
#include <iostream>
#include <string>
#include <map>
#include<iomanip>
# include<fstream>
void shuchuxinxi(student t);
student stu[500];
void gn::duqu(int n)//读取数据
{
ifstream infile("学生信息.txt");
for (int i = 0; i < n; i++)
{
infile >> stu[i].xh
>> stu[i].xm
>> stu[i].xb
>> stu[i].nl
>> stu[i].mz
>> stu[i].dhh
>> stu[i].sfzh
>> stu[i].sheng >> stu[i].shi
>> stu[i].time.year >> stu[i].time.month >> stu[i].time.day
>> stu[i].xi
>> stu[i].zy
>> stu[i].bj
>> stu[i].kc[0] >> stu[i].kc[1] >> stu[i].kc[2] >> stu[i].kc[3] >> stu[i].kc[4]
>> stu[i].cj[0] >> stu[i].cj[1] >> stu[i].cj[2] >> stu[i].cj[3] >> stu[i].cj[4];
}
infile.close();
}
void gn::bangzhu()//操作指令提示
{
system("cls");
cout << "****************************学籍管理系统*********************************" << endl;
cout << " ________________________________________________________ " << endl;
cout << "| |" << endl;
cout << "| 欢迎使用张立辉制作的 |" << endl;
cout << "| 学生学籍管理系统 |" << endl;
cout << "| |" << endl;
cout << "|========================================================|" << endl;
cout << "| 请输入以下指令 |" << endl;
cout << "| |" << endl;
cout << "|========================================================|" << endl;
cout << "| 1:添加学生 2:输出所有学生 |" << endl;
cout << "|========================================================|" << endl;
cout << "| 3:输入学号修改学生信息 4:查找学生信息 |" << endl;
cout << "|========================================================|" << endl;
cout << "| 5:按学号排序 6:课程查询 |" << endl;
cout << "|========================================================|" << endl;
cout << "| 7:成绩查询 8:查询及格率 |" << endl;
cout << "|========================================================|" << endl;
cout << "| 9:保存学生信息 10:修改密码 |" << endl;
cout << "|========================================================|" << endl;
cout << "| 11:输入学号删除学生信息 0:结束本程序 |" << endl;
cout << "|________________________________________________________|" << endl;
}
bool pdxhcf(int n, int a)//判断学号是否重复
{
bool l = 1;
int i;
for (i = 0; i < n; i++)
{
if (a == stu[i].xh)
{
l = 0;
break;
}
}
return l;
}
int gn::shuru(int n)
{
stu[n].srxhh();
while (!pdxhcf(n, stu[n].xh))
{
cout << "已存在该学生请重新输入" << endl;
system("pause");
system("cls");
stu[n].srxhh();
}
stu[n].sr();
n++;
return n;
}
void gn::xianshi(int n)//2:显示
{
for (int i = 0; i < n; i++)
{
cout << "学号:" << stu[i].xh << endl
<< "姓名:" << stu[i].xm << endl
<< "性别:" << stu[i].xb << endl
<< "年龄:" << stu[i].nl << endl
<<"民族:"<< stu[i].mz << endl
<<"电话号:"<< stu[i].dhh << endl
<<"身份证号码:"<< stu[i].sfzh << endl
<< "籍贯:" << stu[i].sheng << setw(4) << stu[i].shi << endl
<< "入学日期:" << stu[i].time.year << setw(4) << stu[i].time.month << setw(4) << stu[i].time.day << endl
<< "学院:" << stu[i].xi << endl
<< "专业:" << stu[i].zy << endl
<< "班级:" << stu[i].bj << endl
<< "课程:" << stu[i].kc[0] << setw(4) << stu[i].kc[1] << setw(4) << stu[i].kc[2] << setw(4) << stu[i].kc[3] << setw(4) << stu[i].kc[4] << endl
<< "成绩:" << stu[i].cj[0] << setw(4) << stu[i].cj[1] << setw(4) << stu[i].cj[2] << setw(4) << stu[i].cj[3] << setw(4) << stu[i].cj[4] << endl << endl;
}
}
student gn::xiugai(int n) //3:信息修改
{
cout << "请输入要修改信息的学生学号 " << endl;
cin >> xh;
int p;
for (int i = 0; i < n; i++)
{
if (stu[i].xh == xh)
{
p = i;
break;
}
}
system("cls");
cout << "**********************************************************" << endl;
cout << "* *" << endl;
cout << "* 《使用说明》 *" << endl;
cout << "* *" << endl;
cout << "*========================================================*" << endl;
cout << "* 依次按提示修改学生学籍信息 *" << endl;
cout << "*========================================================*" << endl;
cout << "* 1:修改姓名 2:修改性别 *" << endl;
cout << "*========================================================*" << endl;
cout << "* 3:修改年龄 4:修改民族 *" << endl;
cout << "*========================================================*" << endl;
cout << "* 5:修改电话号 6:身份证号码 *" << endl;
cout << "*========================================================*" << endl;
cout << "* 7:修改籍贯 8:修改入学时间 *" << endl;
cout << "*========================================================*" << endl;
cout << "* 9:修改系别 10:修改专业 *" << endl;
cout << "*========================================================*" << endl;
cout << "* 11:修改班级 12:修改课程 *" << endl;
cout << "*========================================================*" << endl;
cout << "* 13:修改成绩 *" << endl;
cout << "**********************************************************" << endl;
int a, i;
string xk;
cin >> a;
switch (a)
{
case 1:
cout << "请输入修改后姓名" << endl;
cin >> stu[p].xm;
break;
case 2:
cout << "请输入修改后性别" << endl;
cin >> stu[p].xb;
break;
case 3:
cout << "请输入修改后年龄" << endl;
cin >> stu[p].nl;
break;
case 4:
cout << "请输入修改后民族" << endl;
cin >> stu[p].mz;
break;
case 5:
cout << "请输入修改后电话号" << endl;
cin >> stu[p].dhh;
break;
case 6:
cout << "请输入修改后身份证号码" << endl;
cin >> stu[p].sfzh;
break;
case 7:
cout << "请输入修改后籍贯" << endl;
cin >> stu[p].sheng >> stu[p].shi;
break;
case 8:
cout << "请输入修改后入学时间" << endl;
cin >> stu[p].time.year >> stu[p].time.month >> stu[p].time.day;
break;
case 9:
cout << "请输入修改后系别" << endl;
cin >> stu[p].xm;
break;
case 10:
cout << "请输入修改后专业" << endl;
cin >> stu[p].xm;
break;
case 11:
cout << "请输入修改后班级" << endl;
cin >> stu[p].bj;
break;
case 12:
cout << "请输入修改后课程" << endl;
for (i = 0; i < 5; i++)
{
cin >> stu[p].kc[i];
}
break;
case 13:
cout << "请输入课程名" << endl;
cin >> xk;
for (i = 0; i < 5; i++)
{
if (stu[p].kc[i] == xk)
{
cout << "请输入修改后成绩" << endl;
cin >> stu[p].kc[i];
}
}
break;
default:
cout << "错误!!!";
break;
}
return stu[p];
}
void shuchuxinxi(student t) //输出学生信息
{
cout << "学号:" << t.xh << endl
<< "姓名:" << t.xm << endl
<< "性别:" << t.xb << endl
<< "年龄:" << t.nl << endl
<< "民族:" << t.mz << endl
<< "电话号:" << t.dhh << endl
<< "身份证号码:" << t.sfzh << endl
<< "籍贯:" << t.sheng << setw(4) << t.shi << endl
<< "入学日期:" << t.time.year << setw(4) << t.time.month << setw(4) << t.time.day << endl
<< "学院:" << t.xi << endl
<< "专业:" << t.zy << endl
<< "班级:" << t.bj << endl
<< "课程:" << t.kc[0] << setw(4) << t.kc[1] << setw(4) << t.kc[2] << setw(4) << t.kc[3] << setw(4) << t.kc[4] << endl
<< "成绩:" << t.cj[0] << setw(4) << t.cj[1] << setw(4) << t.cj[2] << setw(4) << t.cj[3] << setw(4) << t.cj[4] << endl << endl;
}
void gn::chazhao(int n)//4:查找
{
system("cls");
cout << "**********************************************************" << endl;
cout << "* *" << endl;
cout << "* 《使用说明》 *" << endl;
cout << "* *" << endl;
cout << "*========================================================*" << endl;
cout << "* 依次按提示查找学生学籍信息 *" << endl;
cout << "*========================================================*" << endl;
cout << "* 1:按学号查找 2:按姓名查找 *" << endl;
cout << "*========================================================*" << endl;
cout << "* 3:按性别查找 4:按年龄查找 *" << endl;
cout << "*========================================================*" << endl;
cout << "* 5:按民族查找 6:按电话号查找 *" << endl;
cout << "*========================================================*" << endl;
cout << "* 7:按身份证号码查找 8:按籍贯查找 *" << endl;
cout << "*========================================================*" << endl;
cout << "* 9:按入学时间查找 10:按系别查找 *" << endl;
cout << "*========================================================*" << endl;
cout << "* 11:按专业查找 12:按班级查找 *" << endl;
cout << "*========================================================*" << endl;
cout << "* 13:按课程查找 *" << endl;
cout << "**********************************************************" << endl;
int a;
string xm, kc, xb, sheng, shi, xi, zy, mz;
int bj, xh, nl;
string dhh, sfzh;
sj time;
cin >> a;
switch (a)
{
case 1:
cout << "请输入学号 " << endl;
cin >> xh;
for (int i = 0; i < n; i++)
{
if (stu[i].xh == xh)
{
shuchuxinxi(stu[i]);
break;
}
}
break;
case 2:
cout << "请输入姓名 " << endl;
cin >> xm;
for (int i = 0; i < n; i++)
{
if (stu[i].xm == xm)
{
shuchuxinxi(stu[i]);
}
}
break;
case 3:
cout << "请输入性别 " << endl;
cin >> xb;
for (int i = 0; i < n; i++)
{
if (stu[i].xb == xb)
{
shuchuxinxi(stu[i]);
}
}
break;
case 4:
cout << "请输入年龄 " << endl;
cin >> nl;
for (int i = 0; i < n; i++)
{
if (stu[i].nl == nl)
{
shuchuxinxi(stu[i]);
}
}
break;
case 5:
cout << "请输入民族 " << endl;
cin >> mz;
for (int i = 0; i < n; i++)
{
if (stu[i].mz == mz)
{
shuchuxinxi(stu[i]);
}
}
break;
case 6:
cout << "请输入电话号 " << endl;
cin >> dhh;
for (int i = 0; i < n; i++)
{
if (stu[i].dhh == dhh)
{
shuchuxinxi(stu[i]);
break;
}
}
break;
case 7:
cout << "请输入身份证号码 " << endl;
cin >> sfzh;
for (int i = 0; i < n; i++)
{
if (stu[i].sfzh == sfzh)
{
shuchuxinxi(stu[i]);
}
}
break;
case 8:
cout << "请输入籍贯 " << endl;
cin >> sheng;
cin >> shi;
for (int i = 0; i < n; i++)
{
if (stu[i].sheng == sheng || stu[i].shi == shi)
{
shuchuxinxi(stu[i]);
}
}
break;
case 9:
cout << "请输入入学时间 " << endl;
cin >> time.year >> time.month >> time.day;
for (int i = 0; i < n; i++)
{
if (stu[i].time.year == time.year || stu[i].time.month == time.month || stu[i].time.day == time.day)
{
shuchuxinxi(stu[i]);
}
}
break;
case 10:
cout << "请输入系别 " << endl;
cin >> xi;
for (int i = 0; i < n; i++)
{
if (stu[i].xi == xi)
{
shuchuxinxi(stu[i]);
}
}
break;
case 11:
cout << "请输入专业 " << endl;
cin >> zy;
for (int i = 0; i < n; i++)
{
if (stu[i].zy == zy)
{
shuchuxinxi(stu[i]);
}
}
break;
case 12:
cout << "请输入班级 " << endl;
cin >> bj;
for (int i = 0; i < n; i++)
{
if (stu[i].bj == bj)
{
shuchuxinxi(stu[i]);
}
}
break;
case 13:
cout << "请输入课程 " << endl;
cin >> kc;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < 5; j++)
{
if (stu[i].kc[j] == kc)
{
shuchuxinxi(stu[i]);
}
}
}
break;
default:
cout << "错误!!!" << endl;
system("pause");
}
}
void gn::paixu(int n)//5:排序
{
student st;
for (int i = 0; i < n - 1; i++)
{
for (int j = 0; j < n - i - 1; j++)
{
if (stu[j].xh > stu[j + 1].xh)
{
st = stu[j + 1];
stu[j + 1] = stu[j];
stu[j] = st;
}
}
}
cout << "排序后学生顺序为:" << endl;
for (int i = 0; i < n; i++)
{
cout << "学号:" << stu[i].xh << endl
<< "姓名:" << stu[i].xm << endl
<< "性别:" << stu[i].xb << endl
<< "年龄:" << stu[i].nl << endl
<< "籍贯:" << stu[i].sheng << setw(4) << stu[i].shi << endl
<< "入学日期:" << stu[i].time.year << setw(4) << stu[i].time.month << setw(4) << stu[i].time.day << endl
<< "学院:" << stu[i].xi << endl
<< "专业:" << stu[i].zy << endl
<< "班级:" << stu[i].bj << endl
<< "课程:" << stu[i].kc[0] << setw(4) << stu[i].kc[1] << setw(4) << stu[i].kc[2] << setw(4) << stu[i].kc[3] << setw(4) << stu[i].kc[4] << endl
<< "成绩:" << stu[i].cj[0] << setw(4) << stu[i].cj[1] << setw(4) << stu[i].cj[2] << setw(4) << stu[i].cj[3] << setw(4) << stu[i].cj[4] << endl << endl;
}
}
void gn::cxkb(int n)//6:显示课程
{
cout << "**********************************************************" << endl;
cout << "* *" << endl;
cout << "* 《使用说明》 *" << endl;
cout << "* *" << endl;
cout << "*========================================================*" << endl;
cout << "* *" << endl;
cout << "* 请输入学号 *" << endl;
cout << "* *" << endl;
cout << "**********************************************************" << endl;
cin >> xh;
for (int i = 0; i < n; i++)
{
if (stu[i].xh == xh)
{
cout << endl << "学号:" << stu[i].xh << endl << "姓名:" << stu[i].xm << endl << "课程:" ;
for (int j = 0; j < 5; j++)
{
cout << stu[i].kc[j] << ' ';
}
cout << endl;
break;
}
}
}
void gn::cj(int n)//
{
int xh;
cout << "**********************************************************" << endl;
cout << "* *" << endl;
cout << "* 《使用说明》 *" << endl;
cout << "* *" << endl;
cout << "*========================================================*" << endl;
cout << "* *" << endl;
cout << "* 1:输入/修改学生成绩 2:显示学生成绩 *" << endl;
cout << "* *" << endl;
cout << "**********************************************************" << endl;
int a;
cin >> a;
if (a == 1)
{
cout << "请输入学号 " << endl;
cin >> xh;
for (int i = 0; i < n; i++)
{
if (stu[i].xh == xh)
{
stu[i].chengji();
cout << endl;
}
}
}
else
{
cout << "请输入学号 " << endl;
cin >> xh;
for (int i = 0; i < n; i++)
{
if (stu[i].xh == xh)
{
stu[i].chengjisc();
cout << endl;
}
}
}
}
void gn::jigelv(int n)//8:及格率
{
double no = 0.00, yes = 0.00;
double jigelv;
cout << "**********************************************************" << endl;
cout << "* *" << endl;
cout << "* 《使用说明》 *" << endl;
cout << "* *" << endl;
cout << "*========================================================*" << endl;
cout << "* *" << endl;
cout << "* 1:显示单个学生及格率 2:显示全体学生及格率 *" << endl;
cout << "* *" << endl;
cout << "**********************************************************" << endl;
int a;
cin >> a;
if (a == 1)
{
int xh;
cout << "请输入学号 " << endl;
cin >> xh;
for (int i = 0; i < n; i++)
{
if (stu[i].xh == xh)
{
cout << endl << "学号" << stu[i].xh << endl << "姓名" << stu[i].xm << endl;
for (int j = 0; j < 5; j++)
{
if (stu[i].cj[j] < 60.00)
{
no++;
cout << stu[i].kc[j] << ":不及格" << endl;
}
else
{
yes++;
cout << stu[i].kc[j] << ":及格" << endl;
}
}
jigelv = yes / 5.00;
jigelv = jigelv * 100.00;
cout << "及格率" << fixed << setprecision(2) << jigelv << "%" << endl << endl;
}
}
}
else
{
for (int i = 0; i < n; i++)
{
cout << endl << "学号" << stu[i].xh << endl << "姓名" << stu[i].xm << endl;
for (int j = 0; j < 5; j++)
{
if (stu[i].cj[j] < 60.00)
{
no++;
cout << stu[i].kc[j] << ":不及格" << endl;
}
else
{
yes++;
cout << stu[i].kc[j] << ":及格" << endl;
}
}
}
jigelv = yes / (n*5.00);
jigelv = jigelv * 100.00;
cout << endl << "全体及格率" << fixed << setprecision(2) << jigelv << "%" << endl << endl;
}
}
void gn::bcxx(int n)//9:保存信息
{
ofstream file1;
student t;
file1.open("学生信息.txt");
for (int i = 0; i < n; i++)
{
t = stu[i];
file1 << t.xh << " " << endl
<< t.xm << " " << endl
<< t.xb << " " << endl
<< t.nl << " " << endl
<< t.mz << " " << endl
<< t.dhh << " " << endl
<< t.sfzh << " " << endl
<< t.sheng << " " << t.shi << " " << endl
<< t.time.year << " " << t.time.month << " " << t.time.day << " " << endl
<< t.xi << " " << endl
<< t.zy << " " << endl
<< t.bj << " " << endl
<< t.kc[0] << " " << t.kc[1] << " " << t.kc[2] << " " << t.kc[3] << " " << t.kc[4] << " " << endl
<< t.cj[0] << " " << t.cj[1] << " " << t.cj[2] << " " << t.cj[3] << " " << t.cj[4] << " " << endl << endl;
}
file1.close();
ofstream into;
into.open("学生数量.txt");
into << n;
into.close();
cout << "保存成功!" << endl;
}
int gn::shanchu( int n)//11:删除
{
int xxh;
cout << "请输入要删除信息的学生学号 " << endl;
cin >> xxh;
for (int i = 0; i < n; i++)
{
if (stu[i].xh == xxh)
{
for (int j = i; j < n; j++)
{
stu[j] = stu[j + 1];
}
cout << endl;
cout << "删除成功!" << endl;
n--;
}
}
return n;
}
main.cpp文件:
#include "pch.h"
#include "student.h"
#include"studentmg.h"
#include "ms.h"
#include"gn.h"
#include <iostream>
#include <string>
#include <map>
#include<iomanip>
# include<fstream>
using namespace std;
gn gnn;
void tiaoshi(int n)//输出文件函数(调试用)
{
ifstream infile("学生信息.txt");
student st[20], t;
for (int i = 0; i < n; i++)
{
infile >> st[i].xh
>> st[i].xm
>> st[i].xb
>> st[i].nl
>> st[i].mz
>> st[i].dhh
>> st[i].sfzh
>> st[i].sheng >> st[i].shi
>> st[i].time.year >> st[i].time.month >> st[i].time.day
>> st[i].xi
>> st[i].zy
>> st[i].bj
>> st[i].kc[0] >> st[i].kc[1] >> st[i].kc[2] >> st[i].kc[3] >> st[i].kc[4]
>> st[i].cj[0] >> st[i].cj[1] >> st[i].cj[2] >> st[i].cj[3] >> st[i].cj[4];
cout << "学号:" << st[i].xh << endl
<< "姓名:" << st[i].xm << endl
<< "性别:" << st[i].xb << endl
<< "年龄:" << st[i].nl << endl
<< "民族:" << st[i].mz << endl
<< "电话号:" << st[i].dhh << endl
<< "身份证号码:" << st[i].sfzh << endl
<< "籍贯:" << st[i].sheng << setw(4) << st[i].shi << endl
<< "入学日期:" << st[i].time.year << setw(4) << st[i].time.month << setw(4) << st[i].time.day << endl
<< "学院:" << st[i].xi << endl
<< "专业:" << st[i].zy << endl
<< "班级:" << st[i].bj << endl
<< "课程:" << st[i].kc[0] << setw(4) << st[i].kc[1] << setw(4) << st[i].kc[2] << setw(4) << st[i].kc[3] << setw(4) << st[i].kc[4] << endl
<< "成绩:" << st[i].cj[0] << setw(4) << st[i].cj[1] << setw(4) << st[i].cj[2] << setw(4) << st[i].cj[3] << setw(4) << st[i].cj[4] << endl << endl;
}
infile.close();
}
int main() ////主函数..................
{
map<int, student> stu_v1;
system("title love 小傻彤");
string miimi;
ifstream in("密码.txt");
in >> miimi;
in.close();
int nn;
ifstream into("学生数量.txt");
into >> nn;
into.close();
int n,i;
n = nn;
string mm, xm;//密码
mm = miimi;
gnn.duqu(n);
i = denglu(mm);
if (i)
{
int a;
system("cls");//清屏
while (1)
{
sj ssj;
cout << "****************************学籍管理系统*********************************" << endl;
ssj.dqsj();
gnn.bangzhu();
cin >> a;
system("cls");
if (a == 0)
{
cout << "感谢使用!!!" << endl;
break;
}
else
{
switch (a)
{
case 1:
n= gnn.shuru(n);//输入
system("pause");//请按任意键继续
break;
case 2:
gnn.xianshi(n);//显示
system("pause");
break;
case 3:
gnn.xiugai(n);//修改
system("pause");
break;
case 4:
gnn.chazhao(n);//查找
system("pause");
break;
case 5:
gnn.paixu(n);//排序
system("pause");
break;
case 6:
gnn.cxkb(n);//查询课表
system("pause");
break;
case 7:
gnn.cj(n);//成绩
system("pause");
break;
case 8:
gnn.jigelv(n);//及格率
system("pause");
break;
case 9:
gnn.bcxx(n);//保存信息
system("pause");
break;
case 10:
mima();//密码
system("pause");
break;
case 11:
n=gnn.shanchu(n);//删除
system("pause");
break;
case 111:
tiaoshi(n);
system("pause");
break;
case 222:
cout << "学生数量n:" << n << endl;
system("pause");
break;
case 333:
cout << "程序密码mm:" << mm << endl;
system("pause");
break;
default:
cout << "错误!!!" << endl;
system("pause");
}
}
}
}
return 0;
}
- 实现效果
(1)登录界面实现效果如图1所示:
若密码输入错误如图2,3,4所示:
(2)主界面实现效果如图5所示:
(3)添加学生界面实现效果如图6所示:
(4)显示所有学生界面实现效果如图7 所示:
(5)修改学生信息界面实现效果如图8 ,9所示:
(6)查找学生信息界面实现效果如图 10所示:
(7)按学号排序界面实现效果如图12 所示:
(8)课程查询界面实现效果如图13 所示:
(9)成绩界面实现效果如图 14,15,,16所示:
(10)查询及格率界面实现效果如图17,18,19 所示:
(11)保存学生信息界面实现效果如图20 所示:
(12)修改密码界面实现效果如图 21所示:
(13)删除学生信息界面实现效果如图 22所示:
四、系统测试
输入内容:
1814010130
张立辉
男
20
汉族
15004639878
230121200000000000
黑龙江省 哈尔滨市
2019 6 16
软件与微电子学院
软件工程
1
语文 数学 英语 生物 物理
99 99 99 99 99
期望的输出结果:(包含已经保存到文件内的数据)
2
2
2
2
2
2
2
2 2
2 2 2
2
2
2
2 3 4 5 6
60 50 40 30 20
1
1
1
1
1
1
1
1 1
1 1 1
1
1
1
1 2 3 4 5
50 40 30 20 10
1814010130
张立辉
男
20
汉族
15004639878
230121200000000000
黑龙江省 哈尔滨市
2019 6 16
软件与微电子学院
软件工程
1
语文 数学 英语 生物 物理
99 99 99 99 99
实际输出结果:
2
2
2
2
2
2
2
2 2
2 2 2
2
2
2
2 3 4 5 6
60 50 40 30 20
1
1
1
1
1
1
1
1 1
1 1 1
1
1
1
1 2 3 4 5
50 40 30 20 10
1814010130
张立辉
男
20
汉族
1.50046e+10
2.30121e+17
黑龙江省 哈尔滨市
2019 6 16
软件与微电子学院
软件工程
1
语文 数学 英语 生物 物理
99 99 99 99 99
期望的保存结果:(包含已经保存到文件内的数据)
2
2
2
2
2
2
2
2 2
2 2 2
2
2
2
2 3 4 5 6
60 50 40 30 20
1
1
1
1
1
1
1
1 1
1 1 1
1
1
1
1 2 3 4 5
50 40 30 20 10
1814010130
张立辉
男
20
汉族
15004639878
230121200000000000
黑龙江省 哈尔滨市
2019 6 16
软件与微电子学院
软件工程
1
语文 数学 英语 生物 物理
99 99 99 99 99
实际保存结果:
2
2
2
2
2
2
2
2 2
2 2 2
2
2
2
2 3 4 5 6
60 50 40 30 20
1
1
1
1
1
1
1
1 1
1 1 1
1
1
1
1 2 3 4 5
50 40 30 20 10
1814010130
张立辉
男
20
汉族
1.50046e+10
2.30121e+17
黑龙江省 哈尔滨市
2019 6 16
软件与微电子学院
软件工程
1
语文 数学 英语 生物 物理
99 99 99 99 99
存在的问题:
输出及保存电话号及身份证号码时输出发生错误,
其与功能均运行正常并得到了想要得到的运行结果。
解决方法:
将电话号及身份证号码的格式由double改为string。
更改后问题解决。
五、项目实践总结
通过本次项目实践,对类的运用,友源类的使用,结构体的使用,多文件结构的使用,以及保存数据到文件的使用有了更深刻的认识,能够更加熟练的拥有以上知识并得到想要的输出。