| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 541 人关注过本帖
标题:数据结构课程设计::在运行程序的时候:系统中已存在数据库,不能建立新的 ...
只看楼主 加入收藏
长治C
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2015-11-28
结帖率:0
收藏
已结贴  问题点数:20 回复次数:4 
数据结构课程设计::在运行程序的时候:系统中已存在数据库,不能建立新的数据库!
/* 职工工资管理系统:
字段:编号,姓名,年龄,性别,基础工资,补贴工资,扣除工资,总工资。
职工工资管理系统(编号,姓名,年龄,性别,基础工资,补贴工资,扣除工资,总工资){密码启动修改模块,数据保存读入模块,数据录入模块,数据查找模块(按编号查询,姓名(包括模糊)查询),数据插入模块,数据统计模块(分别统计基础工资总数,补贴工资总数,扣除工资总数,总工资),数据删除模块,数据排序模块,总共八个模块}  
要求:(1): 总工资数由算法自动计算。(2): 当系统中存在一个数据库时,不能重新建立新数据库或不能从磁盘中读取新的数据库。(3):将数据库的内容用文件的型式输出到文本文件中。(4):采用无头结点的单链表利用类型定义二。*/
现在给的警告:

Compiling...
张强 44.c
C:\Users\Administrator\Desktop\张强 44.c(130) : warning C4700: local variable 'h' used without having been initialized

在运行程序的时候:系统中已存在数据库,不能建立新的数据库!


# include<stdlib.h>
# include<string.h>
# include<stdio.h>
# include<conio.h>

typedef struct node
{/* 结点定义 */
   char numb[15];  /* 职工编号 */
   char name[15];  /* 职工姓名 */
   int age;        /* 职工年龄 */
   char sex[2];    /* 职工性别 */
   double jcgz;    /* 基础工资 */
   double btgz;    /* 补贴工资 */
   double kcgz;    /* 扣除工资 */
   double zgz;     /* 总工资 */
   struct node *next;  /*结构指针*/
}LNode,*Link;


typedef struct link
{/* 链表定义 */
   Link head,tail;
}Linklist;



/* 函数说明 */
  int menu_select();    /* 主程序选择菜单 */
  int menu_delselect();    /* 删除选择菜单 */
  int menu_inselect();    /* 插入选择菜单 */
  int menu_findselect();    /* 查找选择菜单 */
  void menu_prog(Linklist h);     /* 主程序执行菜单 */
  void menu_delprog(Linklist *h);     /* 删除执行菜单 */
  void menu_inprog(Linklist *h);     /* 插入执行菜单 */
  void menu_findprog(Linklist h);     /* 查找执行菜单 */
  void playpasword(char *s); /* 密码采用*号表示 */
  void setpasword();    /* 建立密码 */
  void madpasword();    /* 修改密码 */
  void save(Linklist h);    /* 保存文件 */
  void load(Linklist *h);    /* 装载文件 */

  void inilink(Linklist *h);    /* 初始化 */
  void setlink(Linklist *h);      /* 建立链表 */
  void printlink(Linklist h);    /* 输出链表 */
  void distroylink(Linklist *h);  /* 消链表 */
  void insert(Linklist *h);       /* 插入数据 */
  void inserts(Linklist *h);       /* 插入任意位置数据 */
  void delnumb(Linklist *h);      /* 删除编号 */
  void delname(Linklist *h);      /* 删除姓名 */
  LNode *findnumb(Linklist h);   /* 查找编号 */
  LNode *findname(Linklist h,char strname[],LNode *nexts);  /* 查找姓名 */
  void sortdata(Linklist *h);     /* 数据排序 */
  void madedata(Linklist *h);                /* 修改数据 */
  void sortsdata(Linklist h);               /* 数据统计 */
  int flagint(char strnum[]);           /* 判字串中是否均为数字 */
  int flagints(char strnum[]);           /* 判字串中是*/


main()
{/*主程序*/
   Linklist h;
   FILE *fp;
   Link head;//定义一个文件类型的指针
   char cha[20],chb[20];
   int i=0;
   fp=fopen("pasword.exe","rb");      //以rb(二进制)形式读取文件
   if(fp==NULL) setpasword();         //建立密码
     else fclose(fp);
   head=NULL;  /* 头指针初值为空 */
   system("cls"); /* 清屏 */
   printf("\n");
   printf("\n");
   printf("\n");
   printf("\n");
   printf("\n");
   printf("\n");
   printf("\n");
   printf("                     ************************************ \n");
   printf("                     *                                  * \n");
   printf("                     *      数据结构课程设计实例        * \n");
   printf("                     *                                  * \n");
   printf("                     *        职工工资管理系统          * \n");
   printf("                     *          (无头单链表)            * \n");
   printf("                     *                                  * \n");
   printf("                     *          作者:张强              * \n");
   printf("                     *                                  * \n");
   printf("                     *          2015年11月14日          * \n");
   printf("                     *                                  * \n");
   printf("                     *         初始密码: 1234           * \n");
   printf("                     *                                  * \n");
   printf("                     *                                  * \n");
   printf("                     ************************************ \n");
   printf("\n");
   printf("\n");
   fp=fopen("pasword.exe","rb");
   fgets(cha,81,fp);
   printf("                              请输入密码 : ");
   playpasword(chb);      //密码采用*号表示
   while(strcmp(cha,chb)<0 || strcmp(cha,chb)>0)
    {
      i++;
      if(i==3)
       {
      printf("\n");
      printf("\n");
      printf("\n");
      printf("\n");
      printf("                     ************************************ \n");
      printf("                     *                                  * \n");
      printf("                     *        密码错误无权使用!!!       * \n");
      printf("                     *                                  * \n");
      printf("                     *               谢谢               * \n");
      printf("                     *                                  * \n");
      printf("                     *                                  * \n");
      printf("                     *                                  * \n");
      printf("                     *            2015年11月14日        * \n");
      printf("                     *                                  * \n");
      printf("                     ************************************ \n");
      printf("\n");
      printf("\n");
      scanf("%*c");
      exit(0);
       }
      printf("                     密码错误!!!\n");
      printf("                     请输入密码 :");
      playpasword(chb);
    }
   menu_prog(h);
}

