| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 658 人关注过本帖
标题:向高手问一个小小的问题
只看楼主 加入收藏
sunyh1999
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:14
帖 子:1178
专家分:3032
注 册:2009-5-17
结帖率:79.37%
收藏
 问题点数:0 回复次数:7 
向高手问一个小小的问题
#include <stdio.h>
#define M 500
#include <windows.h>
#include<conio.h>
#include <string.h>

struct student
{   int num;
    char name[20];
    char sex[3];
    char nation[5];
    char addr[30];
    char age[3];
    char brithday[11];
    char phone[13];
    } stu[M];

    int enter (struct student stu []);
    void menu2();
    void menu();
    void scan();
    void print();
    void scanname();
    void scanno();
    void change();
    void menu3();
    void change();
    void paixu();
    void delete_xh();
    void save(struct student stu[]);
    void load(struct student stu[]);
    void help();
    void password();
    int j=0;
   

     main ()
    { char a;
      
     menu ();
     password();
     a=getche();
     switch(a)
    {
        case '1' :system("cls"); enter(stu)  ;break;
        case '2' : system("cls");scan(stu) ;break;
        case '3' :  system("cls");delete_xh(stu);break;
        case '4' :  system("cls");save(stu);break;
        case '5' : system("cls");paixu(stu);break;
        case '6' : system("cls");change(stu);break;system ("exit");
        case '7' : system("cls"); load(stu);;break;
        case '8' : system("cls"); help();;break;
        case '9' :system("cls"); printf("欢迎再次使用学生管理系统");system("PAUSE");;break;
        default:
        {
        system("PAUSE");
        system("cls");
        _beep(300,200);
        _beep(200,200);
        _beep(100,200);
        printf("输入错误请重新选择:\n");}
        if(a=='1'||a=='2'||a=='3'||a=='4'||a=='5'||a=='6'||a=='7'||a=='8'||a=='9')
       break;
      else
       main();
    }
       return 0;
}

void menu ()
{
    printf("\t\t\t学生管理系统主菜单\n");
    printf("********************************************************************************\n");
    printf("请按数字(1-9)选择:\n");
    printf("1.录入学生信息.\n");
    printf("2.查询学生信息.\n");
    printf("3.按学号删除学生信息.\n");
    printf("4.保存学生信息.\n");
    printf("5.按学号排序.\n");
    printf("6.修改信息.\n");
    printf("7.导入信息.\n");
    printf("8.帮助.\n");
    printf("9.退出系统!\n");
    printf("********************************************************************************\n");
    }

   int enter(struct student stu[])
    {
        int i,k;
        for(i=j;i<=j;i++)
        {
            j++;
            printf("**********************************录入学生**************************************\n");
            printf("第%d个学生:\n",j);
            printf("学号:\n");
            scanf("%d",&stu[i].num);
    /*    for(x=1;x<=j;x++)
            {
                if(stu[x].num==stu[i].num)
                {
                printf("学号重复了!请重新录入!\n");
                printf("第%d个学生:\n",j);
                printf("学号:\n");
                scanf("%d",&stu[i].num);
                i--;
                x--;
                break;
                }
            }*/
            printf("姓名:\n");
            scanf("%s",stu[i].name);
            printf("年龄:\n");
            scanf("%s",&stu[i].age);
            printf("性别(m/w):\n");
           scanf("%s",stu[i].sex);
            printf("出生日期 年.月.日:\n");
            scanf("%s",stu[i].brithday);
            printf("籍贯:\n");
            scanf("%s",stu[i].nation);
            printf("家庭地址:\n");
            scanf("%s",stu[i].addr);
            printf("电话:\n");
            scanf("%s",stu[i].phone);
            printf("\n");
            printf("*********************输入R退回主菜单,按ENTER继续录入****************************\n");
            _beep(600,200);
           getchar();
            if((k=getchar())=='R')
            {
                system ("cls");
               main();
                break;
            }
    }
        return 0;
}

