标题:求帮忙修改一下这个资源管理系统的程序,怎么我弄了运行不了。谢谢
取消只看楼主
lmj942522758
Rank: 1
来 自:云南
等 级:新手上路
帖 子:4
专家分:0
注 册:2010-7-12
结帖率:0
 问题点数:0 回复次数:0 
求帮忙修改一下这个资源管理系统的程序,怎么我弄了运行不了。谢谢
麻烦修改了弄出正确的以后解说一下我的错误,谢谢
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct electrical_device_management{
 char id[10];
 char name[30];
 char user[10];
 char department[20];
 int number;
 char time[20];
 double price;
 struct electrical_device_management *next;
};

typedef struct electrical_device_management EDM;

EDM *e=0;
int n=0;

void add(){
    EDM *p;
    if(e==0){
        e=(EDM *)malloc(sizeof(EDM));
        e->next=0;
        p=e;
    }
    else{
        p=e;
        while(p->next!=0) p=p->next;
        p->next=(EDM *)malloc(sizeof(EDM));
        p=p->next;
        p->next=0;
    }
    printf("Enter the ID: ");
    scanf("%s",p->id);
    printf("Enter the name: ");
    scanf("%s",p->name);
    printf("Enter the user: ");
    scanf("%s",p->user);
    printf("Enter the department: ");
 scanf("%s",p->department);
    printf("Enter the number: ");
    scanf("%d",&(p->number));
    printf("Enter the time when it was bought: ");
    scanf("%s",p->time);
    printf("Enter the price: ");
    scanf("%lf",&(p->price));
 n++;
}


void edit(){
 EDM *p;
    if(e==0){
        printf("No record available.\n");
  return;
    }
 else{
  char id[10];
  printf("Enter the ID of the device: ");
  scanf("%s",id);
  p=e;
  while(p!=0){
   if(strcmp(p->id,id)==0) break;
   p=p->next;
  }
  if(p==0) printf("No such device exists.\n");
  else{
   int i;
   do{
    printf("ID     Name      User      Department     Number    Time        Price\n");
    printf("%s %s %s %s %d %s %.2f\n",p->id,p->name,p->user,p->department,p->number,p->time,p->price);
    printf("1.Edit the ID  2.Edit the name  3.Edit the user  4.Edit the department  5.Edit the number  6.Edit the time  7.Edit the price  8.Exit\n");
    printf("Choose your operation: ");
    scanf("%d",&i);
    switch(i){
     case 1:printf("Enter the new ID: ");scanf("%s",p->id);printf("\n");break;
     case 2:printf("Enter the new name: ");scanf("%s",p->name);printf("\n");break;
     case 3:printf("Enter the new user: ");scanf("%s",p->user);printf("\n");break;
     case 4:printf("Enter the new department: ");scanf("%s",p->department);printf("\n");break;
     case 5:printf("Enter the new number: ");scanf("%d",&(p->number));printf("\n");break;
     case 6:printf("Enter the new time: ");scanf("%s",p->time);printf("\n");break;
     case 7:printf("Enter the new price: ");scanf("%lf",&(p->price));printf("\n");break;
     case 8:printf("\n");return;
    }
   }while(1);
  }
 }
}

void del(){
 EDM *p,*q=0;
    if(e==0){
        printf("No record available.\n");
  return;
    }
    else{
        char id[10];
  printf("Enter the ID of the device: ");
  scanf("%s",id);
  p=e;
  while(p!=0){
   if(strcmp(p->id,id)==0) break;
   q=p;
   p=p->next;
  }
  if(p==0){
   printf("No such device exists.\n");
   return;
  }
  else{
   char c;
   printf("ID     Name      User      Department     Number    Time        Price\n");
   printf("%s %s %s %s %d %s %.2f\n",p->id,p->name,p->user,p->department,p->number,p->time,p->price);
   printf("Do you really want to delete this record?(y/n)\n");
   getchar();
   scanf("%c",&c);
   if(c=='y'||c=='Y'){
    if(q==0){
     e=e->next;
     free(p);
    }
    else{
     q->next=p->next;
     free(p);
    }
    printf("This record has been successfully deleted.\n");
    n--;
   }
   else return;
  }
 }
}