void menu_prog(Linklist h)
{ /* 主程序选项菜单执行系统 */
  char ch;
  for (;;)
    {
      switch(menu_select())
       {
     case 1:
        if(h.head!=NULL)
          {
             printf("\n系统中已经存在数据库!不能新建立数据库!!!");
             printf("\n请退出系统后重新操作!!!");
             printf("\n");
             printf("按任意键继续.........");
             getchar();
             break;
          }
        else {
            inilink(&h); /* 初始化链表算法 */
            setlink(&h);  /* 建立链表算法 */
            if(h.head!=NULL && h.head->next!=NULL) printlink(h); /* 输出链表算法 */
             else if(h.head->next==NULL)
                {
                    free(h.head);  h.head=NULL;
                }
            printf("\n");
            printf("按任意键继续.........");
            getchar();
            break;
              }
     case 2:
              if(h.head==NULL) printf("请先建立链表后再进行操作!");
                 else {
            printlink(h); /* 显示数据算法 */
                        printf("\n");
                      }
                printf("按任意键继续.........");
                getchar();
                break;
     case 3:
              if(h.head==NULL) printf("请先建立链表后再进行操作!");
                 else {
            menu_delprog(&h);    /* 调用删除窗口 */
                      }
                printf("按任意键继续.........");
                getchar();
                break;
     case 4:
              if(h.head==NULL) printf("请先建立链表后再进行操作!");
                 else {
            menu_inprog(&h);   /* 调用插入窗口 */
                      }
                printf("按任意键继续.........");
                getchar();
                break;
     case 5:
              if(h.head==NULL) printf("请先建立链表后再进行操作!");
                 else {
             menu_findprog(h);   /* 调用查找窗口 */
                      }
                printf("按任意键继续.........");
                getchar();
                break;
     case 6:
              if(h.head==NULL) printf("请先建立链表后再进行操作!");
                 else {
            madedata(&h);    /* 修改算法 */
                      }
                printf("按任意键继续.........");
                getchar();
                break;
     case 7:
              if(h.head==NULL) printf("请先建立链表后再进行操作!");
                 else {
            sortdata(&h);    /* 排序算法 */
                      }
                printf("按任意键继续.........");
                getchar();
                break;
     case 8:
              if(h.head==NULL) printf("请先建立链表后再进行操作!");
                 else {
            sortsdata(h);    /* 统计算法 */
                      }
                printf("按任意键继续.........");
                getchar();
                break;
     case 9:
        madpasword(); /* 修改密码 */
                printf("按任意键继续.........");
                getchar();
                break;
     case 10:
        save(h);  /* 将程序中数据保存到磁盘文件中 */
                printf("按任意键继续.........");
                getchar();
                break;
     case 11:
        if(h.head!=NULL)
          {
             printf("\n系统中已经存在数据库!不能打开新数据库!!!");
             printf("\n请退出系统后重新操作!!!");
             printf("\n");
             printf("按任意键继续.........");
             getchar();
             break;
          }
         else {
             inilink(&h);
                         load(&h); /* 将磁盘文件内容装载到内存中 */
             printf("按任意键继续.........");
             getchar();
             break;
              }
     case 12:
                if(h.head!=NULL)
                   {
                      printf("\n是否保存内存中的数据?(y/n): ");
              scanf("%c%*c",&ch);
                      if(ch=='y') save(h);  /* 将程序中数据保存到磁盘文件中 */
              distroylink(&h);
                    }
                exit(0);
       }
    }
}

void menu_delprog(Linklist *h)
{ /* 删除选项菜单执行系统 */
   int i;
  for(;;)
   {
     i=menu_delselect();
     switch(i)
       {
     case 1:
              if(h->head==NULL) printf("请先建立链表后再进行操作!");
                 else {
            delnumb(h);  /* 删除编号算法 */
                      }
                printf("按任意键继续.........");
                getchar();
                break;
     case 2:
              if(h->head==NULL) printf("请先建立链表后再进行操作!");
                 else {
             delname(h);   /* 删除姓名算法 */
                      }
                printf("按任意键继续.........");
                getchar();
                break;
     case 3:
              break;
       }
    if(i==3) break;
  }
}

void menu_inprog(Linklist *h)
{ /* 插入选项菜单执行系统 */
  int i;
  for(;;)
   {
     i=menu_inselect();
     switch(i)
       {
     case 1:
              if(h->head==NULL) printf("请先建立链表后再进行操作!");
                 else {
            insert(h);  /* 插入数据算法 */
                      }
                printf("按任意键继续.........");
                getchar();
                break;
     case 2:
              if(h->head==NULL) printf("请先建立链表后再进行操作!");
                 else {
            inserts(h);  /* 插入数据算法 */
                      }
                printf("按任意键继续.........");
                getchar();
                break;
     case 3:
              break;
       }
    if(i==3) break;
  }
}

