当前位置: 移动技术网 > IT编程>开发语言>C/C++ > 学生选题信息管理系统

学生选题信息管理系统

2018年11月20日  | 移动技术网IT编程  | 我要评论

2018国考公务员职位表,监工艾米,海洋工程装备制造业中长期发展规划

//
//本人大一写东忙西忙写的,感觉很一般,巩固基础麻,没有别的大神写的那么酷炫,但是还是基本任务完成了。
//需先建立student.txt文件


#include<fstream> #include<cstring> #include<stdio.h> #include<iostream> #include<stdlib.h> using namespace std; #define ok 1 #define error 0 #define overflow -1 #define list_init_space 100 //存储空间初始分配量 #define list_inc_space 10 //存储空间分配增量 int node = 1; typedef struct student { int age; //年龄 int student_id; //学号 int course_id; //题目编号 char student_name[40]; //姓名 char sex[10]; //性别 char class[40]; //班级 char specialty[40]; //专业 char course_name[40]; //题目名称 char keyword[40]; //关键词 char technology[40]; }student; typedef struct stent_list { struct student *stu; //存储空间基址 int length; //当前长度 int listsize; //当前分配的存储容量(以sizeof(student)为单位 }stent_list; int stent_listinit(stent_list &s) { //在内存中分配空间 s.stu = (student*)malloc(list_inc_space*sizeof(student)); if(!s.stu) exit(overflow); //存储空间分配失败 //构造一个空的线性表 s.length = 0; s.listsize = list_inc_space; //初始存储容量 return ok; }//函数stent_listinit结束 void write(stent_list &s, int n) { fstream myfile; myfile.open("student.txt",ios::out|ios::binary); //fstream myfile("student.txt",ios::out|ios::binary); if(! myfile) { cout<<"该文件不能打开!"<<endl; abort(); //异常终止函数 } int count = n; myfile<<count<<endl<<endl; for(int i = 0; i <= count; i++) { myfile<<(s.stu[i]).student_id<<" "<<(s.stu[i]).student_name<<" "<<(s.stu[i]).sex<<" "<<(s.stu[i]).age<<" "<<(s.stu[i]).class<<" "<<(s.stu[i]).specialty<<" "<<s.stu[i].course_id<<" "<<s.stu[i].course_name<<" "<<s.stu[i].keyword<<" "<<s.stu[i].technology<<" "<<endl; } myfile.close(); } /**************************************/ //函数名: read(stent_list &s) //参数: (传入) stent_list s顺序表 //返回值: int型,返回1表示创建成功,0表示失败 //功能: 读取顺序表中的内容 /*************************************/ int read(stent_list &s) { fstream myfile; myfile.open("student.txt",ios::in|ios::binary); //fstream myfile("student.txt",ios::out|ios::binary); if(! myfile) { cout<<"该文件不能打开"<<endl; abort(); } int count; myfile.seekg(0); myfile>>count; for(int i = 0; i <= count; i++) { myfile>>s.stu[i].student_id>>s.stu[i].student_name>>s.stu[i].sex>>s.stu[i].age>>s.stu[i].class>>s.stu[i].specialty>>s.stu[i].course_id>>s.stu[i].course_name>>s.stu[i].keyword>>s.stu[i].technology; } myfile.close(); return count; } /*****************************************/ //函数名:add(stent_list &s) //参数: (传入)stent_list s,顺序表 //返回值: 空 //功能: 添加学生信息 /*****************************************/ void add(stent_list &s) { int n = read(s); int i = 0; char sign = 'f'; cout<<endl<<"请输入增加的学生的相关信息:"<<endl; while(sign != 'n') { loop: cout<<"学号:"; cin>>s.stu[i].student_id; cout<<endl; int c = 0; while(c < i) { c++; if(s.stu[i].student_id == s.stu[i-c].student_id) { cout<<"你输入的学号已经存在!请重新输入" <<endl; goto loop; } } cout<<"姓名:"; cin>>s.stu[i].student_name; cout<<endl; cout<<"性别:"; cin>>s.stu[i].sex; cout<<endl; cout<<"年龄:"; cin>>s.stu[i].age; cout<<endl; cout<<"班级:"; cin>>s.stu[i].class; cout<<endl; cout<<"专业:"; cin>>s.stu[i].specialty; cout<<endl; cout<<"题目编号:"; cin>>s.stu[i].course_id; cout<<endl; cout<<"题目名称:"; cin>>s.stu[i].course_name; cout<<endl; cout<<"关键词:"; cin>>s.stu[i].keyword; cout<<endl; cout<<"实现技术:"; cin>>s.stu[i].technology; cout<<endl; cout<<"提示:是否继续写入学生信息?(y/n):"; cin>>sign; i++; } write(s, i); } /*****************************************************/ //函数名: search_student_id(stent_list &s) //参数: (传入)stent_list s,顺序表 //返回值: 空 //功能: 根据学号查找学生信息 /*****************************************************/ void search_student_id(stent_list &s) { int n = read(s); int s; int i = 0; cout<<endl<<"查找学生信息:"<<endl; cout<<"请输入需要查找学生的学号:"<<endl; cin>>s; while((s.stu[i].student_id - s) != 0 && i < n) i++; if(i == n) { cout<<"提示: 对不起,无法找到该学生的信息! "<<endl; } else { cout<<"***************************"<<endl; cout<<"学号:"<<s.stu[i].student_id<<endl; cout<<"姓名:"<<s.stu[i].student_name<<endl; cout<<"性别: "<<s.stu[i].sex<<endl; cout<<"年龄:"<<s.stu[i].age<<endl; cout<<"班级:"<<s.stu[i].class<<endl; cout<<"专业:"<<s.stu[i].specialty<<endl; cout<<"题目编号:"<<s.stu[i].course_id<<endl; cout<<"题目名称:"<<s.stu[i].course_name<<endl; cout<<"关键词:"<<s.stu[i].keyword<<endl; cout<<"实现技术:"<<s.stu[i].technology<<endl; } } /*******************************************************/ //函数名: search_student_name(stent_list &s) //参数: (传入)stent_list s,顺序表 //返回值: 空 //功能: 根据学生姓名查找学生信息 /*******************************************************/ void search_student_name(stent_list &s) { int n = read(s); char a[100]; cout<<"请输入需要查找的姓名:"<<endl; cin>>a; for(int i = 0; i < n; i++) if(strcmp(s.stu[i].student_name, a) == 0) { cout<<"****************************"<<endl; cout<<"学号:"<<s.stu[i].student_id<<endl; cout<<"姓名:"<<s.stu[i].student_name<<endl; cout<<"性别: "<<s.stu[i].sex<<endl; cout<<"年龄:"<<s.stu[i].age<<endl; cout<<"班级:"<<s.stu[i].class<<endl; cout<<"专业:"<<s.stu[i].specialty<<endl; cout<<"题目编号:"<<s.stu[i].course_id<<endl; cout<<"题目名称:"<<s.stu[i].course_name<<endl; cout<<"关键词:"<<s.stu[i].keyword<<endl; cout<<"实现技术:"<<s.stu[i].technology<<endl; } } /*******************************************************/ //函数名: search_course_id(stent_list &s) //参数: (传入)stent_list s,顺序表 //返回值: 空 //功能: 根据学生课程设计的编号查找 /*******************************************************/ void search_course_id(stent_list &s) { int n = read(s); int b; int i = 0; cout<<"请输入需要查找的题目编号:"<<endl; cin>>b; while((s.stu[i].course_id - b) != 0 && i < n) i++; if(i == n) { cout<<"提示:对不起,无法找到该信息!"<<endl; } else { for(i = 0; i < n; i++) if(s.stu[i].course_id - b == 0) { cout<<"******************************"<<endl; cout<<"学号:"<<s.stu[i].student_id<<endl; cout<<"姓名:"<<s.stu[i].student_name<<endl; cout<<"性别: "<<s.stu[i].sex<<endl; cout<<"年龄:"<<s.stu[i].age<<endl; cout<<"班级:"<<s.stu[i].class<<endl; cout<<"专业:"<<s.stu[i].specialty<<endl; cout<<"题目编号:"<<s.stu[i].course_id<<endl; cout<<"题目名称:"<<s.stu[i].course_name<<endl; cout<<"关键词:"<<s.stu[i].keyword<<endl; cout<<"实现技术:"<<s.stu[i].technology<<endl; } } } /****************************************************/ //函数名: search_course_name(stent_list &s) //参数: (传入)stent_list s,顺序表 //返回值: 空 //功能: 根据课程设计名称查找 /***************************************************/ void search_course_name(stent_list &s) { int n = read(s); char c[100]; cout<<"请输入需要查找的题目名称:"<<endl; cin>>c; for(int i = 0; i < n; i++) if(strcmp(s.stu[i].course_name, c) == 0) { cout<<"******************************"<<endl; cout<<"学号:"<<s.stu[i].student_id<<endl; cout<<"姓名:"<<s.stu[i].student_name<<endl; cout<<"性别: "<<s.stu[i].sex<<endl; cout<<"年龄:"<<s.stu[i].age<<endl; cout<<"班级:"<<s.stu[i].class<<endl; cout<<"专业:"<<s.stu[i].specialty<<endl; cout<<"题目编号:"<<s.stu[i].course_id<<endl; cout<<"题目名称:"<<s.stu[i].course_name<<endl; cout<<"关键词:"<<s.stu[i].keyword<<endl; cout<<"实现技术:"<<s.stu[i].technology<<endl; } } /******************************************************/ //函数名: search(stent_list &s) //参数: (传入)stent_list s,顺序表 //返回值: 空 //功能: 选择查找关键词 /******************************************************/ void search(stent_list &s) { int n = read(s); cout<<"**(1)根据学号查询 **"<<endl; cout<<"**(2)根据姓名查询 **"<<endl; cout<<"**(3)根据编号查询 **"<<endl; cout<<"**(4)根据名称查询 **"<<endl; cout<<endl; int c; cout<<"请输入选择: "; cin>>c; switch(c) { case 1: search_student_id(s);break; case 2: search_student_name(s);break; case 3: search_course_id(s);break; case 4: search_course_name(s);break; default: cout<<"输入错误,请重新输入!"<<endl; } write(s, n); } /*******************************************/ //函数名: student_alter(stent_list &s) //参数: (传入)stent_list s,顺序表 //返回值: 空 //功能: 修改学生信息 /******************************************/ void student_alter(stent_list &s) { int n = read(s); int s; int i = 0; cout<<endl<<"修改学生信息:"<<endl; cout<<"请输入需要修改学生的学号:"<<endl; cin>>s; while((s.stu[i].student_id - s) != 0 && i < n) i++; if(i == n) { cout<<"提示:对不起,无该学生的信息!!!"<<endl; } else { cout<<"该学生的信息:"<<endl; cout<<"学号:"<<s.stu[i].student_id<<endl; cout<<"姓名:"<<s.stu[i].student_name<<endl; cout<<"性别: "<<s.stu[i].sex<<endl; cout<<"年龄:"<<s.stu[i].age<<endl; cout<<"班级:"<<s.stu[i].class<<endl; cout<<"专业:"<<s.stu[i].specialty<<endl; cout<<"题目编号:"<<s.stu[i].course_id<<endl; cout<<"题目名称:"<<s.stu[i].course_name<<endl; cout<<"关键词:"<<s.stu[i].keyword<<endl; cout<<"实现技术:"<<s.stu[i].technology<<endl; cout<<"请重新输入该学生的信息"<<endl; cout<<"学号:"; cin>>s.stu[i].student_id; cout<<endl; cout<<"姓名:"; cin>>s.stu[i].student_name; cout<<endl; cout<<"性别:"; cin>>s.stu[i].sex; cout<<endl; cout<<"年龄:"; cin>>s.stu[i].age; cout<<endl; cout<<"班级:"; cin>>s.stu[i].class; cout<<endl; cout<<"专业:"; cin>>s.stu[i].specialty; cout<<endl; cout<<"题目编号:"; cin>>s.stu[i].course_id; cout<<endl; cout<<"题目名称:"; cin>>s.stu[i].course_name; cout<<endl; cout<<"关键词:"; cin>>s.stu[i].keyword; cout<<endl; cout<<"实现技术:"; cin>>s.stu[i].technology; cout<<endl; char c; cout<<"是否保存数据?(y/n)"<<endl; cin>>c; if(c == 'y') cout<<"修改成功!"<<endl; write(s, n); } } /**************************************/ //函数名: student_delete(stent_list &s) //参数: (传入)stent_list s,顺序表 //返回值: 空 //功能: 删除学生信息 /*************************************/ void student_delete(stent_list &s) { int n = read(s); int s; int i = 0, j; cout<<endl<<"删除学生信息:"<<endl; cout<<"请输入需要删除学生的学号:"<<endl; cin>>s; while((s.stu[i].student_id - s) != 0 && i < n) i++; if(i == n) { cout<<"提示:记录为空!!!"<<endl; } else { cout<<"提示:已成功删除!"<<endl; cout<<"你要删除的信息如下:"<<endl; cout<<"学号:"<<s.stu[i].student_id<<endl; cout<<"姓名:"<<s.stu[i].student_name<<endl; cout<<"性别: "<<s.stu[i].sex<<endl; cout<<"年龄:"<<s.stu[i].age<<endl; cout<<"班级:"<<s.stu[i].class<<endl; cout<<"专业:"<<s.stu[i].specialty<<endl; cout<<"题目编号:"<<s.stu[i].course_id<<endl; cout<<"题目名称:"<<s.stu[i].course_name<<endl; cout<<"关键词:"<<s.stu[i].keyword<<endl; cout<<"实现技术:"<<s.stu[i].technology<<endl; for(j = i; j < n-1; j++) { s.stu[j].student_id = s.stu[j+1].student_id; strcpy(s.stu[j].student_name,s.stu[j+1].student_name); strcpy(s.stu[j].sex,s.stu[j+1].sex); s.stu[j].age = s.stu[j+1].age; strcpy(s.stu[j].class,s.stu[j+1].class); strcpy(s.stu[j].specialty,s.stu[j+1].specialty); s.stu[j].course_id = s.stu[j+1].course_id; strcpy(s.stu[j].course_name,s.stu[j+1].course_name); strcpy(s.stu[j].keyword,s.stu[j+1].keyword); strcpy(s.stu[j].technology,s.stu[j+1].technology); } } write(s, n-1); } /******************************************/ //函数名: total(stent_list &s) //参数: (传入)stent_list s,顺序表 //返回值: 空 //功能: 统计学生信息 /*****************************************/ void total(stent_list &s) { int n = read(s); char c[100]; int ok = 0; cout<<"请输入需要查找的题目名称:"<<endl; cin>>c; for(int i = 0; i < n; i++) if(strcmp(s.stu[i].course_name, c) == 0) { cout<<"你要统计的信息如下:"<<endl; cout<<"学号:"<<s.stu[i].student_id<<endl; cout<<"姓名:"<<s.stu[i].student_name<<endl; cout<<"性别: "<<s.stu[i].sex<<endl; cout<<"年龄:"<<s.stu[i].age<<endl; cout<<"班级:"<<s.stu[i].class<<endl; cout<<"专业:"<<s.stu[i].specialty<<endl; cout<<"题目编号:"<<s.stu[i].course_id<<endl; cout<<"题目名称:"<<s.stu[i].course_name<<endl; cout<<"关键词:"<<s.stu[i].keyword<<endl; cout<<"实现技术:"<<s.stu[i].technology<<endl; ok = 1; } if(ok == 0) { cout<<"没有此条记录!"<<endl; } } /********************************************/ //函数名: display(stent_list &s) //参数: (传入)stent_list s,顺序表 //返回值: 空 //功能: 输出所有学生的全部信息 /********************************************/ void display(stent_list &s) { int n = read(s); cout<<endl<<"显示全部学生信息:"<<endl; if(! s.stu) { cout<<"没有记录"<<endl; } else { for(int i = 0; i < n; i++) { cout<<"学号:"<<s.stu[i].student_id<<endl; cout<<"姓名:"<<s.stu[i].student_name<<endl; cout<<"性别: "<<s.stu[i].sex<<endl; cout<<"年龄:"<<s.stu[i].age<<endl; cout<<"班级:"<<s.stu[i].class<<endl; cout<<"专业:"<<s.stu[i].specialty<<endl; cout<<"题目编号:"<<s.stu[i].course_id<<endl; cout<<"题目名称:"<<s.stu[i].course_name<<endl; cout<<"关键词:"<<s.stu[i].keyword<<endl; cout<<"实现技术:"<<s.stu[i].technology<<endl; } } } int main() { char choice; cout<<endl<<endl<<"\t\t\t"<<" **欢迎使用课程设计选题管理系统**" <<endl<<endl; cout<<"\t\t\t"<<"1.*********添加新的记录**********"<<endl; cout<<"\t\t\t"<<"2.*********查询记录信息**********"<<endl; cout<<"\t\t\t"<<"3.*********修改学生信息**********"<<endl; cout<<"\t\t\t"<<"4.*********删除学生信息**********"<<endl; cout<<"\t\t\t"<<"5.*********统计所有记录**********"<<endl; cout<<"\t\t\t"<<"6.*********显示所有记录**********"<<endl; cout<<"\t\t\t"<<"0.********* 退出系统 **********"<<endl; stent_list s; stent_listinit(s); cout<<"\t\t\t"<<"请输入您的选择:"; cin>>choice; if(choice == '0') { cout<<endl<<"\t"<<"\t"<<"\t"<<"谢谢使用本系统! "<<endl<<endl; exit(0); } else if(choice == '1') { add(s); system("pause"); main(); } else if(choice == '2') { search(s); system("pause"); main(); } else if(choice == '3') { student_alter(s); system("pause"); main(); } else if(choice == '4') { student_delete(s); system("pause"); main(); } else if(choice == '5') { total(s); system("pause"); main(); } else if(choice == '6') { display(s); system("pause"); main(); } else { cout<<"\t"<<"输入错误,请重新输入你的选择:"; main(); } return 0; }

  

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网