#include "stdio.h"/*I/O函数*/
#include "stdlib.h" /*其它说明*/
#include "string.h" /*字符串函数*/
#include "conio.h" /*屏幕 *** 作函数*/
#include "mem.h" /*内存 *** 作函数*/
#include "ctype.h" /*字符 *** 作函数*/
#include "alloc.h" /*动态地址分配陪缺函数*/
struct score
{
int mingci
char xuehao[8]
char mingzi[20]
float score[6]
}data,info[1000]
int i,j,k=0
char temp[20],ch
FILE *fp,*fp1
void shuru()
{
if((fp=fopen("s_score.txt","ab+"))==NULL)
{
printf("cannot open this file.\n")
getch()exit(0)
}
for(i=0i<=1000i++)
{
printf("\nPlease shuru xuehao:")
gets(data.xuehao)
printf("Please shuru mingzi:")
gets(data.mingzi)
printf("Please shuru yuwen score:")
gets(temp)data.score[0]=atof(temp)
printf("Please shuru shuxue score:")
gets(temp)data.score[1]=atof(temp)
printf("Please input yingyu score:")
gets(temp)data.score[2]=atof(temp)
printf("Please shuru wuli score:")
gets(temp)data.score[3]=atof(temp)
printf("Please shur huaxue score:")
gets(temp)data.score[4]=atof(temp)
data.score[5]=data.score[0]+data.score[1]+data.score[2]+data.score[3]+data.score[4]
fwrite(&data,sizeof(data),1,fp)
printf("another?y/n")
ch=getch()
if(ch=='n'||ch=='N')
break
} fclose(fp)
}
void xianshi()
{
float sint n
if((fp=fopen("s_score.txt","rb+"))==NULL)
{
printf("胡乱老Cannot reading this file.\n")
exit(0)
}
for(i=0i<=1000i++)
{
if((fread(&info[i],sizeof(info[i]),1,fp))!=1)
break
}
printf("\nxuehao mingzi yuwen shuxue yingyu wuli huauxue zhongfen\n")
for(j=0,k=1j<ij++,k++)
{
info[j].mingci=k
printf("%6s %8s %3.1f %3.1f%3.1f%3.1f%3.1f %3.1f\n",info[j].xuehao,info[j].mingzi,info[j].score[0],info[j].score[1],info[j].score[2],info[j].score[3],info[j].score[4],
info[j].score[5])
}
getch()
fclose(fp)
}
void xiugai()
{
if((fp=fopen("s_score.txt","rb+"))==NULL||(fp1=fopen("temp.txt","wb+"))==NULL)
{
printf("Cannot open this file.\n")
exit(0)
}
printf("\nPLease shuru xiugai xuehao:")
scanf("%d",&i)getchar()
while((fread(&data,sizeof(data),1,fp))==1)
{
j=atoi(data.xuehao)
if(j==i)
{
printf("xuehao:%s\nmingzi:%s\n",data.xuehao,data.mingzi)
printf("Please shuru mingzi:")
gets(data.mingzi)
printf("Please shuru yuwen score:")
gets(temp)data.score[0]=atof(temp)
printf("Please shuru shuxue score:")
gets(temp)data.score[1]=atof(temp)
printf("Please input yingyu score:")
gets(temp)data.score[2]=atof(temp)
printf("Please input wuli score:")
gets(temp)data.score[3]=atof(temp)
printf("Please input huaxue score:")
gets(temp)data.score[4]=atof(temp)
data.score[5]=data.score[0]+data.score[1]+data.score[2]+data.score[3]+data.score[4]
} fwrite(&data,sizeof(data),1,fp1)
}
fseek(fp,0L,0)
fseek(fp1,0L,0)
while((fread(&data,sizeof(data),1,fp1))==1)
{
fwrite(&data,sizeof(data),1,fp)
}
fclose(fp)
fclose(fp1)
}
void chazhao()
{
if((fp=fopen("s_score.txt","rb"))==NULL)
{
printf("\nCannot open this file.\n")
exit(0)
}
printf("\nPLease shuru xuehao chakan:")
scanf("%d",&i)
while(fread(&data,sizeof(data),1,fp)==1)
{
j=atoi(data.xuehao)
if(i==j)
{
printf("xuehao:%s mingzi:%s\nyuwen:%f\n shuxue:%f\n yingyu:%f\n wuli:%f\n huaxue:%f\n ",data.xuehao,data.mingzi,data.score[0],data.score[1],data.score[2],data.score[3],data.score[4],data.score[5])
}getch()
}
}
void shanchu()
{
if((fp=fopen("s_score.txt","rb+"))==NULL||(fp1=fopen("temp.txt","wb+"))==NULL)
{
printf("\nopen score.txt was failed!")
getch()
exit(0)
}
printf("\nPlease input ID which you want to del:")
scanf("%d",&i)getchar()
while((fread(&data,sizeof(data),1,fp))==1)
{
j=atoi(data.xuehao)
if(j==i)
{
printf("Anykey will delet it.\n")
getch()
continue
}
fwrite(&data,sizeof(data),1,fp1)
}
fclose(fp)
fclose(fp1)
remove("s_score.txt")
rename("temp.txt","s_score.txt")
printf("Data delet was succesful!\n")
printf("Anykey will return to main.")
getch()
}
main()
{
while(1)
{
clrscr()/*清屏幕*/
gotoxy(1,1)/*移动光标*/
textcolor(YELLOW) /*设置文本显示颜色为黄色*/
textbackground(BLUE) /*设置背景颜色为蓝色*/
window(1,1,99,99) /* 制作显示菜单的窗口,大小根据菜单条数设计*/
clrscr()
printf("*************welcome to use student manage******************\n")
printf("*************************menu********************************\n")
printf("* ========================================================= * \n")
printf("* 1>shuru2>xiugai * \n")
printf("* 3>shanchu 4>chazhao* \n")
printf("* 5>xianshi 6>exit * \n")
printf("* * \n")
printf("* --------------------------------------------------------- * \n")
printf(" Please input which you want(1-6):")
ch=getch()
switch(ch)
{
case '1':shuru()break
case '2':xiugai()break
case '3':shanchu() break
case '4':chazhao()break
case '5':xianshi() break
case '6':exit(0)
default: continue
}
}
#include<stdio.h>#include<stdlib.h>
#include<string.h>
#include<conio.h>
#define N 50
struct student
{
char name[20]
char sex[20]
char college[20]
char item[20]
int ranking
}stu[N]
void menu()
void printf_face1() //定义一个面向用户的输出函数
{
printf("\n\t name\t sex\t college\t item\t ranking\n")
}
void printf_face() //定义一个面弊皮向用户的输出函数
{
printf("\n\t number\t name\t sex\t college\t item\t ranking\n")
}
void printf_one(int i)//定义一个输出函数
{
printf("\t%s\t%s\t%s\t%s\t%d",stu[i].name,stu[i].sex,stu[i].college,stu[i].item,stu[i].ranking)
}
void input(int i)//输入数据
{
printf_face1()
printf("\t")
scanf("\t%s\t%s\t%s\t\t%s\t\t%d",stu[i].name,stu[i].sex,stu[i].college,stu[i].item,stu[i].ranking)
}
void printf_back() //返回上一界面
{
printf("\n\n\t___.done. ___\n\n")
getchar()
// getchar()
// getchar()
menu()
}
void save(int n)//存入数据
{ FILE *fpint i
if((fp=fopen("file","wb"))==NULL)
{ printf("\n open error \n")
exit(0)
}
for(i=0i<ni++)
if(stu[i].name[0]!='\0')
if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1) //结构体依次写入文件,若写入失败则羡携返回非0值
printf("input error\n")
fclose(fp)
}
int load()//打开本地已存入的数据
{ FILE *fp
int i
if((fp=fopen("file","rb"))==NULL)
{ printf("\n open error \租派差n")
exit(0)
}
for(i=0!feof(fp)i++)
fread(&stu[i],sizeof(struct student),1,fp)
fclose(fp)
return(i-1)
}
void enter() //输入原始数据
{
int i,n
printf("input the number of the People(0-%d)?:",N-1)
scanf("%d",&n)
getchar() //这里加个getchar()
printf("input date:\n")
for(i=0i<ni++)
{
printf("\n intput the record of the %d.\n",i+1)
input(i)
}
if(i!=0) save(n)
printf_back()
}
void find() //查找函数//
{
char fs[20]
int i,n
n=load()
printf("input the sportsman's college or name of your research:")
scanf("%s",&fs)
for(i=0i<ni++)
{
if(strcmp(stu[i].college,fs)==0)
{
printf("found the sportsman of your research:\n")
printf_face1()
printf_one(i)
}
else if(strcmp(stu[i].name,fs)==0)
{
printf("found the sportsman of your research:\n")
printf_face1()
printf_one(i)
}
else
{
printf("no date!\n")
}
}
getchar()
getchar()
menu()
}
void scorer() //团体总分//
{
int i,n,sum=0,x
char fs[20]
n=load()
printf("input the college of your research:")
scanf("%s",&fs)
for(i=0i<ni++)
{
if(strcmp(stu[i].college,fs)==0)
{
printf_face1()
printf_one(i)
if(stu[i].ranking==1) x=7
else if(stu[i].ranking==2) x=5
else if(stu[i].ranking==3) x=3
else if(stu[i].ranking==4) x=2
else if(stu[i].ranking==5) x=1
else x=0
sum=sum+x
}
}
printf("\n总分%d:\n",sum)
getchar()
getchar()
getchar()
menu()
}
void menu() //主界面
{
int n, w1
do{
system("cls")
puts("\t\t************************menu************************\n\n ")
#include "stdio.h"#include <math.h>
struct copetitont
{ char name[10]
int score
} a[2]
int mi=0,c,ma=0
max(int x, int y)
{
return(x>脊闹y?x:y)
}
min(int x, int y)
{
return(x>y?y:x)
}
void yundong()
{
{ sleep(1)
clrscr()
c=rand()%2
if( c==1 ) a[1].score++
else a[0].score++
ma=max(a[0].score,a[1].score)
gotoxy(25,10)
printf("%s '谈野睁s score:%d \n", a[0].name,a[0].score)
gotoxy(25,13)
printf("%s 's score:%d \n"含岁, a[1].name,a[1].score)
}
}
main()
{ int i ,t
clrscr()
for(i=0i<2i++)
{
printf("please input the %d Athletes's name:\n",i)
gets(a[i].name)
a[i].score=0
}
while( ma<21 &&mi<20 )
yundong()
if(mi==20)
{
while (ma-mi<2)
yundong()
}
if(a[0].score>a[1].score) t=0
else t=1
printf("\n********%s win the competition!**********\n", a[t].name)
getch()
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)