2010
09-02

求程序!!!!


求一汽车销售管理系统的程序!!!
特来此向各位大虾求助!CryCryCryCryCry


求助》有 1 条评论

  1. 史诗级菜鸟 说:

    求助!!!!!

    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    #include<malloc.h>
    #define NULL 0
    #define LEN sizeof(struct car)
    struct car
    {
     char name[15];
     char code[6];
     char date[20];
     char type[20];
     int price;
     char Company[40];
     struct car *next;
    };
    struct car *creat()/*创建链表*/        /*添加记录*/
    {
     struct car *p,*head,*end;
     head=p=end=(struct car *)malloc(LEN);/*开辟一个新单元*/
     printf(“====请输入汽车信息====\n”);
     printf(“请输入汽车名称:”);
     scanf(“%s”,p->name);
     while(p->name!=0)
     {
      end=p;
      printf(“车名  代号  上市日期    车型  价格      公司\n”);
      scanf(“%s,%s,%-8s,%s,%d,%s”,p->name,p->code,p->date,p->type,&p->price,p->Company);
      p=(struct car *)malloc(LEN);
      end->next=p;
      printf(“请输入汽车名称:”);
      scanf(“%s”,p->name);
     }
     end->next=NULL;
     return (head);
    }
    void print(struct car *head)           /*显示记录*/
    {
     struct car *p;
            p=head;
     printf(“               汽车管理系统                “);
            if(p==NULL);
            {
              printf(“为创建任何记录!\n”);
              getchar();
              return;
             }
     while(p!=NULL)
      {
       printf(“车名  代号  上市日期    车型  价格      公司\n”);
       printf(“%-4s,%-4s,%-8s,%-4s,%-8d,%-4s”,p->name,p->code,p->date,p->type,p->price,p->Company);
       p=p->next ;
      }
                    getchar();
    }
    void Find(struct car *head,struct car *p)     /*查询记录*/    
    {
     int a,b;
     struct car *p1;
     p=head;
     printf(“请输入您要查找的车的代号!\n”);
     scanf(“%d”,&a);
     while(head!=NULL)
     {
      b=0;
      b=a-*(p->code);
      p1=p;
      p=p->next;
      if (b==0) break;
       printf(“您要找的数据已找到:\n”);
       printf(“车名  代号  上市日期    车型  价格      公司\n”);
       printf(“%-4s,%-4s,%-8s,%-4s,%-8d,%-4s”,&p1->name,&p1->code,&p1->date,&p1->type,&p1->price,&p1->Company);
     }
    }
    void sorting(struct car *head)         /*代号排序*/
    {
     struct car *p,*f,*t;
     char ch[100];
     int i;
     p=f=t=head;
     if(head==NULL)
     {
      printf(“未打开任何文件!\n”);
      getchar();
      return;
     }
     for(p=head;p->next!=NULL;p=p->next)
     {
      for(t=head,f=t->next;t->next!=NULL;t=t->next,f=f->next)//由于创建链表是以p->number=0结束的故以f->next结束
      {
       if(strcmp(t->name,f->name)>0)
       {
        strcpy(ch,t->name);
        strcpy(t->name,f->name);
        strcpy(f->name,ch);
       
        strcpy(ch,t->code);
        strcpy(t->code,f->code);
        strcpy(f->code,ch);
        strcpy(ch,t->date);
        strcpy(t->date,f->date);
        strcpy(f->date,ch);
     strcpy(ch,t->type );
        strcpy(t->type,f->type);
        strcpy(f->type,ch);
        i=t->price;
        t->price=f->price;
        f->price=i;
        strcpy(ch,t->Company);
        strcpy(t->Company,f->Company);
        strcpy(f->Company,ch);
       }
      }
     }
     printf(“完成排序!\n”);
     getchar();
    }
    struct car *del(struct car *head)            /*删除记录*/
    {
     struct car *p,*e;
     char str[20];
     if (head==NULL)
     {
      printf(“没有可打开的文件!\n”);
                    getchar();
      return NULL;
     }
     p=e=head;
            printf(“请输入要删除的编号:”);
            scanf(“%s”,str);
     if(strcmp(p->name,str)==0)
     {
      head=head->next;
      printf(“删除成功!\n”);
      return head;
     }
     p=p->next;
     while(p!=NULL)
     {
      if(strcmp(p->name,str)==0)
      {
       if(p->next!=NULL)
        e->next=p->next;
       if(p->next==NULL)
        e->next=NULL;
       printf(“删除成功!\n”);
       return head;
      }
      p=p->next;
      e=e->next;
     }
     printf(“搜索完毕,未能找到结果!\n”);
     return head;
    }
    void renew()                               /*更新记录*/
    {
     int a,b;
     struct car *head,*p,*p1;
     p=head;
     printf(“请输入您要修改的车的代号!\n”);
     scanf(“%d”,&a);
     while(head!=NULL)
     {
      b=0;
      b=a-*(p->code);
      p1=p;
      p=p->next;
      if (b==0) break;
       printf(“您要找的数据已找到:\n”);
       printf(“车名  代号  上市日期    车型  价格      公司\n”);
       printf(“%-4s,%-4s,%-8s,%-4s,%-8d,%-4s”,&p1->name,&p1->code,&p1->date,&p1->type,&p1->price,&p1->Company);
       printf(“请修改该车信息。修改后的信息为:\n”);
       printf(“车名:”);    scanf(“%-4s”,&p1->name);printf(“\n”);
       printf(“代号:”);    scanf(“%-4s”,&p1->code);printf(“\n”);
       printf(“上市日期:”);scanf(“%-8s”,&p1->date);printf(“\n”);
       printf(“车型:”);    scanf(“%-4s”,&p1->type);printf(“\n”);
       printf(“价格:”);    scanf(“%-8d”,&p1->price);printf(“\n”);
       printf(“所属公司:”);scanf(“%-4s”,&p1->Company);printf(“\n”);
     }
    }
    void  save()                                   /*保存文件*/
    {
     FILE *fp;
     char filename[10];
     char *p;
     struct car *head;
     p=filename;
     printf(“请输入要保存的文件名\n”);
     scanf(“%s”,filename);
     fp=fopen(“*p”,”wb”);
     if(head!=NULL)
      do
      {
       fwrite(head,LEN,1,fp);
       head=head->next;
      }
      while(head!=NULL);
      else printf(“对不起,您所要保存的文件不存在!”);
     fclose(fp);
    }
    void Read()                                /*读取文件*/
    {
     char filename[10];
     FILE *fp;
     char *p;
     struct car *p1,*head;
     p=filename;
     printf(“请输入您要读取的文件名\n”);
     scanf(“%s”,filename);
     fp=fopen(p,”r”);
     p1=head=(struct car *)malloc(LEN);
     if(head!=NULL)
     {
      printf(“车名  代号  上市日期    车型  价格      公司\n”);
      do
      {
       fread(head,LEN,1,fp);
       printf(“%-4s,%-4s,%-8s,%-4s,%-8d,%-4s”,head->name,head->code,head->date,head->type,head->price,head->Company);
       head=head->next;
      }
      while(head!=NULL);
     }  
     fclose(fp);
    }
    void main()
    {
     int fn;
     struct car *head,*p;
     p=head;
     printf(“       ~~~~~~~~~~~~~~~~~欢迎使用汽车销售管理系统~~~~~~~~~~~~~~~~~\n”);
     printf(“             1.添加记录        2.显示记录      3.查询记录        \n”);
     printf(“             4.代号排序        5.删除记录      6.更新记录        \n”);
     printf(“             7.保存文件        8.读取文件      9.退出系统        \n”);
     printf(“          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    \n”);
     printf(“请输入您的选项。以回车键结束\n”);
     scanf(“%d”,&fn);
    switch(fn)
     {
     case’1′:head=creat();break;
     case’2′:print(head);break;
     case’3′:Find(head,p);break;
     case’4′:sorting(head);break;
     case’5′:del(head);break;
     case’6′:renew(head);break;
     case’7′:save(head);break;
     case’8′:Read(head);break;
     case’9′:exit(0);break;
    default:printf(“error\n”);
     }
      printf(“按回车键返回\n”);
     getchar();
     }
    帮我完成吧!
    里面有错

留下一个回复