void menu_findprog(Linklist h)
{ /* 选项菜单执行系统 */   
  Link p;
  char ch,chs,sname[15];
  int i;
  for(;;)
   {
     i=menu_findselect();
     switch(i)
       {
     case 1:
              if(h.head==NULL) printf("请先建立链表后再进行操作!");
         else { /* 编号查找算法 */
             ch='y';
             while(ch=='y')
               {
                  p=findnumb(h);   /* 从头沿 next 查找 */
                  if(p!=NULL)
                {
                   printf("编号      姓名     年龄  性别   基础工资   补贴工资   扣除工资   总工资\n");
                   printf("%s%8s%6d%6s%11.2f%11.2f%11.2f%11.2f\n",p->numb,p->name,p->age,p->sex,p->jcgz,p->btgz,p->kcgz,p->zgz);
                }
                   else printf("数据库中无此编号的数据!!!");
                  printf("\n是否重新查找另一个编号的记录?(y/n): ");
                  scanf("%c%*c",&ch);
               }
                      }
                printf("按任意键继续.........");
                getchar();
                break;
     case 2:
              if(h.head==NULL) printf("请先建立链表后再进行操作!");
         else { /* 姓名查找算法 */
             printlink(h);
             chs='y';  ch='y';
             while(chs=='y')
              {
                printf("请输入要查找记录的姓名: ");
                gets(sname);
                p=h.head;
                while(ch=='y')
                  {
                p=findname(h,sname,p);   /* 从 p 沿 next 查找 */
                if(p!=NULL)
                  {
                     printf("编号      姓名     年龄  性别   基础工资   补贴工资   扣除工资   总工资\n");
                     printf("%s%8s%6d%6s%11.2f%11.2f%11.2f%11.2f\n",p->numb,p->name,p->age,p->sex,p->jcgz,p->btgz,p->kcgz,p->zgz);
                     printf("\n是否继续查找相同姓名的记录?(y/n): ");
                     scanf("%c%*c",&ch);
                     if(ch=='y') p=p->next;   /* 沿 next 查找 */
                  }
                else {
                    printf("查找结束或该数据库中无此姓名的记录!!!");
                    break;
                     }
                  }
                printf("\n是否重新进行查找操作?(y/n): ");
                scanf("%c%*c",&chs);
             }
                      }
                printf("按任意键继续.........");
                getchar();
                break;
     case 3:
              break;
       }
     if(i==3) break;
   }
}

int menu_select()
{   /* 主程序选择菜单 */
   char s[8];
   int c;
   system("cls");   /* 清屏 */
   printf("\n");
   printf("\n");
   printf("                     ************************************ \n");
   printf("                     *                                  * \n");
   printf("                     *                                  * \n");
   printf("                     *     无头单向链表基本操作窗口     * \n");
   printf("                     *                                  * \n");
   printf("                     *                                  * \n");
   printf("                     ************************************ \n");
   printf("\n");
    printf("                            01:职工工资库的建立操作\n");
    printf("                            02:职工工资库的显示操作\n");
    printf("                            03:职工工资库的删除操作\n");
    printf("                            04:职工工资库的插入操作\n");
    printf("                            05:职工工资库的查找操作\n");
    printf("                            06:职工工资库的修改操作\n");
    printf("                            07:职工工资库的排序操作\n");
    printf("                            08:职工工资库的统计操作\n");
    printf("                            09:修改系统的密码操作\n");
    printf("                            10:将数据存入磁盘文件\n");
    printf("                            11:将磁盘文件装入内存\n");
    printf("                            12:退出系统\n");
   do {
    printf("\n");
    printf("                           输入你的选择号:1---12: ");
    gets(s);
    c=atoi(s);
      }while(c<0||c>12);
   return(c);
}

int menu_delselect()
{  /* 删除菜单系统 */
   char s[8];
   int c;
   system("cls");   /* 清屏 */
   printf("\n");
   printf("\n");
   printf("                     ************************************ \n");
   printf("                     *                                  * \n");
   printf("                     *                                  * \n");
   printf("                     *     职工工资库的删除操作窗口     * \n");
   printf("                     *                                  * \n");
   printf("                     *                                  * \n");
   printf("                     ************************************ \n");
   printf("\n");
    printf("                               01:按编号删除记录\n");
    printf("                               02:按姓名删除记录\n");
    printf("                               03:退出\n");
   do {
    printf("\n");
    printf("                             输入你的选择号:1---3: ");
    gets(s);
    c=atoi(s);
      }while(c<0||c>3);
   return(c);
}

int menu_inselect()
{  /* 插入菜单系统 */
   char s[8];
   int c;
   system("cls");   /* 清屏 */
   printf("\n");
   printf("\n");
   printf("                     ************************************ \n");
   printf("                     *                                  * \n");
   printf("                     *                                  * \n");
   printf("                     *     职工工资库的插入操作窗口     * \n");
   printf("                     *                                  * \n");
   printf("                     *                                  * \n");
   printf("                     ************************************ \n");
   printf("\n");
    printf("                               01:插入到数据库尾部\n");
    printf("                               02:插入到任意位置处\n");
    printf("                               03:退出\n");
   do {
    printf("\n");
    printf("                             输入你的选择号:1---3: ");
    gets(s);
    c=atoi(s);
      }while(c<0||c>3);
   return(c);
}

