|
|
#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;
|
|
|
case '6':
|
|
|
demand();
|
|
|
break;
|
|
|
case '7':
|
|
|
if(cpassword()!=1){
|
|
|
out();
|
|
|
return 0;
|
|
|
}
|
|
|
break;
|
|
|
case '8':
|
|
|
out();
|
|
|
return 0;
|
|
|
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*--------6 学生基本信息查询--------------*\n");
|
|
|
printf("\t\t\t\t*------------7 密码修改------------------*\n");
|
|
|
printf("\t\t\t\t*------------8 退出系统------------------*\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;
|
|
|
}
|
|
|
|
|
|
void demand()
|
|
|
{
|
|
|
int choice;
|
|
|
while(1){
|
|
|
while(1){
|
|
|
system("cls");
|
|
|
_menus();
|
|
|
printf("请输入正确选项!\n");
|
|
|
scanf("%d",&choice);
|
|
|
if(choice<6&&choice>0)break;
|
|
|
}
|
|
|
struct node tem[1000];
|
|
|
FILE *fp;
|
|
|
fp=fopen("data.txt","r");
|
|
|
if(fp==NULL){
|
|
|
printf("文件打开失败!\n");
|
|
|
end();
|
|
|
return ;
|
|
|
}
|
|
|
int i=0;
|
|
|
while(fscanf(fp,"%s%s%s%d%s",tem[i].stnum,tem[i].stname,tem[i].sex,&tem[i].age,tem[i].detail)!=EOF){
|
|
|
i++;
|
|
|
}
|
|
|
fclose(fp);
|
|
|
int sum=i;
|
|
|
char d[20];
|
|
|
int c;
|
|
|
int fa=1;
|
|
|
switch(choice){
|
|
|
case 1:
|
|
|
printf("请输入学号:");
|
|
|
scanf("%s",d);
|
|
|
printf("\n");
|
|
|
for(int i=0;i<sum;i++){
|
|
|
if(strcmp(d,tem[i].stnum)==0){
|
|
|
printf("学号:%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);
|
|
|
fa=0;
|
|
|
}
|
|
|
}
|
|
|
end();
|
|
|
break;
|
|
|
case 2:
|
|
|
printf("请输入姓名:");
|
|
|
scanf("%s",d);
|
|
|
printf("\n");
|
|
|
for(int i=0;i<sum;i++){
|
|
|
if(strcmp(d,tem[i].stname)==0){
|
|
|
printf("学号:%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);
|
|
|
fa=0;
|
|
|
}
|
|
|
}
|
|
|
end();
|
|
|
break;
|
|
|
case 3:
|
|
|
printf("请输入性别:");
|
|
|
scanf("%s",d);
|
|
|
printf("\n");
|
|
|
for(int i=0;i<sum;i++){
|
|
|
if(strcmp(d,tem[i].sex)==0){
|
|
|
printf("学号:%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);
|
|
|
fa=0;
|
|
|
}
|
|
|
}
|
|
|
end();
|
|
|
break;
|
|
|
case 4:
|
|
|
printf("请输入年龄:");
|
|
|
scanf("%d",&c);
|
|
|
printf("\n");
|
|
|
for(int i=0;i<sum;i++){
|
|
|
if(c==tem[i].age){
|
|
|
printf("学号:%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);
|
|
|
fa=0;
|
|
|
}
|
|
|
}
|
|
|
end();
|
|
|
break;
|
|
|
case 5:
|
|
|
return ;
|
|
|
}
|
|
|
if(fa==0)printf("此次查询无有效信息!\a\n");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void _menus()
|
|
|
{
|
|
|
printf("\t\t\t\t\t********选择你需要的查询********\n");
|
|
|
printf("\t\t\t\t\t*--------1 按学号查询----------*\n");
|
|
|
printf("\t\t\t\t\t*--------2 按姓名查询----------*\n");
|
|
|
printf("\t\t\t\t\t*--------3 按性别查询----------*\n");
|
|
|
printf("\t\t\t\t\t*--------4 按年龄查询----------*\n");
|
|
|
printf("\t\t\t\t\t*--------5 退出查询------------*\n\n");
|
|
|
}
|
|
|
|
|
|
void _menus2()
|
|
|
{
|
|
|
printf("\t\t\t\t\t*********请选择修改方式*******\n");
|
|
|
printf("\t\t\t\t\t*--------1 修改学号----------*\n");
|
|
|
printf("\t\t\t\t\t*--------2 修改姓名----------*\n");
|
|
|
printf("\t\t\t\t\t*--------3 修改性别----------*\n");
|
|
|
printf("\t\t\t\t\t*--------4 修改年龄----------*\n");
|
|
|
printf("\t\t\t\t\t*--------5 退出--------------*\n\n");
|
|
|
}
|
|
|
|
|
|
|
|
|
void end()
|
|
|
{
|
|
|
char c;
|
|
|
printf("按任意键继续!\n");
|
|
|
c=getch();
|
|
|
}
|
|
|
|
|
|
int cpassword()
|
|
|
{
|
|
|
char mi[100];
|
|
|
char zhang[100];
|
|
|
char mi2[100];
|
|
|
char zhang2[100];
|
|
|
if(password()!=1){
|
|
|
return 0;
|
|
|
}
|
|
|
FILE *out;
|
|
|
out=fopen("user.txt","r");
|
|
|
fscanf(out,"%s",zhang2);
|
|
|
fclose(out);
|
|
|
FILE *fp;
|
|
|
fp=fopen("user.txt","w+");
|
|
|
if(fp==NULL){
|
|
|
printf("打开文件失败!\n");
|
|
|
}
|
|
|
do{
|
|
|
printf("请修改您的密码!\n");
|
|
|
scanf("%s",mi2);
|
|
|
printf("请确认您的密码!\n");
|
|
|
scanf("%s",mi);
|
|
|
if(!strcmp(mi,mi2)){
|
|
|
fseek(fp,0L,SEEK_SET);
|
|
|
fprintf(fp,"%s %s",zhang2,mi2);
|
|
|
break;
|
|
|
}
|
|
|
else printf("两次密码不匹配\n请重新输入!\n");
|
|
|
}while(strcmp(mi,mi2)==0);
|
|
|
printf("密码修改成功!\n");
|
|
|
fclose(fp);
|
|
|
printf("请重新登陆!\n");
|
|
|
Sleep(1000);
|
|
|
system("cls");
|
|
|
return login();
|
|
|
}
|
|
|
|
|
|
int login()
|
|
|
{
|
|
|
char mi[100];
|
|
|
char zhang[100];
|
|
|
char mi2[100];
|
|
|
char zhang2[100];
|
|
|
FILE *fp;
|
|
|
fp=fopen("user.txt","r");
|
|
|
if(fp==NULL){
|
|
|
printf("打开文件失败!\n");
|
|
|
}
|
|
|
fscanf(fp,"%s",zhang2);
|
|
|
fscanf(fp,"%s",mi2);
|
|
|
fclose(fp);
|
|
|
for(int i=0;i<3;i++){
|
|
|
printf("请输入您的账号:");
|
|
|
scanf("%s",zhang);
|
|
|
printf("\n");
|
|
|
printf("请输入您的密码:");
|
|
|
// int k=0;
|
|
|
// for(k=0;k<100;k++){
|
|
|
// mi[k]=getch();
|
|
|
// if(mi[k]=='\r'){
|
|
|
// break;
|
|
|
// }
|
|
|
// printf("*");
|
|
|
// }
|
|
|
// mi[k]='\0';
|
|
|
scanf("%s",mi);
|
|
|
printf("\n");
|
|
|
if(strcmp(mi,mi2)!=0||strcmp(zhang,zhang2)!=0){
|
|
|
system("cls");
|
|
|
printf("账号或密码输入错误!\n请重新输入!\n你还有%d次机会\n",3-i-1);
|
|
|
if(3-i-1==0){
|
|
|
printf("本次使用到此结束!\n");
|
|
|
printf("按任意键退出!\n");
|
|
|
getchar();
|
|
|
getchar();
|
|
|
return 0;
|
|
|
}
|
|
|
}else{
|
|
|
printf("欢迎使用本系统!\n");
|
|
|
end();
|
|
|
system("cls");
|
|
|
return 1;
|
|
|
}
|
|
|
}
|
|
|
end();
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
int password()
|
|
|
{
|
|
|
char mi[100];
|
|
|
char mi2[100];
|
|
|
char zhang2[100];
|
|
|
int fa=1;
|
|
|
FILE *fp;
|
|
|
fp=fopen("user.txt","r");
|
|
|
if(fp==NULL){
|
|
|
printf("打开文件失败!\n");
|
|
|
}
|
|
|
fscanf(fp,"%s",zhang2);
|
|
|
fscanf(fp,"%s",mi2);
|
|
|
fclose(fp);
|
|
|
while(1){
|
|
|
if(fa==1)printf("请输入密码!\n");
|
|
|
else printf("密码错误!\n\n请再次输入密码!\n");
|
|
|
scanf("%s",mi);
|
|
|
printf("%s\n",mi);
|
|
|
getchar();
|
|
|
if(fa>3){
|
|
|
char ch;
|
|
|
system("cls");
|
|
|
printf("是否取消修改密码?\n");
|
|
|
printf("若取消则输入Y\n任意键取消\n");
|
|
|
scanf("%c",&ch);
|
|
|
if(ch=='Y')return 0;
|
|
|
}
|
|
|
fa++;
|
|
|
if(strcmp(mi,mi2)==0){
|
|
|
system("cls");
|
|
|
printf("密码正确!\n");
|
|
|
Sleep(1000);
|
|
|
return 1;
|
|
|
}
|
|
|
}
|
|
|
return 0;
|
|
|
}
|