void menu2()
{   
    printf("*******************************查询学生信息*************************************\n");
    printf("请按1~3选择:\n");
    printf("1.显示所有学生信息\n");
    printf("2.搜索学号查询\n");
    printf("3.搜索姓名查询\n");
    printf("4.退回主菜单\n");
    printf("*******************************查询学生信息*************************************\n");
}

    void scan()
{        char b;
        menu2();
        
        b=getche();
    switch(b)
    {   case '1':system("cls"); print(stu) ;break;
        case '2':system("cls"); scanno(stu);break;
        case '3': system("cls");scanname(stu);break;
        case '4': system("cls");main();break;
        default: system ("cls");
        _beep(300,200);
        _beep(200,200);
        _beep(100,200);
        printf("请重新选择:\n");
        scan();
    }
}

    void print(struct student stu[])
    {   int n;
        if(j>0)
    {
        for (n=0;n<j;n++)
        {
            {
            printf("学号:%d\n",stu[n].num);
            printf("姓名:%s\n",stu[n].name);
            printf("年龄:%s\n",stu[n].age);
            printf("性别(m/w):%s\n",stu[n].sex);
            printf("出生日期 年.月.日:%s\n",stu[n].brithday);
            printf("籍贯:%s\n",stu[n].nation);
            printf("家庭地址:%s\n",stu[n].addr);
            printf("电话:%s\n",stu[n].phone);
            printf("*******************************查询学生信息*************************************\n");
            system("PAUSE");
            system("cls");
            }
            if(n==(j-1))
            {
            printf("\n以上是全部学生信息!\n");
            system("PAUSE");
            system("cls");
            scan();
            }
        }
    }
        else
        {
            system("cls");
            printf("\n无学生信息,请输入学生信息!!!!\n");
            _beep(400,500);
            system("PAUSE");
            system("cls");
            scan();
            }
}

  void scanno(struct student stu[])
{
    int i,a,z=-1;
    printf("\n请输入要查询的学号:\n");
    scanf("%d",&a);
    for(i=0;i<j;i++)
    {
        if(a==stu[i].num)z=i;
    }
       if(z!=-1)
        {
        printf("学号:%d\n",stu[z].num);
        printf("姓名:%s\n",stu[z].name);
        printf("年龄:%s\n",stu[z].age);
        printf("性别(m/w):%s\n",stu[z].sex);
        printf("出生日期 年.月.日:%s\n",stu[z].brithday);
        printf("籍贯:%s\n",stu[z].nation);
        printf("家庭地址:%s\n",stu[z].addr);
        printf("电话:%s\n",stu[z].phone);
        printf("*******************************查询学生信息*************************************\n");
        system("PAUSE");
        system("cls");
        scan();
        }
        else
        {
             printf("无此学生信息!按任意键返回\n");
             system("PAUSE");
             system("cls");
             scan();
            }
  }

    void scanname(struct student stu[])
    {
        char a[5];
        int i,n;
        printf("\n请输入要查询的姓名:\n");
        scanf("%s",a);
        for(i=0;i<j;i++)
        {
            if(!strcmp(a,stu[i].name))
            break;
        }
        n=(!strcmp(a,stu[i].name));
        if(n==1)
        {
        printf("学号:%d\n",stu[i].num);
        printf("姓名:%s\n",stu[i].name);
        printf("年龄:%s\n",stu[i].age);
        printf("性别(m/w):%s\n",stu[i].sex);
        printf("出生日期 年.月.日:%s\n",stu[i].brithday);
        printf("籍贯:%s\n",stu[i].nation);
        printf("家庭地址:%s\n",stu[i].addr);
        printf("电话:%s\n",stu[i].phone);
        printf("*******************************查询学生信息*************************************\n");
        system("PAUSE");
        system("cls");
        scan();
        }
        else
        {
             printf("无此学生信息!按任意键返回\n");
             system("PAUSE");
             system("cls");
             scan();
        }
}

    void menu3()
    {
    printf("*******************************修改学生信息*************************************\n");
    printf("请按1~2选择:\n");
    printf("1.搜索学号修改\n");
    printf("2.搜索姓名修改\n");
    printf("3.退回主菜单\n");
    printf("*******************************修改学生信息*************************************\n");
    }

  void change(struct student stu[])
    {  
      char b;
        menu3();
        b=getche();
    switch(b)
    {
        case '1':system("cls");
        {
            int k,i,a,z=-1;
            printf("\n请输入要修改的学号:\n");
            scanf("%d",&a);
            for(i=0;i<j;i++)
            {
            if(a==stu[i].num)
                z=i;
             }
        if(z!=-1)
        {
            printf("此学生信息为:\n");
            printf("学号:%d\n",stu[z].num);
            printf("姓名:%s\n",stu[z].name);
            printf("年龄:%s\n",stu[z].age);
            printf("性别(m/w):%s\n",stu[z].sex);
            printf("出生日期 年.月.日:%s\n",stu[z].brithday);
            printf("籍贯:%s\n",stu[z].nation);
            printf("家庭地址:%s\n",stu[z].addr);
            printf("电话:%s\n",stu[z].phone);
            printf("*******************************修改学生信息*************************************\n");
            printf("请输入此学生新信息:\n");
            printf("学号:\n");
            scanf("%d",&stu[z].num);
            printf("姓名:\n");
            scanf("%s",stu[z].name);
            printf("年龄:\n");
            scanf("%s",stu[z].age);
            printf("性别(m/w):\n");
            scanf("%s",stu[z].sex);
            printf("出生日期 年.月.日:\n");
            scanf("%s",stu[z].brithday);
            printf("籍贯:\n");
            scanf("%s",stu[z].nation);
            printf("家庭地址:\n");
            scanf("%s",stu[z].addr);
            printf("电话:\n");
            scanf("%s",stu[z].phone);
            printf("\n");
            printf("*****************修改完成!输入R退回主菜单,按ENTER返回修改菜单*****************\n");
           getchar();
            if((k=getchar())=='R')
            {
                system ("cls");
               main();
                break;
            }
        }
            if(z==-1);
            {
            system("cls");
            printf("\n无学生信息,请输入学生信息!!!!\n");
            system("PAUSE");
            system("cls");
            change(stu);
            }
           system("cls");
            change(stu);
}break;
        case '2': system("cls");
        {    char a[5];
        int i,n,k;
        printf("\n请输入要修改的姓名:\n");
        scanf("%s",a);
        for(i=0;i<j;i++)
        {
            if(!strcmp(a,stu[i].name))
            break;
        }
        n=(!strcmp(a,stu[i].name));
        if(n==1)
        {
        printf("学号:%d\n",stu[i].num);
        printf("姓名:%s\n",stu[i].name);
        printf("年龄:%s\n",stu[i].age);
        printf("性别(m/w):%s\n",stu[i].sex);
        printf("出生日期 年.月.日:%s\n",stu[i].brithday);
        printf("籍贯:%s\n",stu[i].nation);
        printf("家庭地址:%s\n",stu[i].addr);
        printf("电话:%s\n",stu[i].phone);
       printf("*******************************修改学生信息*************************************\n");
        printf("请输入此学生新信息:\n");
            printf("学号:\n");
            scanf("%d",&stu[i].num);
            printf("姓名:\n");
            scanf("%s",stu[i].name);
            printf("年龄:\n");
            scanf("%s",stu[i].age);
            printf("性别(m/w):\n");
           scanf("%s",stu[i].sex);
            printf("出生日期 年.月.日:\n");
            scanf("%s",stu[i].brithday);
            printf("籍贯:\n");
            scanf("%s",stu[i].nation);
            printf("家庭地址:\n");
            scanf("%s",stu[i].addr);
            printf("电话:\n");
            scanf("%s",stu[i].phone);
            printf("\n");
           printf("*****************修改完成!输入R退回主菜单,按ENTER返回修改菜单*****************\n");
           getchar();
            if((k=getchar())=='R')
            {
                system ("cls");
               main();
                break;
            }
        system("PAUSE");
        system("cls");
        change(stu);
        }
        else
        {
             printf("无此学生信息!按任意键返回\n");
             system("PAUSE");
             system("cls");
             change(stu);
        }
}break;
        case '3': system("cls");main();break;
        default: system ("cls");
        printf("请重新选择:\n");
        change(stu);
    }
}

   void paixu(struct student stu[])
    {
        int i,k,n;
        char t[30];
        for(i=0;i<j;i++)
        for(k=0;k<j-i-1;k++)
        {
        if(stu[k].num>stu[k+1].num)
          {
            n=stu[k].num;//学号调换
            stu[k].num=stu[k+1].num;
            stu[k+1].num=n;
            strcpy (t,stu[k].name);//名字调换
            strcpy (stu[k].name,stu[k+1].name);
            strcpy(stu[k+1].name,t);
            strcpy (t,stu[k].age);//年龄调换
            strcpy (stu[k].age,stu[k+1].age);
            strcpy(stu[k+1].age,t);
            strcpy(t,stu[k].sex);//性别调换
            strcpy (stu[k].sex,stu[k+1].sex);
            strcpy(stu[k+1].sex,t);
            strcpy(t,stu[k].brithday);//生日调换
            strcpy (stu[k].brithday,stu[k+1].brithday);
            strcpy(stu[k+1].brithday,t);
            strcpy(t,stu[k].nation);//籍贯调换
            strcpy(stu[k].nation,stu[k+1].nation);
            strcpy(stu[k+1].nation,t);
            strcpy(t,stu[k].addr); //地址调换
            strcpy(stu[k].addr,stu[k+1].addr);
            strcpy(stu[k+1].addr,t);
            strcpy(t,stu[k].phone);
            strcpy(stu[k].phone,stu[k+1].phone);
            strcpy(stu[k+1].phone,t);
            }
        }
        printf("\n排序完成!\n");
        system("PAUSE");
        system("cls");
       main();
    }

    void delete_xh (  )
    {   int i,z=-1,a,t;
        char k;
         printf("请输入学生学号:\n");
         scanf("%d",&a);
            for(i=0;i<j;i++)
            {
            if(a==stu[i].num)
                z=i;
             }
        if(z!=-1)
        {
            {
            printf("*****************************!删除学生信息!***********************************\n");
            printf("此学生信息为:\n");
            printf("学号:%d\n",stu[z].num);
            printf("姓名:%s\n",stu[z].name);
            printf("年龄:%s\n",stu[z].age);
            printf("性别(m/w):%s\n",stu[z].sex);
            printf("出生日期 年.月.日:%s\n",stu[z].brithday);
            printf("籍贯:%s\n",stu[z].nation);
            printf("家庭地址:%s\n",stu[z].addr);
            printf("电话:%s\n",stu[z].phone);
               for(;z<j;z++)
            {
            stu[z].num=stu[z+1].num;
            strcpy (stu[z].name,stu[z+1].name);
            strcpy (stu[z].age,stu[z+1].age);
            strcpy (stu[z].sex,stu[z+1].sex);
            strcpy (stu[z].brithday,stu[z+1].brithday);
            strcpy (stu[z].nation,stu[z+1].nation);
            strcpy (stu[z].addr,stu[z+1].addr);
            strcpy (stu[z].phone,stu[z+1].phone);
            }
            j--;
             printf("\n*****************删除完成!按ENTER返回删除菜单*********************************\n");
            }
    }
            else
            printf("\n无此学生信息!!!!\n");
            system("PAUSE");
             system("cls");
            main ( );
            if(z==-1)
            {
            system("cls");
            printf("\n无此学生信息!!!!\n");
            system("PAUSE");
            system("cls");
            main();
            }
}
void save(struct student stu[])
{   FILE *fp;
    int i;
    if((fp=fopen("学生信息.txt","wb"))==NULL)
    {   printf("不能打开\n");
        return;
        }
    else
    {
        fwrite(stu,sizeof(struct student),j,fp);
        fclose(fp);
        printf("OK,保存完毕!任意键返回。");
        getch();
        system("cls");
        main();
        }
}
void load(struct student stu[])
{
         FILE *fp;
         int i=0;
        if((fp=fopen("学生信息.txt","rb"))==NULL)
        {   printf("打不开文件!\n");
           main();
            }
        else
    {   if(fp!=NULL)
        while(!feof(fp))
            {   fread(stu+i,sizeof(struct student),1,fp);
                i++;
                }
        fclose (fp);
        i--;
        printf("读取成功!读取了%d个记录,任意键返回!",i);
        j = i;
        getch();
        system("cls");
        main();
    }
return --i;
}
void password()
{
     long b;
      printf ("请输入管理员密码!\n");
      scanf ("%d",&b);
      if (b!=123456)
      {printf ("密码错误!\n");return;}
      else
       printf ("密码正确!欢迎进入系统o(∩_∩)o,请输入");
      

}