int menu_findselect()
{  /* 查找菜单系统 */
   char s[8];
   int c;
   system("cls");  /* 清屏 */
   printf("\n");
   printf("\n");
   printf("                     ************************************ \n");
   printf("                     *                                  * \n");
   printf("                     *                                  * \n");
   printf("                     *     职工工资库的查找操作窗口     * \n");
   printf("                     *                                  * \n");
   printf("                     *                                  * \n");
   printf("                     ************************************ \n");
   printf("\n");
    printf("                               01:按编号查找记录\n");
    printf("                               02:按姓名查找记录\n");
    printf("                               03:退出\n");
   do {
    printf("\n");
    printf("                             输入你的选择号:1---3: ");
    gets(s);
    c=atoi(s);
      }while(c<0||c>3);
   return(c);
}

void setpasword()
{ /* 建立初始密码 */
   FILE *fp;  char chs[20]="1234";
   fp=fopen("pasword.exe","wb");
   fputs(chs,fp);
   fclose(fp);
}

void playpasword(char *s)
{ /* 密码采用*号表示 */
  int i=0;
  while(1)
  {
    s[i]=getch();
    if(s[i]==13) break;
    i++;
    printf("*");
  }
  s[i]='\0';
}

void madpasword()
{ /* 密码修改系统 */
   FILE *fp;
   char cha[20],chb[20],chc[20],chd[20];
   int i=0;
   fp=fopen("pasword.exe","rb");
   fgets(cha,81,fp);
   fclose(fp);
   system("cls");   /* 清屏 */
   printf("\n");
   printf("\n");
   printf("\n");
   printf("\n");
   printf("\n");
   printf("\n");
   printf("\n");
   printf("                     ************************************ \n");
   printf("                     *                                  * \n");
   printf("                     *                                  * \n");
   printf("                     *      课程序设计密码修改窗口      * \n");
   printf("                     *                                  * \n");
   printf("                     *                                  * \n");
   printf("                     *                                  * \n");
   printf("                     ************************************ \n");
   printf("\n");
   printf("\n");
   printf("                     请输入密码 : ");
   playpasword(chb);
   if(strcmp(cha,chb)==0)
    {
      printf("\n                     输入新密码 : "); playpasword(chc);
      printf("\n                     确认新密码 : "); playpasword(chd);
      while(strcmp(chc,chd)<0 || strcmp(chc,chd)>0)
       {
     i++;
     if(i==3)
      {
        printf("\n\n");
        printf("                                密码修改失败!!!"); return;
      }
        printf("\n                     输入新密码 : "); playpasword(chc);
        printf("\n                     确认新密码 : "); playpasword(chd);
       }
       if(strcmp(chc,chd)==0)
       {
     fp=fopen("pasword.exe","wb");
     fputs(chd,fp);
     fclose(fp);
     printf("\n\n");
     printf("                               密码修改成功!!!!");
       }
     }
     else {
         printf("\n");
         printf("\n");
         printf("                     ************************************ \n");
         printf("                     *                                  * \n");
         printf("                     *                                  * \n");
         printf("                     *        密码错误无权修改!!        * \n");
         printf("                     *                                  * \n");
         printf("                     *               谢谢               * \n");
         printf("                     *                                  * \n");
         printf("                     *    如想使用本软件请与作者联系    * \n");
         printf("                     *                                  * \n");
         printf("                     *                                  * \n");
         printf("                     ************************************ \n");
         printf("\n");
         printf("\n");
         scanf("%*c");
         return;
      }
}

void save(Linklist h)
{ /* 在当前目录中保存任意名字的文件 */
   LNode *p;  char str[15];
   FILE *fp;
   system("cls");  /* 清屏 */
   printf("\n");
   printf("\n");
   printf("                     ************************************ \n");
   printf("                     *                                  * \n");
   printf("                     *                                  * \n");
   printf("                     *      课程设计单链表存盘窗口      * \n");
   printf("                     *                                  * \n");
   printf("                     *                                  * \n");
   printf("                     *                                  * \n");
   printf("                     ************************************ \n");
   printf("\n");
   printf("\n");
   if(h.head==NULL) {
             printf("                      系统中没有链表存在!!!\n");
             printf("                      请先建链表后再存盘!!!\n");
          }
    else {
       printf("                     输入存盘文件名(可带路径) : ");  gets(str);
       fp=fopen(str,"wb");
       printf("\n                      单链表文件 %s 存盘成功!!!\n",str);
       p=h.head;
       while(p!=NULL)
        {
          fwrite(p,sizeof(LNode),1,fp);
          p=p->next;
        }
       fclose(fp);
     }
  printf("\n\n");
  printf("                     按任意键返回到主窗口!");
  scanf("%*c");
}

