基于C/C++实现的简单学生信息管理系统

                           基于C/C++实现的简单学生信息管理系统

这是本人在学习了C/C++后,自己尝试写的一个小项目,该程序实现了对学生的学号姓名,年龄和学科成绩进行管理的一个小程序,具体功能实现了包括(1:添加学生信息 2:查看学生信息(分为按学号姓名以及查看全部学生信息)3:删除学生信息 4:修改学生信息),具体代码实现如下:
头文件studentInformationSystem.h
#ifndef STUDENTINFORMATIONSYSTEM_H
#define STUDENTINFORMATIONSYSTEM_H
#include
#include
#include<windows.h>
#include
#include<string.h>
#include <process.h>
#include<conio.h>
#include<time.h>
#define SUPERUSER “zhonggaoke”
#define PASSWARD “zhonggaoke0410”
using namespace std;
typedef struct Score {
float math;
float english;
float chinese;
}score;
typedef struct Student {
char studentNumber[20];
char studentName[20];
char studentSex[20];
int studentAge;
score studentScore;
}stu;
#endif
源文件studentInformation.cpp
#include"studentInformationSystem.h"

class studentInformation {
public:
stu thisStudent;
public:
studentInformation();//构造函数
~studentInformation();//析构函数
int systemMenu();//系统菜单
int checkUser(int input);//检查那种用户执行
int addStudentInformation();//添加学生信息(super)
int checkStudentInformation();//查看学生信息
int nameAndNumberCheckStudentInformation();//按姓名学号查看信息
int allStudentInformation();//全部学生信息
int deleteStudentInformation();//删除学生信息(super)
int modificationStudentInformation();//修改学生信息(super)
int trueFunction();//实现各个操作
};

studentInformation::studentInformation()
{
system(“title student information system.”);
system(“color 5f”);
system(“mode con cols=60 lines=24”);
}
studentInformation::~studentInformation(){}

/菜单/

int studentInformation::systemMenu()
{
system(“cls”);
int input;
for (int i = 0; i < 6; i++) { cout << endl; }
cout << " )-------->"; cout << “1:添加学生信息.” << endl;
cout << " )-------->"; cout << “2:删除学生信息.” << endl;
cout << " )-------->"; cout << “3:修改学生信息.” << endl;
cout << " )-------->"; cout << “4:查看学生信息.” << endl<<endl;
cout << " ->"; cout << “请选择:”;
cin >> input;
while (input < 0 || input>10)
{
system(“cls”);
systemMenu();
}
return input;
}

/判断用户/

int studentInformation::checkUser(int input)
{
system(“cls”);
string account;
string passward;
if (input == 1 || input == 2 || input == 3)
{
cout << “该功能仅限于管理者登陆.” << endl;
cout << “SUPER USER:”;
cin >> account;
while (account != SUPERUSER)
{
cout << “账户错误(重新输入):”;
cin >> account;
}
cout << “PASSWARD:”;
cin >> passward;
while (passward != PASSWARD)
{
cout << “密码错误(重新输入):”;
cin >> passward;
}
}
system(“cls”);
cout << “登陆成功.” << endl;
return 0;
}

/添加学生信息/

int studentInformation::addStudentInformation()
{
system(“cls”);
int checkValue;
system(“title addstudentinformation”);
cout << “请输入学号:” << endl;
cin >> thisStudent.studentNumber;
cout << “请输入姓名:” << endl;
cin >> thisStudent.studentName;
cout << “请输入年龄:” << endl;
cin >> thisStudent.studentAge;
cout << “请输入性别:” << endl;
cin >> thisStudent.studentSex;
cout << “请输入数学成绩:” << endl;
cin >> thisStudent.studentScore.math;
cout << “请输入英语成绩:” << endl;
cin >> thisStudent.studentScore.english;
cout << “请输入语文成绩:” << endl;
cin >> thisStudent.studentScore.chinese;
FILE *thisFile;
thisFile = fopen(“E:\vs2017\studentinformationsystem\studentInformation.txt”, “a”);
fprintf(thisFile, “%-20s”,thisStudent.studentNumber);
fprintf(thisFile, “%-20s”,thisStudent.studentName);
fprintf(thisFile, “%-20s”, thisStudent.studentSex);
fprintf(thisFile, “%-4d”, thisStudent.studentAge);
fprintf(thisFile, “语文:%-8.1f”,thisStudent.studentScore.chinese);
fprintf(thisFile, “数学:%-8.1f”,thisStudent.studentScore.math);
fprintf(thisFile, “英语:%-8.1f”,thisStudent.studentScore.english);
fprintf(thisFile, “\n”);
fclose(thisFile);
cout << “1:继续添加 2:返回上一层” << endl;
cout << “请选择:”;
cin >> checkValue;
if (checkValue == 1)
{
addStudentInformation();
}
if (checkValue == 2)
{
system(“cls”);
cout << “—>3秒后将返回菜单…”;
Sleep(3000);
trueFunction();
}
return 0;
}