void help()
{
    printf("1.首次使用本系统时录入学生信息后请及时保存!\n");
    printf("2.保存文件默认路径和本软件是同一路径,文件名为“学生信息”.\n");
    printf("3.用本系统录入过信息且保存成功,再次查看学生信息时,请先导入数据后再查看\n");
    printf("4.本系统仅限交流之用,严禁用于商业,版权所有。\n\t\t\t\t\t\t编者:孙宇洪\n\t\t\t\t\t\t2009.11.23\n");
    system("PAUSE");
    system("cls");
    main();
    }




说明:我编写了password函数,如何将输入的密码转换成星号
搜索更多相关主题的帖子: 小小的 
2010-06-23 19:04
广陵绝唱
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:29
帖 子:3607
专家分:1709
注 册:2008-2-15
收藏
得分:0 
在 TC 下有个 getch 函数,可以不回显输入.头文件为 conio.h .


如果在 linux 或是 vc 下,有请高手作答了.
2010-06-23 19:09
sunyh1999
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:14
帖 子:1178
专家分:3032
注 册:2009-5-17
收藏
得分:0 
那么具体如何实现,请高手指点

欢迎来到我的博客:http://blog..cn/noisunyuhong
2010-06-23 19:10
BlueGuy
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:29
帖 子:4476
专家分:4055
注 册:2009-4-18
收藏
得分:0 
回复 楼主 sunyh1999
说错了 ,/