void load(Linklist *h)
{  /* 装载文件 */
   LNode *p,*q=NULL;   char str[30];
   FILE *fp;  int i=0;
   system("cls");   /* 清屏 */
   printf("\n");
   printf("\n");
   printf("                     ************************************ \n");
   printf("                     *                                  * \n");
   printf("                     *                                  * \n");
   printf("                     *    课程设计双链表文件载入窗口    * \n");
   printf("                     *                                  * \n");
   printf("                     *                                  * \n");
   printf("                     *                                  * \n");
   printf("                     ************************************ \n");
   printf("\n");
   printf("\n");
   printf("                     输入载入磁盘文件名(可带路径) : ");  gets(str);
   fp=fopen(str,"rb");
   while(fp==NULL)
    {  i++;
       if(i==3)
    {
      printf("\n");
      printf("\n");
      printf("\n");
      printf("\n");
      printf("                     ************************************ \n");
      printf("                     *                                  * \n");
      printf("                     *                                  * \n");
      printf("                     *      请建立新链表后存盘保存      * \n");
      printf("                     *                                  * \n");
      printf("                     *        选择新磁盘文件载入        * \n");
      printf("                     *                                  * \n");
      printf("                     *                                  * \n");
      printf("                     ************************************ \n");
      printf("\n");
      printf("\n");
      scanf("%*c");
      exit(0);
    }
       printf("                     磁盘文件 %s 不存在!\n",str);
       printf("                     输入载入磁盘文件名(可带路径) : "); gets(str);
       fp=fopen(str,"rb");
    }
   printf("\n                     磁盘文件 %s 装入内存成功!!!\n",str);
   h->head=(LNode *)malloc(sizeof(LNode));
   h->head->next=NULL;
   p=h->head;
   while(!feof(fp))
     {
       q=(LNode *)malloc(sizeof(LNode));
       if(!p)
     {
       printf("内存中无容量\n");
       return;
     }
       if(1!=fread(q,sizeof(LNode),1,fp)) break;
       q->next=p->next;
       p->next=q;
       p=q;
     }
   h->tail=p;
   p=h->head;
   h->head=h->head->next;
   free(p);
   fclose(fp);
   printf("\n\n");
   printf("                     按任意键返回到主窗口!");
   scanf("%*c");
}


int flagint(char strnum[])
{ /* 判字串中是否均为数字 */
  int i,flag=1;
  for(i=0;strnum[i]!='\0';i++)
    if(strnum[i]<'0' || strnum[i]>'9')
      {
    flag=0;  break;
      }
  return flag;
}





 
搜索更多相关主题的帖子: 运行程序 数据库 职工工资 课程 管理系统 
2015-11-28 10:16
长治C
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2015-11-28
收藏
得分:0 
回复 楼主 长治C

int flagints(char strnum[])
{ /* 判字串中是否为数字或小数点 */
  int i,flag=1;
  for(i=0;strnum[i]!='\0';i++)
    if((strnum[i]<'0'&& strnum[i]!=46) || strnum[i]>'9')
      {
    flag=0;  break;
      }
  return flag;
}

void inilink(Linklist *h)
{ /*初始化单链表*/
  h->head=NULL;
  h->tail=NULL;
}

void setlink(Linklist *h)
{ /*(采用后插法)建立单链表*/
    char numstr[15],ch;
    LNode *q,*p,*r;
    printf("是否要输入数据?(要则输入y,不要输入n)\n");
    scanf("%c%*c",&ch);
    if(ch=='y')
    {
        printf("输入编号,姓名,年龄,性别,基础工资,补贴工资,扣除工资\n\n");
        q=(LNode *)malloc(sizeof(LNode));
        q->next=NULL;
        h->head=q; p=q;
     }
    while(ch=='y')
   {
        printf("输入职工编号: ");
        gets(numstr);
        while(!strlen(numstr) || !flagint(numstr))    //判断是否输入和输入是否是数字
        {
            printf("输入编号: ");
            gets(numstr);
           }
        r=h->head;
        while(r!=NULL && !(strcmp(r->numb,numstr)==0)) r=r->next;
        if(strcmp(r->numb,numstr)==0)     //strcmp比较数值是否相同
        {
           printf("编号以经存在!是否重新录入数据?(y/n): ");
           scanf("%c%*c",&ch);
           if(ch=='y') continue;
             else break;
         }
        strcpy(q->numb,numstr);   //strcpy把编号复制到q中
        printf("输入姓名: ");
        gets(q->name);
        while(!strlen(q->name))
        {
            printf("输入姓名: ");
            gets(q->name);
        }
        printf("输入年龄: ");
        gets(numstr);
        while(!strlen(numstr) || !flagint(numstr))
        {
            printf("输入年龄: ");
            gets(numstr);
        }
        q->age=atoi(numstr);
        printf("输入性别(t/f): ");
        gets(q->sex);
        while(1)
        {
            if(strcmp("t",q->sex)==0 || strcmp("f",q->sex)==0) break;
            printf("输入性别(t/f): ");
            gets(q->sex);
        }
        printf("输入基础工资: ");
        gets(numstr);
        while(!strlen(numstr) || !flagints(numstr))
        {
            printf("输入基础工资: ");
            gets(numstr);
        }
        q->jcgz=atof(numstr);
        printf("输入补贴工资: ");
        gets(numstr);
        while(!strlen(numstr) || !flagints(numstr))
        {
            printf("输入补贴工资: ");
            gets(numstr);
        }
        q->btgz=atof(numstr);

        printf("输入扣除工资: ");
        gets(numstr);
        while(!strlen(numstr) || !flagints(numstr))
        {
            printf("输入扣除工资: ");
            gets(numstr);
        }
        q->kcgz=atof(numstr);

        q->zgz=q->jcgz+q->btgz-q->kcgz;

        if(q!=h->head)
        {
            q->next=p->next;  /*链接后继指针*/
            p->next=q;
            p=q;
            h->tail=p;
        }
        printf("是否继续录入数据?(y/n)\n");
        scanf("%c%*c",&ch);
        if(ch=='y') q=(LNode *)malloc(sizeof(LNode));
   }
}



void printlink(Linklist h)
{ /*输出线性单链表*/
   LNode *p;
   p=h.head;
   printf("编号      姓名     年龄  性别   基础工资   补贴工资   扣除工资   总工资\n");
   while(p!=NULL)
     {
       printf("%s%8s%6d%6s%11.2f%11.2f%11.2f%11.2f\n",p->numb,p->name,p->age,p->sex,p->jcgz,p->btgz,p->kcgz,p->zgz);
       p=p->next;
     }
   printf("\n");
}

