|
|
|
@ -0,0 +1,274 @@
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <windows.h>
|
|
|
|
|
#include <time.h>
|
|
|
|
|
#include <conio.h>
|
|
|
|
|
//#include <unistd.h>
|
|
|
|
|
#include "head.h"
|
|
|
|
|
|
|
|
|
|
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
|
|
|
|
|
|
|
|
|
|
int num=0;//当前数组中存储的数据量
|
|
|
|
|
struct node{
|
|
|
|
|
char stnum[20];
|
|
|
|
|
char stname[20];
|
|
|
|
|
char sex[8];
|
|
|
|
|
int age;
|
|
|
|
|
char detail[100];
|
|
|
|
|
}student[1000];
|
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
|
|
|
|
|
|
//if(!login())return 0;
|
|
|
|
|
menus();
|
|
|
|
|
char choice;
|
|
|
|
|
while(1){
|
|
|
|
|
printf("请输入正确选项!\n");
|
|
|
|
|
choice=getch();
|
|
|
|
|
system("cls");
|
|
|
|
|
switch(choice){
|
|
|
|
|
case '1':
|
|
|
|
|
input();
|
|
|
|
|
end();
|
|
|
|
|
break;
|
|
|
|
|
case '2':
|
|
|
|
|
display();
|
|
|
|
|
break;
|
|
|
|
|
case '3':
|
|
|
|
|
printf("\a保存后将退出系统\n是否继续?\n继续则输入'Y'\n按其他任意键取消\n");
|
|
|
|
|
char ch;
|
|
|
|
|
ch=getch();
|
|
|
|
|
if(ch=='Y'){
|
|
|
|
|
save();
|
|
|
|
|
out();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case '4':
|
|
|
|
|
if(my_delete()!=1){
|
|
|
|
|
out();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case '5':
|
|
|
|
|
if(alter()!=1){
|
|
|
|
|
out();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
system("cls");
|
|
|
|
|
end();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
system("cls");
|
|
|
|
|
menus();
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void out()
|
|
|
|
|
{
|
|
|
|
|
system("cls");
|
|
|
|
|
printf("本次使用到此结束!\n即将退出程序!\n");
|
|
|
|
|
for(int i=3;i>0;i--){
|
|
|
|
|
printf("%d秒后退出程序!\n",i);
|
|
|
|
|
Sleep(1000);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void menus()
|
|
|
|
|
{
|
|
|
|
|
printf("\t\t\t\t**********请选择系统功能选项**************\n");
|
|
|
|
|
printf("\t\t\t\t*--------1 学生基本信息录入--------------*\n");
|
|
|
|
|
printf("\t\t\t\t*--------2 学生基本信息显示--------------*\n");
|
|
|
|
|
printf("\t\t\t\t*--------3 学生基本信息保存--------------*\n");
|
|
|
|
|
printf("\t\t\t\t*---4 学生基本信息删除(此选项须输入密码)-*\n");
|
|
|
|
|
printf("\t\t\t\t*---5 学生基本信息修改(此选项须输入密码)-*\n");
|
|
|
|
|
printf("\t\t\t\t******************************************\n\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void input()
|
|
|
|
|
{
|
|
|
|
|
int n=0;
|
|
|
|
|
char c='0';
|
|
|
|
|
int falg=1;
|
|
|
|
|
printf("请输入你要录入的学生信息数:\n");
|
|
|
|
|
do{
|
|
|
|
|
c=getch();
|
|
|
|
|
if(c>'9'||c<'0'){
|
|
|
|
|
printf("数值非法!!!\n请重新输入!\n");
|
|
|
|
|
}
|
|
|
|
|
}while(c>'9'||c<'0');
|
|
|
|
|
n=c-'0';
|
|
|
|
|
printf("你选择录入%d名学生!\n",n);
|
|
|
|
|
if(num+n+1>=1000){
|
|
|
|
|
printf("本次录入只能录入%d名学生!\n",1000-num-1);
|
|
|
|
|
falg=0;
|
|
|
|
|
}
|
|
|
|
|
for(int i=num;i<n+num;i++){
|
|
|
|
|
if(i==num)printf("请输入学生基本信息!\n");
|
|
|
|
|
if(!falg){
|
|
|
|
|
printf("您还可以录入%d名学生!",1000-i-1);
|
|
|
|
|
scanf("%s %s %s %d %s",&student[i].stnum,&student[i].stname,&student[i].sex,&student[i].age,&student[i].detail);
|
|
|
|
|
}else{
|
|
|
|
|
scanf("%s %s %s %d %s",&student[i].stnum,&student[i].stname,&student[i].sex,&student[i].age,&student[i].detail);
|
|
|
|
|
}
|
|
|
|
|
if(i!=n+num-1)printf("请输入下一名学生基本信息!\n");
|
|
|
|
|
}
|
|
|
|
|
if(!falg)num=1000;
|
|
|
|
|
else num+=n;
|
|
|
|
|
printf("录入成功!\a\n");
|
|
|
|
|
Sleep(1000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void display()
|
|
|
|
|
{
|
|
|
|
|
struct node tem[1000];
|
|
|
|
|
int i=0;
|
|
|
|
|
printf("已保存的名学生基本信息:\n");
|
|
|
|
|
FILE *fp=fopen("data.txt","r");
|
|
|
|
|
while(fscanf(fp,"%s%s%s%d%s",tem[i].stnum,tem[i].stname,tem[i].sex,&tem[i].age,tem[i].detail)!=EOF){
|
|
|
|
|
printf("学号:%-12s姓名:%-8s\t性别:%-4s\t年龄:%-4d\t备注:%-4s\n",tem[i].stnum,tem[i].stname,tem[i].sex,tem[i].age,tem[i].detail);
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
fclose(fp);
|
|
|
|
|
end();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void save()
|
|
|
|
|
{
|
|
|
|
|
FILE *fp;
|
|
|
|
|
fp=fopen("data.txt","a+");
|
|
|
|
|
if(fp==NULL){
|
|
|
|
|
printf("文件打开失败!\n即将返回菜单\n");
|
|
|
|
|
return ;
|
|
|
|
|
}
|
|
|
|
|
for(int i=0;i<num;i++){
|
|
|
|
|
fprintf(fp,"%s\t%s\t%s\t%d\t%s\n",student[i].stnum,student[i].stname,student[i].sex,student[i].age,student[i].detail);
|
|
|
|
|
}
|
|
|
|
|
printf("已录入%d名学生基本信息!\a\n",num);
|
|
|
|
|
Sleep(1000);
|
|
|
|
|
int c=fclose(fp);
|
|
|
|
|
if(c!=0){
|
|
|
|
|
printf("文件打开失败!\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int my_delete()
|
|
|
|
|
{
|
|
|
|
|
display();
|
|
|
|
|
if(password()==0)return 0;
|
|
|
|
|
struct node tem[1000];
|
|
|
|
|
FILE *fp=fopen("data.txt","r");
|
|
|
|
|
FILE *out=fopen("data2.txt","w");
|
|
|
|
|
int i=0;
|
|
|
|
|
char s[20];
|
|
|
|
|
printf("仅支持按学号删除!!\n");
|
|
|
|
|
printf("请输入您所要删除的信息的相关学号:");
|
|
|
|
|
scanf("%s",s);
|
|
|
|
|
while(fscanf(fp,"%s%s%s%d%s",tem[i].stnum,tem[i].stname,tem[i].sex,&tem[i].age,tem[i].detail)!=EOF){
|
|
|
|
|
if(strcmp(s,tem[i].stnum)!=0)fprintf(out,"%s\t%s\t%s\t%d\t%s\n",tem[i].stnum,tem[i].stname,tem[i].sex,tem[i].age,tem[i].detail);
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
fclose(fp);
|
|
|
|
|
fclose(out);
|
|
|
|
|
unlink("data.txt");
|
|
|
|
|
rename("data2.txt","data.txt");
|
|
|
|
|
printf("删除完成!\a");
|
|
|
|
|
Sleep(500);
|
|
|
|
|
system("cls");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int alter()
|
|
|
|
|
{
|
|
|
|
|
display();
|
|
|
|
|
if(password()==0)return 0;
|
|
|
|
|
struct node tem[1000];
|
|
|
|
|
FILE *fp;
|
|
|
|
|
fp=fopen("data.txt","r");
|
|
|
|
|
FILE *ou;
|
|
|
|
|
ou=fopen("data2.txt","w");
|
|
|
|
|
int i=0;
|
|
|
|
|
char s[20];
|
|
|
|
|
char t[20];
|
|
|
|
|
int d;
|
|
|
|
|
printf("仅支持按学号修改!!\n");
|
|
|
|
|
printf("请输入您所要删除的信息的相关学号:");
|
|
|
|
|
scanf("%s",s);
|
|
|
|
|
system("cls");
|
|
|
|
|
_menus2();
|
|
|
|
|
printf("请选择你的选项!\n");
|
|
|
|
|
char cho;
|
|
|
|
|
cho=getch();
|
|
|
|
|
printf("\n请输入数据:");
|
|
|
|
|
switch (cho){
|
|
|
|
|
case '1':
|
|
|
|
|
scanf("%s",t);
|
|
|
|
|
while(fscanf(fp,"%s%s%s%d%s",tem[i].stnum,tem[i].stname,tem[i].sex,&tem[i].age,tem[i].detail)!=EOF){
|
|
|
|
|
if(strcmp(s,tem[i].stnum)==0)
|
|
|
|
|
{
|
|
|
|
|
fprintf(ou,"%s\t%s\t%s\t%d\t%s\n",t,tem[i].stname,tem[i].sex,tem[i].age,tem[i].detail);
|
|
|
|
|
printf("学号:%-12s姓名:%-8s\t性别:%-4s\t年龄:%-4d\t备注:%-4s\n",t,tem[i].stname,tem[i].sex,tem[i].age,tem[i].detail);
|
|
|
|
|
}
|
|
|
|
|
else fprintf(ou,"%s\t%s\t%s\t%d\t%s\n",tem[i].stnum,tem[i].stname,tem[i].sex,tem[i].age,tem[i].detail);
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case '2':
|
|
|
|
|
scanf("%s",t);
|
|
|
|
|
while(fscanf(fp,"%s%s%s%d%s",tem[i].stnum,tem[i].stname,tem[i].sex,&tem[i].age,tem[i].detail)!=EOF){
|
|
|
|
|
if(strcmp(s,tem[i].stnum)==0)
|
|
|
|
|
{
|
|
|
|
|
fprintf(ou,"%s\t%s\t%s\t%d\t%s\n",tem[i].stnum,t,tem[i].sex,tem[i].age,tem[i].detail);
|
|
|
|
|
printf("学号:%-12s姓名:%-8s\t性别:%-4s\t年龄:%-4d\t备注:%-4s\n",tem[i].stnum,t,tem[i].sex,tem[i].age,tem[i].detail);
|
|
|
|
|
}
|
|
|
|
|
else fprintf(ou,"%s\t%s\t%s\t%d\t%s\n",tem[i].stnum,tem[i].stname,tem[i].sex,tem[i].age,tem[i].detail);
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case '3':
|
|
|
|
|
scanf("%s",t);
|
|
|
|
|
while(fscanf(fp,"%s%s%s%d%s",tem[i].stnum,tem[i].stname,tem[i].sex,&tem[i].age,tem[i].detail)!=EOF){
|
|
|
|
|
if(strcmp(s,tem[i].stnum)==0)
|
|
|
|
|
{
|
|
|
|
|
fprintf(ou,"%s\t%s\t%s\t%d\t%s\n",tem[i].stnum,tem[i].stname,t,tem[i].age,tem[i].detail);
|
|
|
|
|
printf("学号:%-12s姓名:%-8s\t性别:%-4s\t年龄:%-4d\t备注:%-4s\n",tem[i].stnum,tem[i].stname,t,tem[i].age,tem[i].detail);
|
|
|
|
|
}
|
|
|
|
|
else fprintf(ou,"%s\t%s\t%s\t%d\t%s\n",tem[i].stnum,tem[i].stname,tem[i].sex,tem[i].age,tem[i].detail);
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case '4':
|
|
|
|
|
scanf("%d",&d);
|
|
|
|
|
while(fscanf(fp,"%s%s%s%d%s",tem[i].stnum,tem[i].stname,tem[i].sex,&tem[i].age,tem[i].detail)!=EOF){
|
|
|
|
|
if(strcmp(s,tem[i].stnum)==0)
|
|
|
|
|
{
|
|
|
|
|
fprintf(ou,"%s\t%s\t%s\t%d\t%s\n",tem[i].stnum,tem[i].stname,tem[i].sex,d,tem[i].detail);
|
|
|
|
|
printf("学号:%-12s姓名:%-8s\t性别:%-4s\t年龄:%-4d\t备注:%-4s\n",tem[i].stnum,tem[i].stname,tem[i].sex,d,tem[i].detail);
|
|
|
|
|
}
|
|
|
|
|
else fprintf(ou,"%s\t%s\t%s\t%d\t%s\n",tem[i].stnum,tem[i].stname,tem[i].sex,tem[i].age,tem[i].detail);
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
out();
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
while(fscanf(fp,"%s%s%s%d%s",tem[i].stnum,tem[i].stname,tem[i].sex,&tem[i].age,tem[i].detail)!=EOF){
|
|
|
|
|
if(strcmp(s,tem[i].stnum)!=0)fprintf(ou,"%s\t%s\t%s\t%d\t%s\n",tem[i].stnum,tem[i].stname,tem[i].sex,tem[i].age,tem[i].detail);
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
fclose(fp);
|
|
|
|
|
fclose(ou);
|
|
|
|
|
unlink("data.txt");
|
|
|
|
|
rename("data2.txt","data.txt");
|
|
|
|
|
printf("文件修改完成!\a");
|
|
|
|
|
Sleep(2500);
|
|
|
|
|
system("cls");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|