| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 311 人关注过本帖
标题:编写调查学生户口薄信息的程序,大家给点意见。。
只看楼主 加入收藏
岳三路
Rank: 2
等 级:论坛游民
帖 子:23
专家分:19
注 册:2011-3-30
结帖率:60%
收藏
已结贴  问题点数:20 回复次数:1 
编写调查学生户口薄信息的程序,大家给点意见。。
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<time.h>
typedef struct
{
    char id[12];
    char name[21];
    char origin[101];
}student;
FILE *fp;
student stu,cache;
void Menu()
{
    system("cls");
    time_t t = time(0);
    char tmp[64];
    strftime(tmp, sizeof(tmp), "%Y/%m/%d %A",localtime(&t));
    puts(tmp);
    printf("\n");
    printf("1 --输入籍贯信息\n");
    printf("2 --显示所有信息\n");
    printf("3 --按学号查询\n");
    printf("4 --按姓名查询\n");
    printf("5 --按籍贯查询\n");
    printf("0 --退出\n\n\n请输入选项:");
}
void Creat_add()
{
    system("cls");
    fp=fopen("stu_origin.dat","rb+");
    if(fp==NULL)
    {
        fp=fopen("stu_origin.dat","wb+");
        if(fp==NULL)
           {
                     printf("can't creat the file stu_origin.dat!\n");
                     printf("Press any key to exit...");getch();
                  }
    }
    fseek(fp,0,SEEK_END);
    char next='y';
    while(next=='y'||next=='Y')
    {
    printf("请输入学号:");scanf("%s",stu.id);
    printf("请输入姓名:");scanf("%s",stu.name);
    printf("请输入籍贯:");scanf("%s",stu.origin);
    printf("\n\n确定写入数据?(y/n)");
    if(getch()=='y'||getch()=='Y')
        fwrite(&stu,sizeof(stu),1,fp);
    printf("\n\n是否继续输入?(y/n)");
        next=getch();
        system("cls");
    }
    fclose(fp);
}
void Display_all()
{
    system("cls");
    fp=fopen("stu_origin.dat","rb");
    if(fp==NULL)
           {
              printf("can't open the file stu_origin.dat!\nPress any key to get back...");
              getch();
           }
    else
    {
    rewind(fp);printf("\n\n学号\t\t姓名\t\t籍贯\n");
    while(fread(&stu,sizeof(stu),1,fp))
    printf("%s\t%s\t%s\n",stu.id,stu.name,stu.origin);
    fclose(fp);
    printf("\n\nPress any key to get back...");getch();
    }
}
int Check_Id(char *Id,char c)
{
    rewind(fp);
    while(fread(&cache,sizeof(stu),1,fp))
    {
        if(strcmp(Id,cache.id)==0)
        {
            printf("\n\n学号\t\t姓名\t\t籍贯\n");
            printf("%s\t%s\t%s\n",cache.id,cache.name,cache.origin);
            return 0;
        }
    }
    printf("\n\n无此学生!\n");
        return 1;
}
int Check_Name(char *Name,char c)
{
    int n=0;
    rewind(fp);
    while(fread(&cache,sizeof(stu),1,fp))
    {
        if(strcmp(Name,cache.name)==0)
        {
           if(++n==1)
                        printf("\n\n学号\t\t姓名\t\t籍贯\n");
           printf("%s\t%s\t%s\n",cache.id,cache.name,cache.origin);
        }
    }
    if(!n)
           {
             printf("\n\n无此学生!\n");
             return 1;
           }
    return 0;
}
int Check_Orgin(char *Origin,char c)
{
    int n=0;
    rewind(fp);
    while(fread(&cache,sizeof(stu),1,fp))
    {   
    if(strcmp(Origin,cache.origin)==0)
        {
            if(++n==1)printf("\n\n学号\t\t姓名\t\t籍贯\n");   
        printf("%s\t%s\t%s\n",cache.id,cache.name,cache.origin);
        }
    }
    if(!n){printf("\n\n无此学生!\n");return 1;}
    return 0;
}
void Search_id()
{   
     fp=fopen("stu_origin.dat","rb");
     if(fp==NULL)
        {
          printf("can't open the file stu_origin.dat!\nPress any key to get back...");
          getch();
        }
    char k;   
        do
      {system("cls");
         do{
                printf("请输入学号:");
                gets(stu.id);
             }while(Check_Id(stu.id,'s'));
      printf("\n\n继续查询?(y/n)");
        k=getch();
    }while(k=='y'||k=='Y');   
    fclose(fp);
    printf("\nPress any key to get back...");
        getch();
}
void Search_name()
{   
        fp=fopen("stu_origin.dat","rb");
    if(fp==NULL) {printf("can't open the file stu_origin.dat!\nPress any key to get back...");getch();}
    do
       {system("cls");
          do{
                 printf("请输入姓名:");
                 gets(stu.name);
              }while(Check_Name(stu.name,'s'));   
            printf("\n\n继续查询?(y/n)");
    }while(getch()=='y'||getch()=='Y');
    fclose(fp);
    printf("\nPress any key to get back...");getch();
}
void Search_origin()
{
    fp=fopen("stu_origin.dat","rb");
    if(fp==NULL) {printf("can't open the file stu_origin.dat!\nPress any key to get back...");getch();}
    do
       {system("cls");
         do{
                printf("请输入籍贯:");
                gets(stu.origin);
             }while(Check_Orgin(stu.origin,'s'));
        printf("\n\n继续查询?(y/n)");
    }while(getch()=='y'||getch()=='Y');
    fclose(fp);   
        printf("\nPress any key to get back...");
        getch();
}
void Call()
{
    char key=getch();
    if(key=='1') Creat_add();
    if(key=='2') Display_all();
    if(key=='3') Search_id();
    if(key=='4') Search_name();   
        if(key=='5') Search_origin();
    if(key=='0') exit(1);
}
void main()
{
    while(1){Menu();Call();}
}
搜索更多相关主题的帖子: system 姓名 
2011-04-19 00:03
刘定邦
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
帖 子:687
专家分:1570
注 册:2010-9-21
收藏
得分:20 
仅学习。无意见。
2011-04-19 10:40
快速回复:编写调查学生户口薄信息的程序,大家给点意见。。
数据加载中...
 
   



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

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