| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 934 人关注过本帖
标题:学籍管理(带音乐的)
只看楼主 加入收藏
baoliwanqing
Rank: 1
等 级:新手上路
帖 子:27
专家分:0
注 册:2005-7-6
收藏
 问题点数:0 回复次数:4 
学籍管理(带音乐的)

#include <stdio.h> #include <stdlib.h> #include <string.h> #include <conio.h> #include <ctype.h> #define N 100 struct scorce { char admi[6]; char password[6]; char num[10]; char name[30]; int scorce[6]; char key[5]; }data,info[N],a; /*data放数据,info放排序后的数据*/ int i,j,k,m,l=0; char s[20]; /*存储参数*/ FILE *fp,*fp1,*fp2;

void input() { char c; if((fp=fopen("s_scorce.txt","ab+"))==NULL) /*以读写打开文件,并判断是否打开*/ { printf("cannot open this file.\n"); getch(); } for(i=0;i<=100;i++) { char c; printf("Please input student's password:"); /*资料录入*/ gets(data.password);

printf("Please input number:"); gets(data.num);

printf("Please input name:"); gets(data.name);

printf("Please input maths scorce:"); gets(s); data.scorce[1]=atoi(s);

printf("Please input english scorce:"); gets(s); data.scorce[2]=atoi(s);

printf("Please input physics scorce:"); gets(s); data.scorce[3]=atoi(s);

printf("Please input chemistry scorce:"); gets(s); data.scorce[4]=atoi(s);

data.scorce[5]=data.scorce[1]+data.scorce[2]+data.scorce[3]+data.scorce[4]; /*总分*/

data.scorce[6]=((data.scorce[1]+data.scorce[2]+data.scorce[3]+data.scorce[4])/4); /*平均分*/ fwrite(&data,sizeof(data),1,fp); /*写入文件*/ printf("another? (y/n)\n"); c=getch(); if(c=='n'||c=='N') break; }fclose(fp); }

void sort_maths() /*数学排序*/ { float n; if((fp=fopen("s_scorce.txt","r"))==NULL) /*只读打开并判断是否打开*/ { printf("Cannot reading this file.\n"); exit(0); } printf("\nfile:"); for(i=0;fread(&info,sizeof(struct scorce),1,fp)!=0;i++) {printf("\n%8s%8s",info.num,info.name); printf("%d",info.scorce[1]); }fclose(fp); n=i; for(i=0;i<n;i++) /*冒泡排序*/ for(j=i+1;j<n;j++) if(info.scorce[1]<info[j].scorce[1]) {a=info; info=info[j]; info[j]=a; } printf("\nnow:"); fp=fopen("stu_sort.txt","w"); for(i=0;i<n;i++) {fwrite(&info,sizeof(struct scorce),1,fp); printf("\n%8s%8s",info.num,info.name); printf("%d",info.scorce[1]); } getch(); fclose(fp); } void sort_english() { float n; if((fp=fopen("s_scorce.txt","r"))==NULL) { printf("Cannot reading this file.\n"); exit(0); } printf("\nfile:"); for(i=0;fread(&info,sizeof(struct scorce),1,fp)!=0;i++) {printf("\n%8s%8s",info.num,info.name); printf("%d",info.scorce[2]); }fclose(fp); n=i; for(i=0;i<n;i++) for(j=i+1;j<n;j++) if(info.scorce[2]<info[j].scorce[2]) {a=info; info=info[j]; info[j]=a; } printf("\nnow:"); fp=fopen("stu_sort.txt","w"); for(i=0;i<n;i++) {fwrite(&info,sizeof(struct scorce),1,fp); printf("\n%8s%8s",info.num,info.name); printf("%d",info.scorce[2]); } getch(); fclose(fp); } void sort_physics() { float n; if((fp=fopen("s_scorce.txt","r"))==NULL) { printf("Cannot reading this file.\n"); exit(0); } printf("\nfile:"); for(i=0;fread(&info,sizeof(struct scorce),1,fp)!=0;i++) {printf("\n%8s%8s",info.num,info.name); printf("%d",info.scorce[3]); }fclose(fp); n=i; for(i=0;i<n;i++) for(j=i+1;j<n;j++) if(info.scorce[3]<info[j].scorce[3]) {a=info; info=info[j]; info[j]=a; } printf("\nnow:"); fp=fopen("stu_sort.txt","w"); for(i=0;i<n;i++) {fwrite(&info,sizeof(struct scorce),1,fp); printf("\n%8s%8s",info.num,info.name); printf("%d",info.scorce[3]); } getch(); fclose(fp); } void sort_chemistry() { float n; if((fp=fopen("s_scorce.txt","r"))==NULL) { printf("Cannot reading this file.\n"); exit(0); } printf("\nfile:"); for(i=0;fread(&info,sizeof(struct scorce),1,fp)!=0;i++) {printf("\n%8s%8s",info.num,info.name); printf("%d",info.scorce[4]); }fclose(fp); n=i; for(i=0;i<n;i++) for(j=i+1;j<n;j++) if(info.scorce[4]<info[j].scorce[4]) {a=info; info=info[j]; info[j]=a; } printf("\nnow:"); fp=fopen("stu_sort.txt","w"); for(i=0;i<n;i++) {fwrite(&info,sizeof(struct scorce),1,fp); printf("\n%8s%8s",info.num,info.name); printf("%d",info.scorce[4]); } getch(); fclose(fp); } void sort_total() { float n; if((fp=fopen("s_scorce.txt","r"))==NULL) { printf("Cannot reading this file.\n"); exit(0); } printf("\nfile:"); for(i=0;fread(&info,sizeof(struct scorce),1,fp)!=0;i++) {printf("\n%8s%8s",info.num,info.name); printf("%d",info.scorce[5]); }fclose(fp); n=i; for(i=0;i<n;i++) for(j=i+1;j<n;j++) if(info.scorce[5]<info[j].scorce[5]) {a=info; info=info[j]; info[j]=a; } printf("\nnow:"); fp=fopen("stu_sort.txt","w"); for(i=0;i<n;i++) {fwrite(&info,sizeof(struct scorce),1,fp); printf("\n%8s%8s",info.num,info.name); printf("%d",info.scorce[5]); } getch(); fclose(fp); }

