哈喽,大家好!代码小白爱分享又又又来分享代码了,已经很久没有。更新了捏😆
今天给大家带来的是我最近在做的一个学校实训项目,在众多选题中选择了学生个人消费信息管理系统。为啥?别问,问就是能力不够哈哈。
好了进入正题,我们先开看看题目描述:
学生个人消费管理系统
功能:创建学生个人消费信息,根据提示输入查询的学生学号查询学生消费信息,显示录入的学生信息,把录入的学生信息保存到指定的文件中。
本选题较为简单,主要要求是录入并查询学生的个人消费信息。但是为了实现功能的多样化,我把这两个功能分为了八个部分,分别是:录入学生个人信息,录入学生个人消费信息,录入学生充值信息,查询学生信息,查询学生消费信息,查询账户余额,查询学生消费信息及消费信息汇总。为了使得该系统更像个系统,我还象征性的设计了登录与注册页面(这些信息实际上只需要打开文件管理就可以查看)。既然有了登录与注册页面,那么修改密码功能也必不可少啦,于是便多了一项修改密码功能,当然,我还添加了进入学校官网功能(此处就先省略了,需要的可以自行添加网址,已注释)
该系统运用了学号直接做了文件名,为了方便查找,文件名+"in.txt"/"spend.txt"/"sec.txt"/.txt分别代表充值 消费 安全 信息文件
注意:管理员密码是:123456
想要更改网址操作是case 9那行
还是那句话,初学编程,欢迎更正!
#include<iostream>
#include<fstream>
#include<string>
#include<cmath>
using namespace std;
void check()//检查是否重复输入学生信息
{
string num;
cout << "*请输入一卡通号:*" <<endl;
cin >> num;
ifstream ifs;
ifs.open(num + ".txt", ios::in);
if (ifs.is_open())
{
cout << "--------------------------------------------------------------" << endl;
cout << "学生信息已存在!" << endl;
cout << "--------------------------------------------------------------" << endl;
}
else
{
cout << "--------------------------------------------------------------" << endl;
cout << "未查询到学生信息,请检查是否输入有误。" << endl;
cout << "--------------------------------------------------------------" << endl;
}
ifs.close();
}
void stuinformation()//录入学生的个人信息
{
string name;
string classname;
string num;
cout << "请输入学生姓名:" << endl;
cin >> name;
cout << "请输入学生班级:" << endl;
cin >> classname;
cout << "请输入学生一卡通号:" << endl;
cin >> num;
ofstream ofs;
string filename;
filename = num + ".txt";
ofs.open(filename, ios::out);
ofs << name << endl;
ofs << classname << endl;
ofs.close();
}
void stuspendinformation()//录入消费信息
{
string num;
string num1;
int time, spdnum;//消费时间,金额
string place, spdclass;//消费地点,类型
cout << "请输入学生学号: " << endl;
cin >> num;
num1 = num + "spend.txt";
ofstream ofs;
ofs.open(num1, ios::out | ios::app);
cout << "请输入消费时间(例如2023年6月28日为:2023628):" << endl;
cin >> time;
ofs << time << endl;
s:cout << "输入消费类型(餐饮,水费,电费,其他):" << endl;
cin >> spdclass;
if(spdclass=="餐饮"|| spdclass == "水费"|| spdclass == "电费"|| spdclass == "其他")
ofs << spdclass << endl;
else
{
cout << "输入有误,请按规则输入" << endl;
goto s;
}
cout << "请输入地点:" << endl;
cin >> place;
ofs << place << endl;
cout << "请输入金额:" << endl;
cin >> spdnum;
ofs << spdnum << endl;
ofs << "--------------------------------------------------------------" << endl;
ofs.close();
}
void stuin()//录入充值信息
{
int intime, innum;
string num;
cout << "请输入学号:" << endl;
cin >> num;
cout << "请输入充值时间(如:20230628):" << endl;
cin >> intime;
cout << "请输入充值金额:" << endl;
cin >> innum;
ofstream ofs;
ofs.open(num + "in.txt", ios::out);
ofs << intime << endl;
ofs << innum << endl;
ofs.close();
}
void findstu()//查询学生信息
{
string num;
fstream ifs;
cout << "请输入要查询的学生一卡通账号:" << endl;
cin >> num;
ifs.open(num + ".txt", ios::in);
if (!ifs.is_open())
{
cout << "未找到一卡通号为:" << num << "学生的信息!" << endl;
}
else
{
string name1;
string classname1;
getline(ifs, name1);
getline(ifs, classname1);
cout << "学生姓名为: " << name1 << endl;
cout << "学生所属班级为: " << classname1 << endl;
ifs.close();
ifs.open(num + "in.txt", ios::in);
string c, t;
getline(ifs, t);
getline(ifs, c);
cout << "最新充值时间为: " << t << endl;
cout << "最新充值金额为: " << c << endl;
ifs.close();
}
}
void findspenndinform()//查找学生消费信息
{
ifstream ifs;
string num,inform;
cout << "请输入一卡通账号:" << endl;
cin >> num;
ifs.open(num + "spend.txt", ios::in);
cout << "--------------------------------------------------------------" << endl;
if(ifs.is_open())
{
cout << "消费信息为:" << endl;
cout << "--------------------------------------------------------------" << endl;
int i = 1;
while (getline(ifs, inform))
{
if (i == 1) cout << "消费时间:" << inform << endl;
else if (i == 2) cout << "消费类型:" << inform << endl;
else if (i == 3) cout << "消费地点:" << inform << endl;
else if (i == 4) cout << "消费金额:" << inform << "元" << endl;
else {
cout << inform << endl;
i = 0;
};
++i;
}
ifs.close();
}
else
{
cout << "无此学生消费信息" << endl;
cout << "--------------------------------------------------------------" << endl;
}
}
void findbalance()//查询余额
{
string num,juge;
int t=0,i,c,k1=1,k2=4,l,m;
cout << "请输入一卡通账号:" << endl;
cin >> num;
ifstream ifs;
ifs.open(num +"in.txt",ios::in );
if (ifs.is_open())
{
for (i = 0; i <= 2; i++)
ifs >> c;
ifs.close();
ifs.open(num + "spend.txt", ios::in);
while (getline(ifs, juge))
{
if (k1 == k2)
{
i = juge.size() - 1;
m = i;
for (l = 0; l < i; l++)
{
t += (juge[l] - 48) * pow(10, m--);
}
k2 += 5;
}
++k1;
}
ifs.close();
cout << "一卡通号为:" << num << "的余额为:" << c - t -1<<"元"<< endl;
}
else
{
cout << "无此学生余额信息" << endl;
cout << "--------------------------------------------------------------" << endl;
}
}
void classspend()//查询各类型消费信息(餐饮,水费,电费,超市消费)
{
string num,inform;
cout << "请输入一卡通账号:"<<endl;
cin >> num;
ifstream ifs;
ifs.open(num + "spend.txt", ios::in);
if (ifs.is_open())
{
int cls[5] = { 0 }, t;
while (getline(ifs,inform))
{
if (inform == "餐饮")
{
getline(ifs, inform);
ifs >> t;
cls[0] += t;
}
else if (inform == "水费")
{
getline(ifs, inform);
ifs >> t;
cls[1] += t;
}
else if (inform == "电费")
{
{
getline(ifs, inform);
ifs >> t;
cls[2] += t;
}
}
else if (inform == "其他")
{
getline(ifs, inform);
ifs >> t;
cls[3] += t;
}
}
cls[4] = cls[1] + cls[2] + cls[3] + cls[0];
ifs.close();
cout << "--------------------------------------------------------------" << endl;
cout << "学号为:" << num << " 学生各类消费信息为:" << endl;
cout << "餐饮消费:" << cls[0] << endl;
cout << "水费:" << cls[1] << endl;
cout << "电费:" << cls[2] << endl;
cout << "其他消费:" << cls[3] << endl;
cout << "总消费为:" << cls[4] << endl;
cout << "--------------------------------------------------------------" << endl;
}
else
{
cout << "无此学生消费信息汇总" << endl;
cout << "--------------------------------------------------------------" << endl;
}
}
int secure(int y)//安全系统
{
string num;
cout << "请输入一卡通号:" << endl;
cin >> num;
if (y == 1)
{
ifstream ifs;
ifs.open(num + "sec.txt", ios::in);
if (ifs.is_open())
{
cout << "请输入密码:" << endl;
string mima, mima2;
cin >> mima;
ifs >> mima2;
if (mima == mima2) return 1;
else
{
cout << "密码错误!" << endl;
return 3;
}
}
else
{
return 0;
}
ifs.close();
}
else
{
cout << "为更好保护个人信息,本程序注册须有管理员密钥" << endl;
x:cout << "请输入管理员密钥:" << endl;
int n;
cin >> n;
if (n == 123456)
{
cout << "--------------------------------------------------------------" << endl;
cout << "管理员密钥正确" << endl;
cout << "--------------------------------------------------------------" << endl;
ofstream ofs;
ofs.open(num + "sec.txt", ios::out);
cout << "请输入密码:" << endl;
string sec;
cin >> sec;
ofs << sec << endl;
ofs.close();
return 2;
}
else
{
cout << "错误" << endl;
goto x;
}
}
}
void change()//修改密码
{
string mima,num;
cout << "--------------------------------------------------------------" << endl;
cout << "请输入一卡通号:";
cin >> num;
cout << endl;
cout << "请输入新密码:" ;
cin >> mima;
ofstream ofs;
ofs.open(num + "sec.txt", ios::out);
ofs << mima;
ofs.close();
cout << "密码更改成功!" << endl;
cout << "--------------------------------------------------------------" << endl;
}
int main()
{
system("color 47");
cout << " *********************************** " << endl;
cout << " * * * * * " << endl;
cout << " * * * " << endl;
cout << " * * * " << endl;
cout << " * * * " << endl;
cout << " * * * " << endl;
cout << " * * * * * * " << endl;
cout << " * * * " << endl;
cout << " * * * " << endl;
cout << " * * * " << endl;
cout << " * * * " << endl;
cout << " * * * " << endl;
cout << " * * * * * " << endl;
cout << " " << endl;
cout << " 志存高远,责任为先 " << endl;
v:cout << "--------------------------------------------------------------" << endl;
cout << "欢迎使用xxxxxxxxx大学xxxx校区学生个人消费管理系统! " << endl;//此行输入学校信息
cout << "请输入您想要的操作(如:1): " << endl;
cout << "1.进入管理系统 " << endl;
cout << "2.安全退出程序 " << endl;
cout << "3.查看程序信息 " << endl;
cout << "--------------------------------------------------------------" << endl;
int n;
l:cin >> n;
if (n == 1)
{
system("cls");
q:cout << "--------------------------------------------------------------" << endl;
cout << " 个人消费管理系统安全系统 " << endl;
cout << " 1.登录 " << endl;
cout << " 2.注册 " << endl;
cout << "-------------------------------------------------------------- " << endl;
int y, y1;
cin >> y;
y1 = secure(y);
if (y1 == 1||y1==2)
{
if (y1 == 2) cout << "注册成功!" << endl;
cout << "--------------------------------------------------------------" << endl;
cout << "| 已成功进入本程序 |" << endl;
cout << "--------------------------------------------------------------" << endl;
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 << "| 10.修改密码 |" << endl;
cout << "| 0.退出本程序 |" << endl;
cout << "--------------------------------------------------------------" << endl;
int y;
cout << "输入1代表继续,否则按任意键退出" << endl;
cin >> y;
if (y == 1)
{
system("cls");
int x;
while (1)
{
cout << "请继续选择您要进行的操作:(如:1)" << endl;
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 << "*10.修改密码 *" << endl;
cout << "* 0.退出本程序 *" << endl;
cout << "--------------------------------------------------------------" << endl;
cin >> x;
system("cls");
switch (x)
{
case 1: system("color F9"); stuinformation(); break;
case 2: system("color E0"); stuspendinformation(); break;
case 3: system("color 19"); stuin(); break;
case 4: system("color 20"); findstu(); break;
case 5: system("color 3B"); findspenndinform(); break;
case 6: system("color 40"); findbalance(); break;
case 7: system("color 50"); classspend(); break;
case 8: system("color A0"); check(); break;
case 9: system("start https://mp.csdn.net/mp_blog/creation/editor/131496528?spm=1000.2115.3001.4503"); break;
case 10:change(); break;
case 0:cout << "欢迎下次使用!" << endl; exit(0); break;
default:
cout << "无效操作,请检查您的操作代号。" << endl;
cout << "--------------------------------------------------------------" << endl;
}
}
}
else
{
cout << "成功退出系统!" << endl;
return 1;
}
}
else
{
if (y1 == 0) cout << "信息不存在,请先注册!" << endl;
goto q;
}
}
else if (n == 2)
{
system("cls");
cout << "已安全退出!欢迎下次使用。" << endl;
return 1;
}
else if (n == 3)
{
cout << "--------------------------------------------------------------" << endl;
cout << "开发日期:6月29日" << endl;
cout << "开发人员: " << endl;
cout << "程序版本:windous.vs.5.0" << endl;
cout << "--------------------------------------------------------------" << endl;
goto v;
}
else
{
cout << "操作错误!请重新输入:" << endl;
goto l;
}
}