[ 本帖最后由 BlueGuy 于 2010-6-24 08:28 编辑 ]

我就是真命天子,顺我者生,逆我者死!
2010-06-23 21:54
huxiangwenhu
Rank: 4
等 级:业余侠客
威 望:1
帖 子:191
专家分:262
注 册:2010-6-1
收藏
得分:0 
回复 4楼 BlueGuy
期待把代码写出来,呵呵,共同学习
2010-06-23 22:32
BlueGuy
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:29
帖 子:4476
专家分:4055
注 册:2009-4-18
收藏
得分:0 
回复 楼主 sunyh1999
就我了解,c 标准库是做不到这一点的, 我想你得接收键值。根据键值来绘制字符。

我就是真命天子,顺我者生,逆我者死!
2010-06-24 08:50
lijm1989
Rank: 11Rank: 11Rank: 11Rank: 11
来 自:珠海
等 级:贵宾
威 望:12
帖 子:675
专家分:2844
注 册:2009-10-14
收藏
得分:0 
回复 6楼 BlueGuy
好像他已经用了有非标准的了。。看代码应该是用VC。。。getch()够了···
2010-06-24 22:08
skio
Rank: 1
等 级:新手上路
帖 子:6
专家分:3
注 册:2010-6-14
收藏
得分:0 
类似于:
#include<stdio.h>
main()
{
    char password[16];
    int i=0;
    while(1)
    {
        password[i]=getch();
        if(password[i]=='\r')
            break;
        i++;
        printf("*");
    }
    password[i]='\0';
}
2010-07-04 12:10
快速回复:向高手问一个小小的问题
数据加载中...
 
   



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

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