master
王怡 6 years ago
commit b9bfa62a4b

@ -0,0 +1,62 @@
[Project]
FileName=CÓïÑÔ¿ÎÉè.dev
Name=CÓïÑÔ¿ÎÉè
Type=1
Ver=2
ObjFiles=
Includes=
Libs=
PrivateResource=
ResourceIncludes=
MakeIncludes=
Compiler=
CppCompiler=
Linker=
IsCpp=0
Icon=
ExeOutput=
ObjectOutput=
LogOutput=
LogOutputEnabled=0
OverrideOutput=0
OverrideOutputName=
HostApplication=
UseCustomMakefile=0
CustomMakefile=
CommandLine=
Folders=
IncludeVersionInfo=0
SupportXPThemes=0
CompilerSet=3
CompilerSettings=0000000100000000000000000
UnitCount=1
[VersionInfo]
Major=1
Minor=0
Release=0
Build=0
LanguageID=1033
CharsetID=1252
CompanyName=
FileVersion=
FileDescription=Developed using the Dev-C++ IDE
InternalName=
LegalCopyright=
LegalTrademarks=
OriginalFilename=
ProductName=
ProductVersion=
AutoIncBuildNr=0
SyncProduct=1
[Unit1]
FileName=main.c
CompileCpp=0
Folder=
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=

Binary file not shown.

@ -0,0 +1,8 @@
[Editors]
Order=0
Focused=0
[Editor_0]
CursorCol=6
CursorRow=244
TopLine=238
LeftChar=1

@ -0,0 +1,28 @@
# Project: CÓïÑÔ¿ÎÉè
# Makefile created by Dev-C++ 5.11
CPP = g++.exe
CC = gcc.exe
WINDRES = windres.exe
OBJ = main.o
LINKOBJ = main.o
LIBS = -L"C:/Program Files/Dev-Cpp/MinGW64/x86_64-w64-mingw32/lib32" -static-libgcc -m32
INCS = -I"C:/Program Files/Dev-Cpp/MinGW64/include" -I"C:/Program Files/Dev-Cpp/MinGW64/x86_64-w64-mingw32/include" -I"C:/Program Files/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include"
CXXINCS = -I"C:/Program Files/Dev-Cpp/MinGW64/include" -I"C:/Program Files/Dev-Cpp/MinGW64/x86_64-w64-mingw32/include" -I"C:/Program Files/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include" -I"C:/Program Files/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++"
BIN = CÓïÑÔ¿ÎÉè.exe
CXXFLAGS = $(CXXINCS) -m32
CFLAGS = $(INCS) -m32
RM = rm.exe -f
.PHONY: all all-before all-after clean clean-custom
all: all-before $(BIN) all-after
clean: clean-custom
${RM} $(OBJ) $(BIN)
$(BIN): $(OBJ)
$(CC) $(LINKOBJ) -o $(BIN) $(LIBS)
main.o: main.c
$(CC) -c main.c -o main.o $(CFLAGS)

273
main.c