/查看学生信息/

int studentInformation::checkStudentInformation()
{
system(“cls”);
int checkChioce;
cout << “1:输入姓名/学号查看学生信息.” << endl;
cout << “2:查看全部学生信息.” << endl;
cout << “->请选择:”;
cin >> checkChioce;
while (checkChioce != 1 && checkChioce!=2)
{
cout << “!!!不合法的输入.” << endl;
cout << “->请选择:”;
cin >> checkChioce;
}
if (checkChioce == 1)
{
nameAndNumberCheckStudentInformation();
}
if (checkChioce == 2)
{
allStudentInformation();
}
return 0;
}
/按姓名学号查看学生信息/

int studentInformation::nameAndNumberCheckStudentInformation()
{
string thisNameOrNumber;
string getNameNumber;
int choice;
system(“cls”);
cout << “->按学生姓名学号查看学生信息:” << endl;
cout << “请输入学生姓名或者学号:”;
cin >> thisNameOrNumber;
ifstream file(“E:\vs2017\studentinformationsystem\studentInformation.txt”);
if (file)
{
while (getline(file, getNameNumber))
{
string::size_type idx;
idx = getNameNumber.find(thisNameOrNumber);
if (idx != string::npos)
{
//value = 1;
cout << getNameNumber << endl;
}
}
}
else
{
cout << “no file.”<<endl;
}
cout << “1:继续查找.2:返回菜单.” << endl;
cout << “请选择:”;
cin >> choice;
while (choice != 1 && choice != 2)
{
cout << “错误!!!” << endl;
cout << “请重新输入:”;
cin >> choice;
}
if (choice == 1)
{
nameAndNumberCheckStudentInformation();
}
if (choice == 2)
{
system(“cls”);
cout << “—>3秒后将返回菜单…”;
Sleep(3000);
trueFunction();
}
return 0;
}

/全部学生信息查看/

int studentInformation::allStudentInformation()
{
system(“cls”);
FILE *thisFile;
thisFile = fopen(“E:\vs2017\studentinformationsystem\studentInformation.txt”, “r”);
char date;
char checkValue;
//date = fgetc(thisFile);
while ((date = fgetc(thisFile)) != EOF)
{
cout << date;
}
cout << “E返回菜单.” << endl;
cout << “请输入:”;
cin >> checkValue;
while (checkValue != ‘e’ && checkValue != ‘E’)
{
cout << “错误的输入!!!” << endl;
cout << “请重新输入:”;
cin >> checkValue;
}
system(“cls”);
cout << “—>3秒后将返回菜单…”;
Sleep(3000);
trueFunction();
return 0;
}

/删除学生信息/