void insert(Linklist *h)
{ /* 插入数据 */
   char numstr[15],ch;
   LNode *q,*p,*r;
   printf("是否插入数据?(y/n)");
   scanf("%c%*c",&ch);
   printf("输入编号,姓名,年龄,性别,基础工资,补贴工资,扣除工资\n\n");
   while(ch=='y')
   {
      printf("输入编号: ");
      gets(numstr);
      while(!strlen(numstr) || !flagint(numstr))
      {
          printf("输入编号: ");
          gets(numstr);
       }
       r=h->head;
       while(r!=NULL && !(strcmp(r->numb,numstr)==0)) r=r->next;
       if(strcmp(r->numb,numstr)==0)
       {
           printf("编号以经存在!是否重新插入数据?(y/n): ");
           scanf("%c%*c",&ch);
           if(ch=='y') continue;
             else break;
        }
        q=(LNode *)malloc(sizeof(LNode));
        strcpy(q->numb,numstr);

        printf("输入姓名: ");
        gets(q->name);
        while(!strlen(q->name))
        {
            printf("输入姓名: ");
            gets(q->name);
        }

        printf("输入年龄: ");
        gets(numstr);
        while(!strlen(numstr) || !flagint(numstr))
        {
            printf("输入年龄: ");
            gets(numstr);
        }
        q->age=atoi(numstr);

        printf("输入性别(t/f): ");
        gets(q->sex);
        while(1)
        {
            if(strcmp("t",q->sex)==0 || strcmp("f",q->sex)==0) break;
            printf("输入性别(t/f): ");
            gets(q->sex);
        }

        printf("输入基础工资: ");
        gets(numstr);
        while(!strlen(numstr) || !flagints(numstr))
        {
            printf("输入基础工资: ");
            gets(numstr);
        }
        q->jcgz=atof(numstr);

        printf("输入补贴工资: ");
        gets(numstr);
        while(!strlen(numstr) || !flagints(numstr))
        {
            printf("输入补贴工资: ");
            gets(numstr);
        }
        q->btgz=atof(numstr);

        printf("输入扣除工资: ");
        gets(numstr);
        while(!strlen(numstr) || !flagints(numstr))
        {
            printf("输入扣除工资: ");
            gets(numstr);
        }
        q->kcgz=atof(numstr);

        q->zgz=q->jcgz+q->btgz-q->kcgz;

         p=h->head;
         while(p->next!=NULL) p=p->next;

         q->next=p->next;  /*链接后继指针*/
         p->next=q;
         h->tail=q;
         printf("是否继续插入数据?(y/n)\n");
         scanf("%c%*c",&ch);
   }
}

void inserts(Linklist *h)
{ /* 插入任意位置数据 */
   char numstr[15],ch;
   LNode *q,*p,*r;
   printf("是否插入数据?(y/n)");
   scanf("%c%*c",&ch);
   printf("输入编号,姓名,年龄,性别,基础工资,补贴工资,扣除工资\n\n");
   while(ch=='y')
   {
      printf("输入编号: ");
      gets(numstr);
      while(!strlen(numstr) || !flagint(numstr))
      {
      printf("输入编号: ");
      gets(numstr);
      }
      r=h->head;
      while(r!=NULL && !(strcmp(r->numb,numstr)==0)) r=r->next;
      if(strcmp(r->numb,numstr)==0)
      {
          printf("编号以经存在!是否重新插入数据?(y/n): ");
          scanf("%c%*c",&ch);
           if(ch=='y') continue;
             else break;
       }
       q=(LNode *)malloc(sizeof(LNode));
       strcpy(q->numb,numstr);

       printf("输入姓名: ");
       gets(q->name);
       while(!strlen(q->name))
       {
           printf("输入姓名: ");
           gets(q->name);
       }

      printf("输入年龄: ");
      gets(numstr);
      while(!strlen(numstr) || !flagint(numstr))
      {
          printf("输入年龄: ");
          gets(numstr);
      }
      q->age=atoi(numstr);

      printf("输入性别(t/f): ");
      gets(q->sex);
      while(1)
      {
          if(strcmp("t",q->sex)==0 || strcmp("f",q->sex)==0) break;
          printf("输入性别(t/f): ");
          gets(q->sex);
      }

      printf("输入基础工资: ");
      gets(numstr);
      while(!strlen(numstr) || !flagints(numstr))
      {
          printf("输入基础工资: ");
          gets(numstr);
      }
      q->jcgz=atof(numstr);

      printf("输入补贴工资: ");
      gets(numstr);
      while(!strlen(numstr) || !flagints(numstr))
      {
          printf("输入补贴工资: ");
          gets(numstr);
      }
      q->btgz=atof(numstr);

      printf("输入扣除工资: ");
      gets(numstr);
      while(!strlen(numstr) || !flagints(numstr))
      {
          printf("输入扣除工资: ");
          gets(numstr);
      }
      q->kcgz=atof(numstr);

      q->zgz=q->jcgz+q->btgz-q->kcgz;


      printf("\n输入插入的位置(编号): ");
      gets(numstr);
      while(!strlen(numstr) || !flagint(numstr))
      {
          printf("输入编号: ");
          gets(numstr);
       }
       r=h->head;
       while(r!=NULL && !(strcmp(r->numb,numstr)==0)) r=r->next;
       while(r==NULL)
       {
           printf("\n该插入位置不存在!请重新输入插入的位置(编号): ");
           gets(numstr);
           while(!strlen(numstr) || !flagint(numstr))
           {
               printf("输入编号: ");
               gets(numstr);
           }
           r=h->head;
           while(r!=NULL && !(strcmp(r->numb,numstr)==0)) r=r->next;
       }

      printf("是否插入到该编号: %s 之(前/后)?(y/n): ",r->numb);
      scanf("%c%*c",&ch);
      if(ch=='y')
      {
          p=h->head;
          if(r==h->head)
             {
                 q->next=r;
                 h->head=q;
             }
            else {
                    while(p->next!=r) p=p->next;
                      q->next=r;  
                      p->next=q;  
                 }
         }
       else {
                 q->next=r->next;  /*链接后继指针*/
                 r->next=q;
                 if(r==h->tail) h->tail=h->tail->next;
       }
      printf("是否继续插入数据?(y/n)\n");
      scanf("%c%*c",&ch);
   }
}