void search(){
 int i;
 EDM *p;
 printf("1.By ID  2.By department  3.Exit\n");
 printf("Enter the way you want to search: ");
 scanf("%d",&i);
 if(i==1){
  char id[10];
  printf("\nEnter the ID: ");
  scanf("%s",id);
  p=e;
  printf("ID     Name      User      Department     Number    Time        Price\n");
  while(p!=0){
   if(strcmp(p->id,id)==0) printf("%s %s %s %s %d %s %.2f\n",p->id,p->name,p->user,p->department,p->number,p->time,p->price);
   p=p->next;
  }
 }
 else if(i==2){
  char department[20];
  printf("\nEnter the department: ");
  scanf("%s",department);
  p=e;
  printf("ID     Name      User      Department     Number    Time        Price\n");
  while(p!=0){
   if(strcmp(p->department,department)==0) printf("%s %s %s %s %d %s %.2f\n",p->id,p->name,p->user,p->department,p->number,p->time,p->price);
   p=p->next;
  }
 }
 else return;
}

void display(){
 EDM *p;
 p=e;
 if(p==0){
  printf("No record exits.\n");
  return;
 }
 printf("ID     Name      User      Department     Number    Time        Price\n");
 while(p!=0){
  printf("%s %s %s %s %d %s %.2f\n",p->id,p->name,p->user,p->department,p->number,p->time,p->price);
  p=p->next;
 }
}

void statistics(){
 if(e==0){
  printf("No record exits.\n");
  return;
 }
 int i=0,j,total_number;
 double total_price;
 EDM *p,**q;
 p=e;
 q=(EDM **)calloc(sizeof(EDM *),n);
 while(p!=0){
  q[i]=p;
  p=p->next;
  i++;
 }
 p=e;
 printf("1.By name  2.By department  3.Exit\n");
 printf("Enter your choice: ");
 scanf("%d",&i);
 if(i==1){
  char name[30];
  j=n;
  printf("Name      Total number      Total price\n");
  while(j>0){
   i=0;
   while(i<n){
    if(q[i]!=0){
     strcpy(name,q[i]->name);
     break;
    }
    i++;
   }
   i=0;
   total_number=0;
   total_price=0;
   while(i<n){
    if(q[i]!=0&&strcmp(name,q[i]->name)==0){
     total_number+=q[i]->number;
     total_price+=(q[i]->price)*(q[i]->number);
     q[i]=0;
     j--;
    }
    i++;
   }
   printf("%s %d %.2f\n",name,total_number,total_price);
  }
  free(q);
 }
 else if(i==2){
  char department[20];
  j=n;
  printf("Department      Total number      Total price\n");
  while(j>0){
   i=0;
   while(i<n){
    if(q[i]!=0){
     strcpy(department,q[i]->department);
     break;
    }
    i++;
   }
   i=0;
   total_number=0;
   total_price=0;
   while(i<n){
    if(q[i]!=0&&strcmp(department,q[i]->department)==0){
     total_number+=q[i]->number;
     total_price+=(q[i]->price)*(q[i]->number);
     q[i]=0;
     j--;
    }
    i++;
   }
   printf("%s %d %.2f\n",department,total_number,total_price);
  }
  free(q);
 }
 else return;
}

int main(){
 int i;
 do{
  printf("1.Add  2.Edit  3.Delete  4.Search  5.Display  6.Statistics  8.Quit\n");
  printf("Choose your operation: ");
  scanf("%d",&i);
  if(i==1) add();
  else if(i==2) edit();
  else if(i==3) del();
  else if(i==4) search();
  else if(i==5) display();
  else if(i==6) statistics();
  else{
   EDM* p;
   while(e!=0){
    p=e->next;
    free(e);
    e=p;
   }
   break;
  }
 }while(1);
 return 0;
}
搜索更多相关主题的帖子: 资源管理 系统 运行 
2010-08-07 13:47



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-315045-1-1.html




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

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