int studentInformation::deleteStudentInformation() //判断无该学生信息
{
system(“cls”);
char choice;
int n = 0;
int input;
string inputNameOrNumber;
string getStudentInformation;
string studentInformation[100];
string midValue;
ifstream thisFile(“E:\vs2017\studentinformationsystem\studentInformation.txt”);
cout << “<------删除学生信息------->” << endl;
cout << “请输入要删除的学生信息(姓名或者学号):”;
cin >> inputNameOrNumber;
if (thisFile)
{
while (getline(thisFile, getStudentInformation))
{
string::size_type idx;
idx = getStudentInformation.find(inputNameOrNumber);
studentInformation[n] = getStudentInformation;
if (idx!=string::npos)
{
cout << “要删除的学生信息是:” << endl;
cout<< getStudentInformation << endl;
midValue = getStudentInformation;
}
n = n++;
}
}
else
{
cout << “no file.” << endl;
}
cout << “是否确定删除该学生信息(Y/N)?” << endl;
cout << “请选择:”;
cin >> choice;
if (choice == ‘y’ || choice == ‘Y’)
{
/删除/
fstream file(“E:\vs2017\studentinformationsystem\studentInformation.txt”, ios::out);
ofstream fout(“E:\vs2017\studentinformationsystem\studentInformation.txt”);
if (!fout)
{
cout << “删除失败!!!” << endl;
}
else
{
for (int i = 0; i < n; i++)
{
if (studentInformation[i] != midValue)
{
fout << studentInformation[i] << endl;
}
}
cout << “删除成功!!!” << endl;
}
cout << “1:继续删除. 2:返回菜单.” << endl;
cout << “请选择:”;
cin >> input;
if (input == 1)
{
deleteStudentInformation();
}
else if (input == 2)
{
trueFunction();
}
}
else if (choice == ‘n’ || choice == ‘N’)
{
system(“cls”);
cout << “—>3秒后将返回菜单…”;
Sleep(3000);
trueFunction();
}
return 0;
}

/修改学生信息/

int studentInformation::modificationStudentInformation()
{
system(“cls”);
char choice;
int n = 0;
int input;
string inputNameOrNumber;
string getStudentInformation;
string studentInformation[100];
string midValue;
ifstream thisFile(“E:\vs2017\studentinformationsystem\studentInformation.txt”);
cout << “<------修改学生信息------->” << endl;
cout << “请输入要修改的学生信息(姓名或者学号):”;
cin >> inputNameOrNumber;
if (thisFile)
{
while (getline(thisFile, getStudentInformation))
{
string::size_type idx;
idx = getStudentInformation.find(inputNameOrNumber);
studentInformation[n] = getStudentInformation;
if (idx != string::npos)
{
cout << “要修改的学生信息是:” << endl;
cout << getStudentInformation << endl;
midValue = getStudentInformation;
}
n = n++;
}
}
else
{
cout << “no file.” << endl;
}
cout << “是否确定修改该学生信息(Y/N)?” << endl;
cout << “请选择:”;
cin >> choice;
if (choice = ‘y’ || choice == ‘Y’)
{
fstream file(“E:\vs2017\studentinformationsystem\studentInformation.txt”, ios::out);
ofstream fout(“E:\vs2017\studentinformationsystem\studentInformation.txt”);
if (!fout)
{
cout << “修改失败!!!” << endl;
}
else
{
for (int i = 0; i < n; i++)
{
if (studentInformation[i] != midValue)
{
fout << studentInformation[i] << endl;
}
else if (studentInformation[i] == midValue)
{
cout << “请重新输入学生信息:” << endl;
cout << “请输入学号:” << endl;
cin >> thisStudent.studentNumber;
cout << “请输入姓名:” << endl;
cin >> thisStudent.studentName;
cout << “请输入年龄:” << endl;
cin >> thisStudent.studentAge;
cout << “请输入性别:” << endl;
cin >> thisStudent.studentSex;
cout << “请输入数学成绩:” << endl;
cin >> thisStudent.studentScore.math;
cout << “请输入英语成绩:” << endl;
cin >> thisStudent.studentScore.english;
cout << “请输入语文成绩:” << endl;
cin >> thisStudent.studentScore.chinese;
FILE *thisFile;
string midInformation;
thisFile = fopen(“E:\vs2017\studentinformationsystem\midFile.txt”, “a”);
fprintf(thisFile, “%-20s”, thisStudent.studentNumber);
fprintf(thisFile, “%-20s”, thisStudent.studentName);
fprintf(thisFile, “%-20s”, thisStudent.studentSex);
fprintf(thisFile, “%-4d”, thisStudent.studentAge);
fprintf(thisFile, “语文:%-8.1f”, thisStudent.studentScore.chinese);
fprintf(thisFile, “数学:%-8.1f”, thisStudent.studentScore.math);
fprintf(thisFile, “英语:%-8.1f”, thisStudent.studentScore.english);
//fprintf(thisFile, “\n”);
fclose(thisFile);
ifstream midFile(“E:\vs2017\studentinformationsystem\midFile.txt”);
getline(midFile, midInformation);
fstream _file(“E:\vs2017\studentinformationsystem\midFile.txt”, ios::out);//清空midFile文件
fout << midInformation << endl;
}
}
cout << “修改成功!!!” << endl;
}
cout << “1:继续修改 2:返回菜单” << endl;
cout << “请选择:”;
int _input;
cin >> _input;
while (_input != 1 && _input != 2)
{
cout << “输入错误!!!” << endl;
cout << “请重新输入:”;
cin >> _input;
}
if (_input == 1)
{
modificationStudentInformation();
}
else if (_input == 2)
{
trueFunction();
}
}
else if (choice == ‘n’ || choice == ‘N’)
{
trueFunction();
}
return 0;
}