void display() /*显示数据*/ { float s;int n; if((fp=fopen("s_scorce.txt","rb+"))==NULL) /*只读打开*/ { printf("Cannot reading this file.\n"); exit(0); } for(i=0;i<=100;i++) { if((fread(&info,sizeof(info),1,fp))!=1) break; } printf("\nclass number name chinese maths english physics chemistry total average\n"); for(j=0,k=1;j<i;j++,k++) { printf(" %6s %5s %3d %3d %3d %3d %3d \n",info[j].num,info[j].name,info[j].scorce[1],info[j].scorce[2],info[j].scorce[3],info[j].scorce[4],info[j].scorce[5]); } fclose(fp); getch(); } void showone() /*显示个人数据*/ { if((fp=fopen("s_scorce.txt","rb"))==NULL) { printf("\nCannot open this file.\n"); exit(0); } printf("\nPlease input number:"); scanf("%d",&i); printf("Please input password:"); scanf("%d",&k); while(fread(&data,sizeof(data),1,fp)==1) { j=atoi(data.num); l=atoi(data.password); if((i==j)&&(k==l)) { printf("num:%7s name:%7s\n maths: %3d\n english: %3d\n physics: %3d\n chemistry: %3d\n total: %3d\n average: %3d\n ",data.num,data.name,data.scorce[1],data.scorce[2],data.scorce[3],data.scorce[4],data.scorce[5],data.scorce[6]); }fclose(fp); getch(); } } void change() /*修改数据*/ { if((fp=fopen("s_scorce.txt","rb+"))==NULL||(fp1=fopen("temp.txt","wb+"))==NULL) { printf("Cannot open this file.\n"); exit(0); } printf("\nPlease input the change number:"); scanf("%d",&i); getchar(); while((fread(&data,sizeof(data),1,fp))==1) { j=atoi(data.num); if(j==i) { printf("Please input name:"); gets(data.name);

printf("Please inpu maths scorce:"); gets(s); data.scorce[1]=atoi(s);

printf("Please input english scorce:"); gets(s); data.scorce[2]=atoi(s);

printf("Please input physics scorce:"); gets(s); data.scorce[3]=atoi(s);

printf("Please input chemistry scorce:"); gets(s); data.scorce[4]=atoi(s);

data.scorce[5]=data.scorce[1]+data.scorce[2]+data.scorce[3]+data.scorce[4]; data.scorce[6]=((data.scorce[1]+data.scorce[2]+data.scorce[3]+data.scorce[4])/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 search() /*查询*/ { if((fp=fopen("s_scorce.txt","rb"))==NULL) { printf("\nCannot open this file.\n"); exit(0); } printf("\nPlease input number:"); scanf("%d",&i); while(fread(&data,sizeof(data),1,fp)==1) { j=atoi(data.num); if(i==j) { printf(" number:%10s\n name:%8s %3d\n maths: %3d\n english: %3d\n physics: %3d\n chemistry: %3d\n total: %3d\n average: %3d\n",data.num,data.name,data.scorce[1],data.scorce[2],data.scorce[3],data.scorce[4],data.scorce[5],data.scorce[6]); } fclose(fp); getch(); } }

void change_password() { if((fp=fopen("s_scorce.txt","rb+"))==NULL||(fp1=fopen("temp.txt","wb+"))==NULL) { printf("\nCannot open this file.\n"); exit(0); } printf("\nPlease input number:"); scanf("%d",i); getchar(); printf("Please input password:"); scanf("%d",&k); getchar(); while(fread(&data,sizeof(data),1,fp)==1) { j=atoi(data.num); l=atoi(data.password); if((i==j)&&(k==l)) { printf("number:%s\n name:%s\n password:%s\n",data.num,data.name,data.password); printf("Please input new password:"); gets(data.password); } 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 menu() { char c; while(1) { char c; clrscr(); printf("**********************Scorce Manage System******************\n"); printf(" 1.diaplay the maths scorce \n"); printf(" 2.display the english scorce \n " ); printf(" 3.display rhe physics scorce \n"); printf(" 4.display the chemistry \n"); printf(" 5.display the total "); printf(" 0.quit \n"); printf("************************************************************\n"); printf(" Please enter your choice(0-5):"); c=getch(); switch(c) { case '1':sort_maths();break; case '2':sort_english();break; case '3':sort_physics();break; case '4':sort_chemistry();break; case '5':sort_total();break; case '0':exit(0); default: continue; } } }

搜索更多相关主题的帖子: 音乐 学籍管理 
2005-07-06 16:00
baoliwanqing
Rank: 1
等 级:新手上路
帖 子:27
专家分:0
注 册:2005-7-6
收藏
得分:0 
void
stu()
{
      for(;;)
   
{
      char c;
      
clrscr();
      printf("
=======================student
interface==================\n\n");
      
printf("                        
1.list         
\n");
         
printf("                    
2.modify password\n");
         
printf("                    
0.quit\n");
         
printf("   \n  Please enter your
choice(0-2):");
         
c=getch();
         
switch(c)
               
{
                        
case '1':showone();
break;
                        
case '2':change_password();
break;
                        
case
'3':exit(0);
                        
default:
continue;
                 
}
        }
}
void
admi_password()
{
   
if((fp2=fopen("admi.txt","r"))==NULL)
   
{
        printf("Cannot open the related
file!\n");
        
exit(0);
    }
    printf("\nPlease input
the former password:\n");
   
scanf("%d",&amp;i);
    fread(&amp;data,sizeof(struct
scorce),1,fp2);
   
if(i!=atoi(data.key))
        
{
        
printf("Error!\n");
        
fclose(fp2);
         
}
    fclose(fp2);
   
fp2=fopen("admi.txt","w");
    printf("\nPlease input new
password:\n");
    scanf("%s",data.key);
   
fwrite(&amp;data,sizeof(struct scorce),1,fp2);
   
fclose(fp2);
    printf("save secess\n");
}
void
admi()
{
   
if((fp2=fopen("admi.txt","r"))==NULL)
   
{
        
fp2=fopen("admi.txt","w");
        
if(fp2==NULL)
        
{
            
printf("Cannot opening related
files!\n");
            
exit(-1);
        
}
        printf("Please input original
password:\n");
        
gets(data.key);
        
fwrite(&amp;data,sizeof(struct
scorce),1,fp2);
        
fclose(fp2);
        
printf("Ok!\n");
    }
    printf("\nplease
input password:");
   
scanf("%d",&amp;i);
   
while(fread(&amp;data,sizeof(data),1,fp2)==1)
   
{
        
j=atoi(data.key);
        
if(i==j)
        
{printf("sucess\n");
        
}
        else
   
{printf("error");exit(0);
    }
   
fclose(fp2);
}
for(;;)
{
        char
c;
        
clrscr();
        
printf("----------------------administractor-----------------------\n");
        
printf("                     
1.enter the record     
\n");
        
printf("                     
2.modify the record\n");
        
printf("                     
3.search\n");
        
printf("                     
4.list  \n");
        
printf("                     
5.sort\n");
        
printf("                     
6.modify password     \n")
;
        
printf("                     
0.quit   \n");
      
printf("\n");
      
printf("     Please enter your
choice(0-7):\n");
      
c=getch();
      
switch(c)
         
{
            case
'1':input();break;
            
case
'2':change();break;
            
case
'3':search();break;
            
case
'4':display();break;
            
case
'5':menu();break;
            
case
'6':admi_password();break;
            
case
'0':exit(0);
            
default: continue;
    }
}
}
main()
{

      char c;
      
clrscr();
      
printf("                           
menu                  
\n");
      
printf("-------------------------------------------------------------\n");
      
printf("                        
1.student    \n");
      
printf("                        
2.administractor  \n");
      
printf("                        
0.quit    \n");
      
printf("--------------------------------------------------------------\n");
      
printf("     Please enter your
choice(0-2):\n");
      
c=getch();
      
switch(c)
        
{
          case
'1':stu();break;
          case
'2':admi();break;
          case
'0':exit(0);
        }
}

/*我就是我*/
2005-07-06 16:01
飞舞留香
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2005-4-18
收藏
得分:0 
printf("     Please enter your
choice(0-7):\n");

那我输入a或 b会怎么样呢?
2005-07-06 18:22
飞舞留香
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2005-4-18
收藏
得分:0 
可不可以,输入字符串,转为整形呢
printf("     Please enter your
choice(0-7):\n");
scanf("%s",s);
c=atoi(s);
switch(c)
........
2005-07-06 18:27
laicai2003
Rank: 1
等 级:新手上路
帖 子:76
专家分:2
注 册:2005-8-25
收藏
得分:0 
还不如直接让输入一个字符:
printf("Input your chioce:");
scanf("%s",&amp;a);
switch(a)
{
   case '1':
      .......
   case '2':
     ........
   default:
    ........
}

爱好和平,就是热爱生命!
2005-08-26 18:49
快速回复:学籍管理(带音乐的)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.026203 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved