学生信息管理系统包括了输入、查询、修改、删除等操作。
代码:
#define MAX 1000//最大存储人数 //个人信息 typedef struct Student { char num[10];//编号 char name[15];//姓名 int chinese;//语文 int english;//英语 int math;//数学 int physical;//物理 int chemical;//化学 int biology;//生物 int Lgrade;//平时成绩 int Fgrade;//期末成绩 float ave;//总评成绩 }Stu; typedef struct GradeManage { Stu stu[MAX ]; int count; }Tele, * ptele; void initiate(ptele ptele);//启动 void Add(ptele ptele);//输入学生人数,最多输入1000个 void Search(ptele ptxl);//查找学生人数,按姓名查找 void Display(ptele ptxl);//显示学生通讯录中所有人 void Modify(ptele ptele);//修改学生某一人的信息 void Delete(ptele ptxl);//删除某一人的信息 void Save(ptele ptxl);//保存学生信息到文件中 void menu();//菜单 void initiate(ptele ptele) { ptele->count = 0; } static int hanshu(ptele ptele, const char * name) { int i = 0; for (i = 0; i < ptele ->count; i++) { if (strcmp(name , ptele->stu[i].name) == 0) { return i; } } return -1; } void Add(ptele ptele) { if (ptele ->count == MAX) { printf( "录入学生已满!\n" ); return; } cout<< "学号:"; cin>> ptele->stu[ptele ->count].num; cout << "姓名:"; cin>> ptele->stu[ptele ->count].name; cout << "语文:"; cin >> ptele->stu[ptele ->count].chinese; cout << "英语:"; cin >> ptele->stu[ptele ->count].english; cout << "数学:"; cin >> ptele->stu[ptele ->count].math; cout << "物理:"; cin >> ptele->stu[ptele ->count].physical; cout << "化学:"; cin >> ptele->stu[ptele ->count].chemical; cout << "生物:"; cin >> ptele->stu[ptele ->count].biology; cout << "平时成绩:" ; cin >> ptele->stu[ptele ->count].Lgrade; cout << "期末成绩:" ; cin >> ptele->stu[ptele ->count].Fgrade; ptele->stu[ptele ->count].ave = (ptele->stu[ptele ->count].Lgrade*0.3) + (ptele->stu[ptele ->count].Fgrade*0.7); ptele->count++; printf( "录入成功!\n" ); } void Search(ptele ptxl) { int ret = 0; char name[10]; cout<< "请输入要查询学生的姓名:" ; cin>>name; ret = hanshu( ptxl, name); if (ret == -1) { cout << "没有要找的人!" << endl; return; } else { ptxl->stu[ptxl ->count].ave = (ptxl->stu[ptxl ->count].Lgrade*0.3) + (ptxl->stu[ptxl ->count].Fgrade*0.7); cout << "学号\t姓名 语文 英语 数学 物理 化学 生物 平时成绩 期末成绩 总评成绩" << endl; cout << ptxl->stu[ret].num << " " << ptxl->stu[ret].name << " " << ptxl->stu[ret].chinese << " " << ptxl ->stu[ret].english << " " << ptxl->stu[ret].math << " " << ptxl->stu[ret].physical << " " << ptxl ->stu[ret].chemical << " " << ptxl->stu[ret].biology << " " << ptxl->stu[ret].Lgrade << " " << ptxl->stu[ret].Fgrade << " " << ptxl->stu[ret].ave <<endl; } } void Modify(ptele ptele) { int ret = 0; char name[10]; cout<< "请输入要修改人的姓名:" ; cin>>name; ret = hanshu( ptele, name); if (ret == -1) { cout << "不存在要修改的人!" << endl; return; } else { cout << "学号:"; cin >> ptele->stu[ret].num; cout << "姓名:"; cin >> ptele->stu[ret].name; cout << "语文:"; cin >> ptele->stu[ret].chinese; cout << "英语:"; cin >> ptele->stu[ret].english; cout << "数学:"; cin >> ptele->stu[ret].math; cout << "物理:"; cin >> ptele->stu[ret].physical; cout << "化学:"; cin >> ptele->stu[ret].chemical; cout << "生物:"; cin >> ptele->stu[ret].biology; cout << "平时成绩:" ; cin >> ptele->stu[ret].Lgrade; cout << "期末成绩:" ; cin >> ptele->stu[ret].Fgrade; } ptele->stu[ptele ->count].ave = (ptele->stu[ptele ->count].Lgrade*0.3) + (ptele->stu[ptele ->count].Fgrade*0.7); cout << "修改成功!" << endl; } void Delete(ptele ptxl) { int ret = 0; int j = 0; char name[10]; cout << "请输入要删除学生的姓名:" << endl; cin>>name; ret = hanshu( ptxl, name); if (ret == -1) { cout << "没有要删除的学生!" << endl; return; } else { for (j = ret; j < ptxl ->count - 1; j++) { ptxl->stu[j] = ptxl ->stu[j + 1]; } } ptxl->count--; cout << "删除学生成功!" << endl; } void Save(ptele ptxl) { FILE* fp; int i = 0; if ((fp = fopen("manage.txt" , "ab+")) == NULL) { cout << "不能打开" << endl;; exit( EXIT_SUCCESS); } fprintf(fp, "学号\t姓名 语文 英语 数学 物理 化学 生物 平时成绩 期末成绩 总评成绩" ); fprintf(fp, "\r\n"); for (i = 0; i < ptxl ->count; i++) { fprintf(fp, "%2s %s %d %d %d %d %d %d %d %d %f\n", ptxl->stu[i].num, ptxl ->stu[i].name, ptxl->stu[i].chinese, ptxl ->stu[i].english, ptxl->stu[i].math, ptxl ->stu[i].physical, ptxl->stu[i].chemical, ptxl ->stu[i].biology, ptxl->stu[i].Lgrade, ptxl ->stu[i].Fgrade, ptxl->stu[i].ave); fprintf(fp, "\r\n"); } fclose(fp); cout << "保存到文件中成功!" << endl; } void Display(ptele ptxl) { int i = 0; cout << "学号\t姓名 语文 英语 数学 物理 化学 生物 平时成绩 期末成绩 总评成绩" << endl; for (i = 0; i < ptxl ->count; i++) { cout << ptxl->stu[i].num << " " << ptxl->stu[i].name << " " << ptxl->stu[i].chinese << " " << ptxl ->stu[i].english << " " << ptxl->stu[i].math << " " << ptxl->stu[i].physical << " " << ptxl ->stu[i].chemical << " " << ptxl->stu[i].biology << " " << ptxl->stu[i].Lgrade << " " << ptxl->stu[i].Fgrade << " " << ptxl->stu[i].ave << endl; } } void menu() { cout << "*******************************************************" << endl; cout << "* 学生成绩管理系统 " << endl; cout << "*******************************************************" << endl; cout << "设计人:高铎 班级:信息143 学号:201412030305" << endl; cout << "*******************************************************" << endl; cout << "* 1 录入学生信息 " << endl; cout << "* 2 显示学生信息 " << endl; cout << "* 3 查询学生信息 " << endl; cout << "* 4 修改学生信息 " << endl; cout << "* 5 删除学生信息 " << endl; cout << "* 6 保存学生信息 " << endl; cout << "* 0 退出 " << endl; cout << "*******************************************************" << endl; } #define _CRT_SECURE_NO_WARNINGS 1 #include<iostream> using namespace std; #include "Studdent.h" int main() { Tele ptele; int input = 1; initiate(&ptele); system( "color a"); while (input) { menu(); cout << "\t\t请选择自己的操作<0~5>:" ; cin >> input; switch (input) { case 1:Add(&ptele); break; case 2:Display(&ptele); break; case 3:Search(&ptele); break; case 4:Modify(&ptele); break; case 5:Delete(&ptele); break; case 6:Save(&ptele); break; case 0:exit(EXIT_SUCCESS ); break; } } return 0; }
原文地址:http://mnt3918290.blog.51cto.com/10729316/1827047