@ -0,0 +1,273 @@
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct stu /*定义结构体数组*/
{
char num[15];
char banji[10];
char name[25];
int hour1;
int hour2;
int min1;
int min2;
}st[99];
void menu() /*菜单*/
{
printf("\t**************************\n");
printf("\t****1---输入数据**********\n");
printf("\t****2---计算费用**********\n");
printf("\t****3---删除数据**********\n");
printf("\t****4---查询数据**********\n");
printf("\t**************************\n");
printf("\t输入相应数字选择以回车结束\n");
}
void new_students(int *p);
void calculate(struct stu st[],int *q);
void del(int *p);
void search(int *p);
void main() /*主函数*/
{
int b=0;
int a,*p;
FILE *fpp; /*定义文件指针*/
p=&b;
if((fpp=fopen("stu_num.txt","r"))==NULL)
{
printf("无历史记录");
system("pause");
}
else
{
fread(p,4,1,fpp);
fclose(fpp);
}
while(1)
{
system("cls");
menu();
scanf("%d",&a);
switch(a)
{
case 1:
new_students(p); break;
case 2:
calculate(st,p); break;
case 3:
del(p); break;
case 4:
search(p); break;
case 5:
{
system("pause");
exit(0);
}
default :
printf("continue\n");
}
system("pause");
}
}
void new_students(int *p) /*输入函数*/
{
int i;
FILE *fp;
FILE *fpp;
for(i=*p;i<*p+1;i++)
{
printf("请输入信息!\n");
printf("学号为:");
scanf("%s",&st[i].num);
fflush(stdin);
printf("班级为:");
scanf("%s",&st[i].banji);
printf("姓名为:");
scanf("%s",&st[i].name);
printf("上机小时为:");
scanf("%d",&st[i].hour1);
printf("上机分钟为:");
scanf("%d",&st[i].min1);
printf("下机小时为:");
scanf("%d",&st[i].hour2);
printf("下机机分钟为:");
scanf("%d",&st[i].min2);
}
if(*p==0)
{
if((fp=fopen("stu_menu.txt","w"))==NULL)
printf("cannot open file");
}
else
{
fp=fopen("stu_menu.txt","r+");
for(i=0;i<*p;i++)
fread(&st[i],sizeof(struct stu),1,fp); /*写入文件*/
}
for(i=0;i<*p+1;i++)
if(fwrite(&st[i],sizeof(struct stu),1,fp)!=1)
fclose(fp);
*p=*p+1;
if((fpp=fopen("stu_num.txt","w"))==NULL)
{
printf("cannot open file");
return;
}
if(fwrite(p,4,1,fpp)!=1)
printf("file write error");
fclose(fpp);
}
void calculate(struct stu st[],int *q)
{
int i,j;
FILE *fp;
char a;
fp=fopen("stu_menu.txt","r"); /*打开文件*/
for(i=0;i<*q;i++)
{
fread(&st[i],sizeof(struct stu),1,fp);
system("cls");
printf("学号为:%s\t 班级为:%s\t 姓名为:%s\t",st[i].num,st[i].banji,st[i].name);
printf("\t上机时间为:%d时%d分",st[i].hour1,st[i].min1);
printf("\t下机时间为:%d时%d分",st[i].hour2,st[i].min2);
if(st[i].min1<=st[i].min2)
j=(st[i].hour2-st[i].hour1)*60+(st[i].min2-st[i].min1);
else if(st[i].min1>st[i].min2)
j=(st[i].hour2-st[i].hour1-1)*60+(60-st[i].min1+st[i].min2);
else if(st[i].min1==0&&st[i].min2==0)
j=(st[i].hour2-st[i].hour1)*60;
printf("费用为:%d元",j);
}
fflush(stdin);
a=getchar();
system("cls");
}
void del(int *p) /*删除函数*/
{
int i,j;
char a[9];
FILE *fp;
FILE *fpp;
fp=fopen("stu_menu.txt","r+");
for(i=0;i<*p;i++)
fread(&st[i],sizeof(struct stu),1,fp);
printf("请输入要删除的名字");
scanf("%s",a);
for(i=0;i<*p;i++)
{
if(strcmp(a,st[i].name)==0)
{
for(j=i;j<*p-1;j++)
{
strcpy(st[j].num,st[j+1].num);
strcpy(st[j].banji,st[j+1].banji);
st[j].hour1=st[j+1].hour1;
st[j].min1=st[j+1].min1;
st[j].hour2=st[j+1].hour2;
st[j].min2=st[j+1].min2;
strcpy(st[j].name,st[j+1].name);
}
*p=*p-1;
}
}
for(i=0;i<*p;i++)
fwrite(&st[i],sizeof(struct stu),1,fp);
fclose(fp);
if((fpp=fopen("stu_num.txt","w"))==NULL)
{
printf("cann't open file");
return;
}
if(fwrite(p,4,1,fp)!=1)
printf("file write error");
fclose(fpp);
printf("该生信息已经不存在");
}
void search(int *p) /*查询数据*/
{
int a,i,c=1,j;
char b[9];
FILE *fp;
fp=fopen("stu_menu.txt","r");
for(i=0;i<*p;i++)
fread(&st[i],sizeof(struct stu),1,fp);
fclose(fp);
printf("**请输入相应数字选择查询的条件**\n");
printf("1:学号 2:姓名 3:班级\n");
scanf("%d",&a);
switch(a) /*选择查找方式*/
{
case 1:
{
printf("学号");
scanf("%s",b);
for(i=0;i<*p;i++)
if(strcmp(b,st[i].num)==0)
{
printf("学号为:%s 班级为:%s 姓名为:%s",st[i].num,st[i].banji,st[i].name);
printf("\t上机时间为:%d时%d分",st[i].hour1,st[i].min1);
printf("\t下机时间为:%d时%d分",st[i].hour2,st[i].min2);
if(st[i].min1<=st[i].min2)
j=(st[i].hour2-st[i].hour1)*60+(st[i].hour2-st[i].hour1);
else if(st[i].min1>st[i].min2)
j=(st[i].hour2-st[i].hour1-1)*60+(60-st[i].min1+st[i].min2);
else if(st[i].min1==0&&st[i].min2==0)
j=st[i].hour2-st[i].hour1;
printf("费用为:%d元",j);
c=0;
}
if(c==1)
{
printf("没有相关消息");
}
} break;
case 2:
{
printf("姓名");
scanf("%s",b);
for(i=0;i<*p;i++)
if(strcmp(b,st[i].name)==0)
{
printf("学号为:%s 班级为:%s 姓名为:%s",st[i].num,st[i].banji,st[i].name);
printf("\t上机时间为:%d时%d分",st[i].hour1,st[i].min1);
printf("\t下机时间为:%d时%d分",st[i].hour2,st[i].min2);
if(st[i].min1<=st[i].min2)
j=(st[i].hour2-st[i].hour1)*60+(st[i].min2-st[i].min1);
else if(st[i].min1>st[i].min2)
j=(st[i].hour2-st[i].hour1-1)*60+(60-st[i].min1+st[i].min2);
else if(st[i].min1==0&&st[i].min2==0)
j=st[i].hour2-st[i].hour1;
printf("费用为:%d元",j);
c=0;
}
if(c==1)
{
printf("没有相关消息");
}
} break;
case 3:
{
printf("班级");
scanf("%s",b);
for(i=0;i<*p;i++)
if(strcmp(b,st[i].banji)==0)
{
printf("学号为:%s 班级为:%s 姓名为:%s",st[i].num,st[i].banji,st[i].name);
printf("\t上机时间为:%d时%d分",st[i].hour1,st[i].min1);
printf("\t下机时间为:%d时%d分",st[i].hour2,st[i].min2);
if(st[i].min1<=st[i].min2)
j=(st[i].hour2-st[i].hour1)*60+(st[i].min2-st[i].min1);
else if(st[i].min1>st[i].min2)
j=(st[i].hour2-st[i].hour1-1)*60+(60-st[i].min1+st[i].min2);
else if(st[i].min1==0&&st[i].min2==0)
j=(st[i].hour2-st[i].hour1)*60;
printf("费用为:%d元",j);
c=0;
}
if(c==1)
{
printf("没有相关消息");
}
} break;
default :
printf("没有相关信息");
}
}

BIN
main.o

Binary file not shown.
Loading…
Cancel
Save