void delnumb(Linklist *h)
{/* 按编号删除 */
  LNode *p,*q; char numb[15]; char ch,chs='y';
  printlink(*h);
  printf("\n\n");
  while(chs=='y')
    {
      printf("请输入要删除记录的编号: ");
      gets(numb);
      while(!strlen(numb) || !flagint(numb))
    {
      printf("请输入要删除记录的编号: ");
      gets(numb);
           }

      q=h->head;
      if(strcmp(q->numb,numb)==0)
    {
       printf("编号      姓名     年龄  性别   基础工资   补贴工资   扣除工资   总工资\n");
       printf("%s%8s%6d%6s%11.2f%11.2f%11.2f%11.2f\n",q->numb,q->name,q->age,q->sex,q->jcgz,q->btgz,q->kcgz,q->zgz);
       printf("\n是否删除此条记录?(y/n): ");
       scanf("%c%*c",&ch);
       if(ch=='y')
        {
           h->head=h->head->next;
          free(q);
          printf("\n此条记录已经被删除!!!");
        }
    }
       else {
           p=q->next;
           while(p!=NULL && !(strcmp(p->numb,numb)==0))
        {
          q=p;  p=p->next;
        }
           if(strcmp(p->numb,numb)==0)
        {
          printf("编号      姓名     年龄  性别   基础工资   补贴工资   扣除工资 总工资\n");
          printf("%s%8s%6d%6s%11.2f%11.2f%11.2f%11.2f\n",p->numb,p->name,p->age,p->sex,p->jcgz,p->btgz,p->kcgz,p->zgz);
          printf("\n是否删除此条记录?(y/n): ");
          scanf("%c%*c",&ch);
          if(ch=='y')
           {
             q->next=p->next;  free(p);
             printf("\n此条记录已经被删除!!!");
           }
        }
           else printf("\n该条记录不存在,无法进行删除操作!!!");
       }
       printf("\n是否继续进行删除操作?(y/n): ");
       scanf("%c%*c",&chs);
    }
    p=h->head;  /* 定位尾指针 */
  while(p->next!=NULL) p=p->next;
  h->tail=p;
}

void delname(Linklist *h)
{/* 按姓名删除 */
  LNode *p,*q; char ch,chs='y',cha,str[15];
  printlink(*h);
  printf("\n\n");
  while(chs=='y')
    {
      printf("请输入要删除记录的姓名: ");
      gets(str);
      p=h->head;
      while(p!=NULL)
    {
       if(strcmp(str,p->name)==0)
         {
        printf("编号      姓名     年龄  性别   基础工资   补贴工资   扣除工资   总工资\n");
        printf("%s%8s%6d%6s%11.2f%11.2f%11.2f%11.2f\n",p->numb,p->name,p->age,p->sex,p->jcgz,p->btgz,p->kcgz,p->zgz);
        printf("\n是否删除此条记录?(y/n): ");
        scanf("%c%*c",&ch);
        if(ch=='y')
         {
           if(p==h->head)
             {
            h->head=h->head->next;
            q=h->head;
             }
            else{
              q=h->head;
              while(q->next!=p) q=q->next;
              q->next=p->next;
            }
           free(p);
           printf("\n此条记录已经被删除!!!");
         }
        printf("\n是否继续查找相同姓名的记录?(y/n): ");
        scanf("%c%*c",&cha);
        if(cha=='y')
          if(p==NULL) p=q;
            else p=p->next;
         else break;
         }
        else{
           p=p->next;
           if(p==NULL) printf("\n该条记录不存在,无法进行删除操作!!!");
        }
    }
      printf("\n是否重新进行删除操作?(y/n): ");
      scanf("%c%*c",&chs);
    }
    p=h->head;  /* 定位尾指针 */
   while(p->next!=NULL) p=p->next;
   h->tail=p;
}

void distroylink(Linklist *h)
{ /* 链表销毁 */
  LNode *p,*q;
  p=h->head; h->head=NULL;
  while(p!=NULL)
   {
     q=p;  p=p->next;
     free(q);
   }
}

LNode *findnumb(Linklist h)
{/* 按编号查找 */
  LNode *p; char numb[15];
  printlink(h);
  printf("\n\n");
  printf("请输入要查找记录的编号: ");
  gets(numb);
  while(!strlen(numb) || !flagint(numb))
    {
       printf("请输入要查找记录的编号: ");
       gets(numb);
    }
  p=h.head;
  while(p!=NULL && !(strcmp(p->numb,numb)==0)) p=p->next;
  if(strcmp(p->numb,numb)==0) return p;
    else return NULL;
}