/实现/

int studentInformation::trueFunction()
{
int key;
key = systemMenu();
switch (key) {
case 1:checkUser(key); addStudentInformation(); break;
case 2:checkUser(key); deleteStudentInformation(); break;
case 3:checkUser(key); modificationStudentInformation(); break;
case 4:checkStudentInformation(); break;
}
return 0;
}
int main()
{
studentInformation melody;
melody.trueFunction();
system(“pause”);
return 0;
}
其中修改学生信息处理方法为创建两哥文件夹分别为studentInformation.txt和midFile.tex利用getline获取一个学生的全部信息(getStudentInformation)再利用getStudentInformation.find(name/number)找到需要修改的学生信息将其储存再MidFile.txt文件下,再将读取的每个学生信息存入清空的studentInformation.txt文件中当遇到需要修改的学生再重新输入信息。

  • 7
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
修正了已发现的所有错误.欢迎大家下载试用.. 一、项目名称:学校学生信息管理系统。 二、项目目标:实现对学校学生的信息管理——信息的建立和维护、信息的检索。 三、主要功能: 1.信息的输入:建立学生档案文件。 2.信息维护: 添加:增加新学生; 修改:学生信息的改变; 删除:学生减少。 3.信息处理 按要求检索学生信息; 按要求统计信息。 四、界面系统 1.系统管理员进入 (请输入密码) 2.一级菜单 (1 信息维护 2 信息检索 3 信息统计 4 退出) 3. 二级菜单 信息维护 (1 建立学生成绩文件 2 添加学生记录 3 删除学生记录 4 修改学生记录 5 返回上级菜单) 信息检索 (1 按班级查找 2 返回上级菜单) 信息统计 (1 成绩统计 2 返回上级菜单) 五、主要功能说明: 1.用口令(密码)形式验证管理员身份(可输入三次),合法者可进入,否则程序结束。 2.有关功能说明 1)建立学生成绩表(模块a) 建立新的学生成绩文件; 建立若干学生记录,包括姓名、学号、班级、课程编号、成绩。 2)添加学生记录(模块b) 在已存在的学生成绩文件中添加新记录。 3)删除学生记录(模块c) 在学生成绩文件中删除有三门课程不及格的学生记录; 删除前,逐条显示符合删除条件的学生姓名、成绩,确认后再删除。 4)修改学生信息(模块d) 输入学生学号,在学生成绩文件中找出该学生记录; 在屏幕上逐条显示该学生的各条记录; 每显示一条,询问是否修改,如果“Y”,输入修改后数据, 将文件原记录删除,保存新的记录; 5)按姓名和班级查找(模块e) 输入姓名显示相应信息。 6)信息统计(模块f) 同时按照班级和课程统计每门课程、每个班级的平均成绩,最高分、最低分; 在屏幕上先依次显示各门课程,对应的各个班级的统计数据。 7)退出信息管理系统,返回操作系统。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值