LNode *findname(Linklist h,char strname[],LNode *nexts)
{/* 按姓名查找 */
    LNode *p;
    p=nexts;
    while(p!=NULL && !(strcmp(strname,p->name)==0)) p=p->next;
    if(strcmp(strname,p->name)==0) return p;
      else return NULL;
}


  void madedata(Linklist *h)
{/* 修改数据 */
   char numstr[15],ch,chs;
   LNode *p;
   printf("是否修改数据?(y/n)");
   scanf("%c%*c",&ch);
   while(ch=='y')
   {
      printf("输入要修改记录的编号: ");
      gets(numstr);
      while(!strlen(numstr) || !flagint(numstr))
    {
      printf("输入要修改记录的编号: ");
      gets(numstr);
           }
      p=h->head;
      while(p!=NULL && !(strcmp(p->numb,numstr)==0)) p=p->next;
      if(strcmp(p->numb,numstr)==0)
    {
       printf("编号      姓名     年龄  性别   基础工资   补贴工资   扣除工资   总工资\n");
       printf("%s%8s%6d%6s%11.2f%11.2f%11.2f%11.2f\n",p->numb,p->name,p->age,p->sex,p->jcgz,p->btgz,p->kcgz,p->zgz);
       printf("记录存在!是否进行修改?(y/n): ");
       scanf("%c%*c",&chs);
       if(chs=='y')
         {
        printf("输入姓名: ");
        gets(p->name);
        while(!strlen(p->name))
          {
             printf("输入姓名: ");
             gets(p->name);
          }

        printf("输入年龄: ");
        gets(numstr);
        while(!strlen(numstr) || !flagint(numstr))
          {
             printf("输入年龄: ");
             gets(numstr);
          }
        p->age=atoi(numstr);

        printf("输入性别(t/f): ");
        gets(p->sex);
        while(1)
          {
             if(strcmp("t",p->sex)==0 || strcmp("f",p->sex)==0) break;
             printf("输入性别(t/f): ");
             gets(p->sex);
          }

        printf("输入基础工资: ");
        gets(numstr);
        while(!strlen(numstr) || !flagints(numstr))
          {
             printf("输入基础工资: ");
             gets(numstr);
          }
        p->jcgz=atof(numstr);

        printf("输入补贴工资: ");
        gets(numstr);
        while(!strlen(numstr) || !flagints(numstr))
          {
             printf("输入补贴工资: ");
             gets(numstr);
          }
        p->btgz=atof(numstr);

        printf("输入扣除工资: ");
        gets(numstr);
        while(!strlen(numstr) || !flagints(numstr))
          {
             printf("输入扣除工资: ");
             gets(numstr);
          }
        p->kcgz=atof(numstr);

        p->zgz=p->jcgz+p->btgz-p->kcgz;
        }
    }
      printf("是否继续修改数据?(y/n)\n");
      scanf("%c%*c",&ch);
   }
}

void sortdata(Linklist *h)
{ /* 按编号排序或总工资排序 */
   LNode *p,*q,*s,*r;
   p=h->head;
   s=(LNode *)malloc(sizeof(LNode));
   s->next=NULL;
   h->head=s;
   while(p!=NULL)
   {
      s=p;
      q=p;  /* q始终指向最小值 */
      r=q->next;  /* r移动指针 */
      while(r!=NULL)
      { /* 查找最小值 */
         /* if(strcmp(q->numb,r->numb)<0)  q=r;  按编号排序 */
          if(q->zgz>r->zgz) q=r; /* 按总工资排序 */
          r=r->next;
      }
      if(q!=p){ /* 如果假设的最小值不正确 */
            while(s->next!=q) s=s->next; /* 确定最小值 q 的直接前驱 s */
            s->next=q->next; /* 删除最小值结点 */
               }
         else p=p->next;
      q->next=h->head->next; /* 将最小值结点链接到此趟的第一个位置处 */
      h->head->next=q;
   }
   s=h->head;
   h->head=h->head->next;
   free(s);

}

void sortsdata(Linklist h)
{/* 统计算法 */
   LNode *p;  double jcgz=0.0,btgz=0.0,kcgz=0.0,zgz=0.0;
   p=h.head;
   printf("编号      姓名     年龄  性别   基础工资   补贴工资   扣除工资   总工资\n");
   while(p!=NULL)
    {
      printf("%s%8s%6d%6s%11.2f%11.2f%11.2f%11.2f\n",p->numb,p->name,p->age,p->sex,p->jcgz,p->btgz,p->kcgz,p->zgz);
      jcgz=jcgz+p->jcgz;
      btgz=btgz+p->btgz;
      kcgz=kcgz+p->kcgz;
      zgz=zgz+p->zgz;
      p=p->next;
    }
   printf("\n统计结果:%11.2f%11.2f%11.2f%11.2f\n\n",jcgz,btgz,kcgz,zgz);
}
2015-11-28 10:17
hellovfp
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:禁止访问
威 望:30
帖 子:2976
专家分:7697
注 册:2009-7-21
收藏
得分:7 
那个警告告诉你,130行那里有个变量h未赋初值就使用了。

我们都在路上。。。。。
2015-11-28 11:54
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:7 
什么叫“无头单链表”?

授人以渔,不授人以鱼。
2015-11-29 12:17
快速回复:数据结构课程设计::在运行程序的时候:系统中已存在数据库,不能建立 ...
数据加载中...
 
   



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

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