关闭

车辆信息管理系统(部分模块待改进),直接运行即可,绝对原创

1839人阅读 评论(0) 收藏 举报

#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include "list.h"

#define N 20
#define M 5


struct car_parameter
{
 char car_length[N];
 char car_wideth[N];
 char car_high[N];
 char car_colour[N];
};

struct car_basic
{
 char plate_number[N];
 char car_name[N];
 char car_brand[N];
 char car_amount[N];
 char car_price[N];
};


typedef struct car_struct
{
 struct car_basic car2;
 struct car_parameter car1;
 struct list_head list;
}CAR_LIST;
CAR_LIST car_head;
CAR_LIST *p=NULL;
CAR_LIST *p1=NULL;
CAR_LIST *p2=NULL;

int load_car_management(void);
int insert_car_information(void);
/*int check_plate_number(void);
int check_car_name(void);
int check_car_brand(void);
int check_car_amount(void);
int check_car_price(void);
int check_car_lwhth(void);
int check_car_colour(void);
*/ 
int show_car_information(void);
int show_all(void);
int show_car_brand(void);
int show_saling_car(void);
int show_need_reserve_car(void);
int show_car_price_ascending(void);
int show_car_price_decending(void); 
int bubble_sort_decending(void);
int bubble_sort_ascending(void);   
int search_car_information(void);
int search_car_by_name(void);
int search_car_by_brand(void);
int search_car_betwwen_price(void);
int search_car_by_plate_number(void);
int search_car_by_colour(void);
int delete_car_information(void);
int delete_all_car(void);
int delete_car_by_name(void);
int delete_acr_by_brand(void);
int atoi(char *s);
char *itoa(int n, char *s);
int reverse(char *s);
int free_list(CAR_LIST *p);
int get_confirm(void);
int check_empty_list(void);
void print_menu_head(void);
void print_information(void);
int cars_compare(void);
 
int load_car_management()
{
 int i,iflag,iflag2;
 char usr[N];
 char pass[N];
 char ch,ch2;
 
 char *username[M]={"099074216","099074215","099074213","099074212","099074211"};
 char *pwd[M]={"216","215","213","212","211"};
 iflag=1;
 printf("\t|=========================================================|\n");
 printf("\t|                                                         |\n");
 printf("\t|        您好,欢迎使用车辆信息管理系统,使用前请登录     |\n");
 printf("\t|                                                         |\n");
 printf("\t|=========================================================|\n");
 printf("\t|                                                         |\n");
 
 do
 {
  iflag2=0;
  printf("\n\t\t\t请输入您的用户名:");
  scanf("%s",usr);
  for(i=0; i<M; i++)
  {
   if((0==(strcmp(username[i],usr))))
   {
    iflag=0;
    printf("\t\t\t请输入您的密码:");
    scanf("%s",pass);
    if((0==(strcmp(pwd[i],pass))))
    {
     printf("\n\t\t\t登录成功!\n\n");
     iflag2 = 1;
     break;
    }
    else
    {
     printf("\n\t\t\t密码错误!\n");
     printf("\t今天您还有一次登录机会! 重新登录请按y键,其他键退出系统:");
     scanf("\n%c", &ch);
     if(ch=='y'||ch=='Y')
     {
      printf("\t\t\t请重新登录,请输入您的密码:");
      scanf("%s",pass);
      if((0==(strcmp(pwd[i],pass))))
      {
       printf("\n\t\t\t登录成功!\n\n");
       iflag2 = 1;
       break;
      }
      else
      {
       printf("\n\t\t\t密码错误!\n");
       printf("\n\t\t今天您已登录两次失败,请24小时之后再试!\n");
       return 0;
      }
     }
    }  
   }
  }
  if(1 == iflag2)
  {
   break;
  }
  if(iflag)
  {
   printf("\n\t\t\t用户名不存在!\n\n");
  }
  printf("\n\t\t\t按y键重新登录,其他键退出本系统:");
  scanf("\n%c", &ch2);
 }while((ch2=='y')||(ch2=='Y'));
 if(iflag)
 {
  return 0;
 }
 else
 {
  return 1;
 }
}


int insert_car_information()
{
 char ch;

 printf("\t\t\t请输入新录入车辆的信息:\n");
 do
 {
  p=(CAR_LIST*)malloc(sizeof(CAR_LIST));
  printf("车牌号码:");
  scanf("%s",&p->car2.plate_number);
  printf("车辆名称:");
  scanf("%s",&p->car2.car_name);
  printf("车辆品牌:"); 
  scanf("%s",&p->car2.car_brand);
  printf("库存数量(辆):");
  scanf("%s",&p->car2.car_amount);
  printf("车身长度(米):");
  scanf("%s",&p->car1.car_length);
  printf("车身宽度(米):");
  scanf("%s",&p->car1.car_wideth);
  printf("车身高度(米):");
  scanf("%s",&p->car1.car_high);  
  printf("车身颜色:");
  scanf("%s",&p->car1.car_colour);
  printf("车辆报价:");
  scanf("%s",&p->car2 .car_price );
  list_add_tail(&(p->list), &(car_head.list));  
  printf("继续录入新的车辆信息请按y:\n");
  scanf("\n%c", &ch); 
 }while((ch=='y')||(ch=='Y'));
 return 1;
}


int show_car_information()
{
 char ch;
 int i;
 do
 {
  printf("\t|================================================================|\n");
  printf("\t|                                                                |\n");
  printf("\t|                                                                |\n");
  printf("\t|                       车辆显示界面                             |\n");
        printf("\t|                                                                |\n");
  printf("\t|================================================================|\n");
  printf("\t|             1................全部显示..........................|\n");
  printf("\t|             2................按品牌显示........................|\n");
  printf("\t|             3................显示正在出售的车辆信息............|\n");
  printf("\t|             4................显示现无库存需预定的车辆信息......|\n");
  printf("\t|             5................按颜色显示........................|\n");
  printf("\t|             6................按报价区间显示....................|\n"); 
  printf("\t|             7................按报价的升序(自低向高)显示........|\n");
  printf("\t|             8................按报价的降序(自高向低)显示........|\n");
  printf("\t|================================================================|\n");
  printf("\t请输入您的选择:");
  scanf("%d", &i);
  switch(i)
  {
   case 1:
      show_all();
      break;
     
   case 2:
      show_car_brand();
      break;
   case 3:
      show_saling_car();
         break;
   case 4:
      show_need_reserve_car();
      break;
   case 5:
      search_car_by_colour(); 
      break;
   case 6:
     search_car_betwwen_price(); 
     break;
   case 7:
     show_car_price_ascending();
     break;
   case 8:
     show_car_price_decending(); 
     break;
   
   default:
      printf("            输入无效的选择!\n");
  }
 
  printf("按y键继续本界面的显示功能,其他键结束本界面:\n");
  scanf("\n%c", &ch);
 }while((ch=='y')||(ch=='Y'));

 return 1;
}

int show_all()

 
 struct list_head *ptr=NULL;
 struct list_head *n=NULL;
 
 printf("                     车辆的信息为:\n");
 printf("\t|===============================================================|\n");
 printf("\t|                                                               |\n");
 printf("\t|                                                               |\n");
 printf("\t|车牌      车名      品牌   存量  长度  宽度    高度  颜色  报价|\n");
    printf("\t|                                                               |\n");
 printf("\t|===============================================================|\n");
 printf("\t|                                                               |\n");
 
 list_for_each_safe(ptr,n,&car_head.list)
 {
  p=list_entry(ptr,CAR_LIST,list);
  printf("\t|%s  ",p->car2.plate_number);
  printf("%s   ",p->car2.car_name);
  printf("%s   ",p->car2.car_brand);  
  printf("%s    ",p->car2.car_amount);
  printf("%s   ",p->car1.car_length);  
  printf("%s   ",p->car1.car_wideth); 
  printf("%s  ",p->car1.car_high); 
  printf("%s  ",p->car1.car_colour);
  printf("%s\n",p->car2 .car_price );
  printf("\t|---------------------------------------------------------------|\n");
  printf("\t|                                                               |\n"); 
 }
 return 1;
}


int show_car_brand()
{
 int flag = 0;
 struct list_head *ptr=NULL;
 struct list_head *n=NULL;
 char temp_brand[N];
 
 printf("请输入您要查询的车辆的品牌:\n");
 scanf("%s",temp_brand);

 list_for_each_safe(ptr,n,&car_head.list)
 {
  p=list_entry(ptr,CAR_LIST,list);
  if(0 == strcmp(temp_brand, p->car2.car_brand))
  {
   printf("\t恭喜您,已经查询到此品牌的车辆信息:\n");
   flag = 1;  //用于判断是否存在此品牌的车辆
   break;
  }
 }
 if(1 == flag)
 {
  print_menu_head();
 
  list_for_each_safe(ptr,n,&car_head.list)
  {
   p=list_entry(ptr,CAR_LIST,list);
   if(0 == strcmp(temp_brand, p->car2.car_brand))
   {
    print_information(); 
   }
  }
 }
 else
 {
  printf("对不起,你所要查询的车辆品牌不存在!\n");
 }
 return 1;
}

int show_saling_car(void)
{
 int car_acount;
 int flag=0;
 struct list_head *ptr=NULL;
 struct list_head *n=NULL;

 list_for_each_safe(ptr,n,&car_head.list)
 {
  p=list_entry(ptr,CAR_LIST,list);
  car_acount = atoi(p->car2.car_amount );
  if(car_acount > 0)
  {
   printf("\t恭喜您,已经查询到现可出售的车辆信息:\n");
   flag = 1;  //用于判断是否存在此品牌的车辆
   break;
  }
 }
 if(1 == flag)
 {
  print_menu_head();
  list_for_each_safe(ptr,n,&car_head.list)
  {
   p=list_entry(ptr,CAR_LIST,list);
   car_acount = atoi(p->car2.car_amount );
   if(car_acount > 0)
   {
    print_information();  
   }
  }
 }
 else
 {
  printf("对不起,现无任何可现售的车辆,请您预购!\n");
 }
 return 1;
}

int show_need_reserve_car(void)
{
 int car_acount;
 int flag=0;
 struct list_head *ptr=NULL;
 struct list_head *n=NULL;

 list_for_each_safe(ptr,n,&car_head.list)
 {
  p=list_entry(ptr,CAR_LIST,list);
  car_acount = atoi(p->car2.car_amount );
  if(car_acount <= 0)
  {
   printf("\t恭喜您,已经查询到现可出售的车辆信息:\n");
   flag = 1;  //用于判断是否存在此品牌的车辆
   break;
  }
 }
 if(1 == flag)
 {
  print_menu_head();
  list_for_each_safe(ptr,n,&car_head.list)
  {
   p=list_entry(ptr,CAR_LIST,list);
   car_acount = atoi(p->car2.car_amount );
   if(car_acount <= 0)
   {
     print_information();  
   }
  }
 }
 else
 {
  printf("对不起,现无任何需预定的车辆!\n");
 }
 return 1;
}

int show_car_price_ascending()
{
 int flag=0;
 struct list_head *ptr=NULL;
 struct list_head *n=NULL;

 flag =  bubble_sort_ascending();
 if(1 == flag)
 {
  printf("\t                按报价升序排列的车辆信息如下:                 \n");
  print_menu_head();
 
  list_for_each_safe(ptr,n,&car_head.list)
  {
   p=list_entry(ptr,CAR_LIST,list);

   print_information();  
  }
 }
 else
 {
  printf("无法按报价的升序显示!\n");
  return 0;
 }
 return 1;
}

int bubble_sort_ascending()//这里只须要求交换双向循环链表节点的内容

 int i,j;
 int count = 0;
 int car1_price;
 int car2_price;
 struct list_head *ptr,*ptr1,*n;
  
 i=j=0;
 ptr=ptr1=NULL;

 list_for_each_safe(ptr,n,&car_head.list)
 {
  p=list_entry(ptr,CAR_LIST,list);
  count++;
 }

 list_for_each(ptr, &car_head.list)
 {
     p=list_entry(ptr,CAR_LIST,list);
  car1_price = atoi(p->car2.car_price );
  ptr1=ptr;
        for(j=0; j<count-i-1; j++)
        {
         ptr1=ptr1->next;
   p1=(CAR_LIST*)malloc(sizeof(CAR_LIST));
   p1=list_entry(ptr1,CAR_LIST,list);
   car2_price = atoi(p1->car2.car_price );
      if(car1_price>car2_price)
         {
         p=list_entry(ptr,CAR_LIST,list);
    p2=(CAR_LIST*)malloc(sizeof(CAR_LIST)); 

    strcpy(p2->car2.plate_number,p->car2.plate_number);
    strcpy(p2->car2.car_name,p->car2.car_name);
    strcpy(p2->car2.car_brand,p->car2.car_brand);  
    strcpy(p2->car2.car_amount,p->car2.car_amount);
    strcpy(p2->car1.car_length,p->car1.car_length);  
    strcpy(p2->car1.car_wideth,p->car1.car_wideth); 
    strcpy(p2->car1.car_high,p->car1.car_high); 
    strcpy(p2->car1.car_colour,p->car1.car_colour);
    strcpy(p2->car2.car_price,p->car2.car_price);

    strcpy(p->car2.plate_number,p1->car2.plate_number);
    strcpy(p->car2.car_name,p1->car2.car_name);
    strcpy(p->car2.car_brand,p1->car2.car_brand);  
    strcpy(p->car2.car_amount,p1->car2.car_amount);
    strcpy(p->car1.car_length,p1->car1.car_length);  
    strcpy(p->car1.car_wideth,p1->car1.car_wideth); 
    strcpy(p->car1.car_high,p1->car1.car_high); 
    strcpy(p->car1.car_colour,p1->car1.car_colour);
    strcpy(p->car2.car_price,p1->car2.car_price);
    
    strcpy(p1->car2.plate_number,p2->car2.plate_number);
    strcpy(p1->car2.car_name,p2->car2.car_name);
    strcpy(p1->car2.car_brand,p2->car2.car_brand);  
    strcpy(p1->car2.car_amount,p2->car2.car_amount);
    strcpy(p1->car1.car_length,p2->car1.car_length);  
    strcpy(p1->car1.car_wideth,p2->car1.car_wideth); 
    strcpy(p1->car1.car_high,p2->car1.car_high); 
    strcpy(p1->car1.car_colour,p2->car1.car_colour);
    strcpy(p1->car2.car_price,p2->car2.car_price);
            }
  }
  i++;
 }
 return 1;
}


int show_car_price_decending()
{
 int flag=0;
 struct list_head *ptr=NULL;
 struct list_head *n=NULL;

 flag =  bubble_sort_decending();
 if(1 == flag)
 {
  printf("\t                按报价降序排列的车辆信息如下:                 \n");
  printf("\t|===============================================================|\n");
  printf("\t|                                                               |\n");
  printf("\t|                                                               |\n");
  printf("\t|车牌      车名      品牌   存量  长度  宽度    高度  颜色  报价|\n");
  printf("\t|                                                               |\n");
  printf("\t|===============================================================|\n");
  printf("\t|                                                               |\n");
 
  list_for_each_safe(ptr,n,&car_head.list)
  {
   p=list_entry(ptr,CAR_LIST,list);
   printf("\t|%s  ",p->car2.plate_number);
   printf("%s   ",p->car2.car_name);
   printf("%s   ",p->car2.car_brand);  
   printf("%s    ",p->car2.car_amount);
   printf("%s   ",p->car1.car_length);  
   printf("%s   ",p->car1.car_wideth); 
   printf("%s  ",p->car1.car_high); 
   printf("%s  ",p->car1.car_colour);
   printf("%s\n",p->car2.car_price  );
   printf("\t|--------------------------------------------------------------|\n");
   printf("\t|                                                              |\n");   
  }
 }
 else
 {
  printf("无法按报价的降序显示!\n");
 }
 return 1;
}


int bubble_sort_decending()//这里只须要求交换双向循环链表节点的内容
{
 int i,j;
 int car1_price;
 int car2_price;
 int count = 0;
 struct list_head *ptr,*ptr1,*n;
  
 i=j=0;
 ptr=ptr1=NULL;

 list_for_each_safe(ptr,n,&car_head.list)
 {
  p=list_entry(ptr,CAR_LIST,list);
  count++;
 }

 list_for_each(ptr, &car_head.list)
 {
     p=list_entry(ptr,CAR_LIST,list);
  car1_price = atoi(p->car2.car_price );
  ptr1=ptr;
        for(j=0; j<count-i-1; j++)
        {
         ptr1=ptr1->next;
   p1=(CAR_LIST*)malloc(sizeof(CAR_LIST));
   p1=list_entry(ptr1,CAR_LIST,list);
   car2_price = atoi(p1->car2.car_price );
      if(car1_price<car2_price)
         {
         p=list_entry(ptr,CAR_LIST,list);
    p2=(CAR_LIST*)malloc(sizeof(CAR_LIST)); 

    strcpy(p2->car2.plate_number,p->car2.plate_number);
    strcpy(p2->car2.car_name,p->car2.car_name);
    strcpy(p2->car2.car_brand,p->car2.car_brand);  
    strcpy(p2->car2.car_amount,p->car2.car_amount);
    strcpy(p2->car1.car_length,p->car1.car_length);  
    strcpy(p2->car1.car_wideth,p->car1.car_wideth); 
    strcpy(p2->car1.car_high,p->car1.car_high); 
    strcpy(p2->car1.car_colour,p->car1.car_colour);
    strcpy(p2->car2.car_price,p->car2.car_price);

    strcpy(p->car2.plate_number,p1->car2.plate_number);
    strcpy(p->car2.car_name,p1->car2.car_name);
    strcpy(p->car2.car_brand,p1->car2.car_brand);  
    strcpy(p->car2.car_amount,p1->car2.car_amount);
    strcpy(p->car1.car_length,p1->car1.car_length);  
    strcpy(p->car1.car_wideth,p1->car1.car_wideth); 
    strcpy(p->car1.car_high,p1->car1.car_high); 
    strcpy(p->car1.car_colour,p1->car1.car_colour);
    strcpy(p->car2.car_price,p1->car2.car_price);
    
    strcpy(p1->car2.plate_number,p2->car2.plate_number);
    strcpy(p1->car2.car_name,p2->car2.car_name);
    strcpy(p1->car2.car_brand,p2->car2.car_brand);  
    strcpy(p1->car2.car_amount,p2->car2.car_amount);
    strcpy(p1->car1.car_length,p2->car1.car_length);  
    strcpy(p1->car1.car_wideth,p2->car1.car_wideth); 
    strcpy(p1->car1.car_high,p2->car1.car_high); 
    strcpy(p1->car1.car_colour,p2->car1.car_colour);
    strcpy(p1->car2.car_price,p2->car2.car_price);
            }
  }
  i++;
 }
 return 1;
}

int search_car_information()
{
 char ch;
 int i;
 do
 {
  printf("\t|===============================================================|\n");
  printf("\t|                                                               |\n");
  printf("\t|                                                               |\n");
  printf("\t|                           查询界面                         |\n");
        printf("\t|                                                               |\n");
  printf("\t|===============================================================|\n");
  printf("\t|             1....................按车辆名称查找...............|\n");
  printf("\t|             2....................按车辆品牌查找...............|\n");
  printf("\t|             3....................按车辆的报价区间查找.........|\n");
  printf("\t|             4....................按车牌号码查找...............|\n");
  printf("\t|             5....................按颜色查找...................|\n");
  printf("\t|             6....................查找正在出售的车辆...........|\n");
  printf("\t|             7....................查找现无库存需预定的车辆.....|\n");
  printf("\t|===============================================================|\n");
  printf("\t请输入您的选择:\n");
  scanf("%d", &i);
  switch(i)
  {
   case 1:
     search_car_by_name();
     break;
     
   case 2:
      search_car_by_brand();
      break;
   case 3:
      search_car_betwwen_price();
         break;
   case 4:
      search_car_by_plate_number();
      break;
   case 5:
      search_car_by_colour(); 
      break;
   case 6:
     show_saling_car();
     break;
   case 7:
     show_need_reserve_car();
     break;
   //case 8: ;  break;
   
   default:
      printf("无效的选择!\n");
  }
 
  printf("\t按y键重新选择,其他键退出此界面:\n");
  scanf("\n%c", &ch);
 }while((ch=='y')||(ch=='Y'));

 return 1;
}

int search_car_by_name()
{
 char name[N];
 int flag=0;
 struct list_head *ptr=NULL;
 struct list_head *n=NULL;
 
 printf("请输入您要查询的车辆名称:");
 scanf("%s", name);
 list_for_each_safe(ptr,n,&car_head.list)
 {
  p=list_entry(ptr,CAR_LIST,list);
  if(strcmp(name,p->car2.car_name)==0)
  {
   printf("恭喜,已经找到相关信息如下:\n");
   print_menu_head();
   print_information();
   flag=1;
  }
 }
 if(!flag)
 {
  printf("\t对不起,你要查询的汽车%s不存在!\n",name);
 }
 return 1;
}

int search_car_by_brand()
{
 char temp_brand[N];
 int flag=0;
 struct list_head *ptr=NULL;
 struct list_head *n=NULL;
 
 printf("\t请输入您所要查询的车辆品牌:\n");
 scanf("%s", temp_brand);

 list_for_each_safe(ptr,n,&car_head.list)
 {
  p=list_entry(ptr,CAR_LIST,list);
  if(0 == strcmp(temp_brand, p->car2.car_brand))
  {
   printf("\t恭喜您,已经查询到此品牌的车辆信息:\n");
   flag = 1;  //用于判断是否存在此品牌的车辆
   break;
  }
 }
 if(1 == flag)
 {
  print_menu_head();
  list_for_each_safe(ptr,n,&car_head.list)
  {
   p=list_entry(ptr,CAR_LIST,list);
   if(0 == strcmp(temp_brand, p->car2.car_brand))
   {
    print_information();  
   }
  }
 }
 else
 {
  printf("对不起,你所要查询的车辆品牌不存在!\n");
 }
 return 1;
}

int search_car_betwwen_price()
{
 int low_price,up_price,car_price;
 int flag=0;
 struct list_head *ptr=NULL;
 struct list_head *n=NULL;
 
 printf("\t请输入您所要查询的车辆的报价区间:\n");
 printf("\t请输入车辆报价区间下限:");
 scanf("%d", &low_price);
 printf("\t请输入车辆报价区间上限:");
 scanf("%d", &up_price);

 list_for_each_safe(ptr,n,&car_head.list)
 {
  p=list_entry(ptr,CAR_LIST,list);
  car_price = atoi(p->car2.car_price );
  if((car_price >= low_price) && (car_price <= up_price))
  {
   printf("\t恭喜您,已经查询到此报价区间的车辆信息:\n");
   flag = 1;  //用于判断是否存在此品牌的车辆
   break;
  }
 }
 if(1 == flag)
 {
  print_menu_head();
  list_for_each_safe(ptr,n,&car_head.list)
  {
   p=list_entry(ptr,CAR_LIST,list);
   car_price = atoi(p->car2.car_price );
   if((car_price >= low_price) && (car_price <= up_price))
   {
     print_information(); 
   }
  }
 }
 else
 {
  printf("对不起,你所要查询的报价区间无任何车辆!\n");
 }
 return 1;
}

int atoi(char *s)
{
 int n,sign;
 int i=0;
 sign=1;

 while(s[i]!='\0')
 {
  while( !isdigit(s[i])&&s[i]!='+'&&s[i]!='-')
  {
   i++;
  }


  while(s[i]=='-')
  {
   sign=-1;
   i++;
  }

  while(s[i]=='+')
  {
   sign=1;
   i++;
  }

  for(n=0; isdigit(s[i]); i++)
  {
   n=10*n+(s[i]-'0');
  }
 }
  return n;
}
 
int reverse(char *s)
{
 int c,i,j;

 for(i=0,j=strlen(s)-1; i<j; i++,j--)
 {
  c=s[i];
  s[i]=s[j];
  s[j]=c;
 }
 return 1;
}

char * itoa(int n, char *s)
{
 int i;
 int sign=0;

 if((sign = n)<0)
 {
  n=-n;
 }
 i=0;
 do
 {
  s[i++]=(int)n%10+'0';
 }while((n/=10)>0);
 if(sign<0)
 {
  s[i++]='-';
 }
 s[i]='\0';
 reverse(s);

 return s;
}

int search_car_by_plate_number(void)
{
 char car_plate_number[N];
 int flag=0;
 struct list_head *ptr=NULL;
 struct list_head *n=NULL;
 
 printf("请输入您要查询车辆的车牌号码:\n");
 scanf("%s", car_plate_number);
 list_for_each_safe(ptr,n,&car_head.list)
 {
  p=list_entry(ptr,CAR_LIST,list);
  if(strcmp(car_plate_number,p->car2.plate_number)==0)
  {
   printf("恭喜,已经找到相关信息如下:\n");
   print_menu_head();
   print_information();
   flag=1;
  }
 }
 if(!flag)
 {
  printf("\t对不起,你要查询的汽车%s不存在!\n",car_plate_number);
 }
 return 1;
}

int search_car_by_colour()
{
 char car_colour[N];
 int flag=0;
 struct list_head *ptr=NULL;
 struct list_head *n=NULL;
 
 printf("\t请输入您所要查询的车辆颜色:\n");
 scanf("%s", car_colour);

 list_for_each_safe(ptr,n,&car_head.list)
 {
  p=list_entry(ptr,CAR_LIST,list);
  if(0 == strcmp(car_colour, p->car1.car_colour))
  {
   printf("\t恭喜您,已经查询到此颜色的车辆信息:\n");
   flag = 1;  //用于判断是否存在此品牌的车辆
   break;
  }
 }
 if(1 == flag)
 {
  print_menu_head();
  list_for_each_safe(ptr,n,&car_head.list)
  {
   p=list_entry(ptr,CAR_LIST,list);
   if(0 == strcmp(car_colour, p->car1.car_colour))
   {
    print_information();  
   }
  }
 }
 else
 {
  printf("对不起,你所要查询颜色的车辆不存在!\n");
 }
 return 1;
}

int  delete_car_information()
{
 char ch;
 int i;
 do
 {
  printf("\t|================================================================|\n");
  printf("\t|                                                                |\n");
  printf("\t|                                                                |\n");
  printf("\t|                       车辆信息删除界面                         |\n");
        printf("\t|                                                                |\n");
  printf("\t|================================================================|\n");
  printf("\t|             1................全部删除..........................|\n");
  printf("\t|             2................按车辆名称删除....................|\n");
  printf("\t|             3................按车辆品牌删......................|\n");
  printf("\t|             4................删除无库存的车辆信息..............|\n");
  printf("\t|             5..................................................|\n");
  printf("\t|             6..................................................|\n"); 
  printf("\t|             7..................................................|\n");
  printf("\t|             8..................................................|\n");
  printf("\t|================================================================|\n");
  printf("\t请输入您的选择:");
  scanf("%d", &i);
  switch(i)
  {
   case 1:
      delete_all_car(); 
      break;
     
   case 2:
      delete_car_by_name();
      break;
  /* case 3:
      show_saling_car();
         break;
   case 4:
      show_need_reserve_car();
      break;
   case 5:
      search_car_by_colour(); 
      break;
   case 6:
     search_car_betwwen_price(); 
     break;
   case 7:
     show_car_price_ascending();
     break;
   case 8:
     show_car_price_decending(); 
     break;*/
   
   default:
      printf("            输入无效的选择!\n");
  }
 
  printf("按y键继续本界面的显示功能,其他键结束本界面:\n");
  scanf("\n%c", &ch);
 }while((ch=='y')||(ch=='Y'));

 return 1;
}

int delete_car_by_name()
{
 char name[N];
 int flag=0;
 struct list_head *ptr=NULL;
 struct list_head *n=NULL;
 printf("请输入您要删除的车辆的名称:");
 scanf("%s", name);
 list_for_each_safe(ptr,n,&car_head.list)
 {
  p=list_entry(ptr,CAR_LIST,list);
  if(strcmp(name,p->car2.car_name)==0)
  {
   flag=1; 
   print_menu_head();
   print_information();
   if(get_confirm())
   {
    list_del_init(ptr);
    free(p);
    printf("恭喜您,已经成功删除\n");
   }
  }
 }
 if(!flag)
 {
  printf("您输入的车辆不存在!\n",name);
 }
 return 1;
}

int delete_all_car()
{
 struct list_head *ptr=NULL;
 struct list_head *n=NULL;

 if(!check_empty_list())
 {
  show_all();
  if(get_confirm())
  {
   list_for_each_safe(ptr,n,&car_head.list)
   {
    p=list_entry(ptr,CAR_LIST,list); 
    list_del_init(ptr);
    free(p);     
   }
   printf("恭喜您,已经成功删除\n"); 
  }
 }
 else
 {
  printf("\t       对不起,无任何车辆信息,无法删除!");
 }
 return 1;
}

int delete_acr_by_brand()
{
 char brand[N];
 int flag=0;
 struct list_head *ptr=NULL;
 struct list_head *n=NULL;
 char ch;
 do
 {
  printf("请输入您要删除的车辆的品牌:\n");
  scanf("%s", brand);
  list_for_each_safe(ptr,n,&car_head.list)
  {
   p=list_entry(ptr,CAR_LIST,list);
   if(strcmp(brand,p->car2.car_brand)==0)
   {
    flag=1; 
    print_menu_head();
    print_information();
    if(get_confirm())
    {
     list_del_init(ptr);
     free(p);   
     printf("恭喜您,已经成功删除\n");
    }
   }
  }
  if(!flag)
  {
   printf("您输入车辆品牌不存在!\n",brand);
  }
  printf("按y键继续删除,其他键退出删除界面:\n");
  scanf("\n%c", &ch); 
 }while((ch=='y')||(ch=='Y'));
 return 1;
}

int get_confirm()
{
 int flag = 0;
 char ch;
 printf("\t             Are you sure ?(y/n):");
 scanf("\n%c", &ch);
 if('y' == ch|| 'Y' == ch)
 {
  flag = 1;
 }

 return flag;
}

int check_empty_list()
{
 int flag = 0;
 struct list_head *ptr = NULL;
 struct list_head *n = NULL;

 list_for_each_safe(ptr,n,&car_head.list)  
 {
  p=list_entry(ptr,CAR_LIST,list); 
  if(NULL == p)
  {
   flag = 1;
   break;
  }
 }
 return flag;
}

void print_menu_head()
{
 printf("                     车辆的信息为:\n");
 printf("\t|===============================================================|\n");
 printf("\t|                                                               |\n");
 printf("\t|                                                               |\n");
 printf("\t|车牌      车名      品牌   存量  长度  宽度    高度  颜色  报价|\n");
    printf("\t|                                                               |\n");
 printf("\t|===============================================================|\n");
 printf("\t|                                                               |\n");
}

void print_information()
{
 printf("\t|%s  ",p->car2.plate_number);
 printf("%s   ",p->car2.car_name);
 printf("%s   ",p->car2.car_brand);  
 printf("%s    ",p->car2.car_amount);
 printf("%s   ",p->car1.car_length);  
 printf("%s   ",p->car1.car_wideth); 
 printf("%s  ",p->car1.car_high); 
 printf("%s  ",p->car1.car_colour);
 printf("%s\n",p->car2.car_price );
 printf("\t|---------------------------------------------------------------|\n");
 printf("\t|                                                               |\n"); 
}

int cars_compare()
{
 char name[N];
 int i = 0;
 int flag=0;
 char a[M]="#";
 struct list_head *ptr=NULL;
 struct list_head *n=NULL;
 char ch;
 
 print_menu_head();
 do
 { 
  printf("请输入您要加入比较的车辆名称:");
  scanf("%s",name);
  
  list_for_each_safe(ptr,n,&car_head.list)
  {
   p=list_entry(ptr,CAR_LIST,list);
   if(strcmp(name,p->car2.car_name)==0)
   { 
    print_information();
    flag = 1;
    break;
   }
  }
  if(!flag)
  {
   printf("\t|                    没有%s车辆的相关信息                       |\n",name);
   printf("\t|---------------------------------------------------------------|\n");
   printf("\t|                                                               |\n");
  }
  printf("按y键继续添加比较,其他键退出比较界面:");
  scanf("\n%c", &ch); 
 }while((ch=='y')||(ch=='Y'));
 return 1;
}

int free_list(CAR_LIST *p)
{
 struct list_head *n=NULL;
 struct list_head *ptr=NULL;
 list_for_each_safe(ptr,n,&car_head.list)
 {
  p=list_entry(ptr,CAR_LIST,list);
  list_del_init(ptr);
  free(p);
 }
 printf("free successed!\n");
 return 1;
}

int main()
{
 int i,flag=0;
 char ch;
 INIT_LIST_HEAD(&car_head.list);
 flag=load_car_management();
 if(1 == flag)
 {
  printf("\t                 您好!欢迎使用车辆信息管理系统!\n\n\n\n");
  do
  {
   printf("\t|===========================================================|\n");
   printf("\t|   欢迎您使用车辆信息管理             愿您的生活更美好     |\n");
   printf("\t|                                                           |\n");
   printf("\t|                        车辆管理系统                       |\n");
   printf("\t|                                          制作人:xk_qq    |\n");
   printf("\t|===========================================================|\n");
   printf("\t|             1................录入车辆信息.................|\n");
   printf("\t|             2................显示已存在的车辆信息.........|\n");
   printf("\t|             3................快速查询车辆信息.............|\n");
   printf("\t|             4................删除车辆信息.................|\n");
   printf("\t|             5................车辆信息对比.................|\n");
   printf("\t|             6................更新车辆信息.................|\n");
   printf("\t|             7.............................................|\n");
   printf("\t|             8.............................................|\n");
   printf("\t|===========================================================|\n");
   printf("\t请输入您的选择:");
   scanf("%d", &i);
   switch(i)
   {
    case 1:
      insert_car_information();
      break; 
    case 2:
      show_car_information();
      break;
    case 3:
        search_car_information();
       break;
    case 4:
       delete_car_information();
       break;
   case 5:
       cars_compare(); 
       break;
    /*case 6: ;  break;
    case 7: ; break;
    case 8: ;  break;*/
   
    default:
       printf("对不起,您的选择无效!\n");
   }
 
   printf("按y键重新选择,其他键退出本系统!\n");
   scanf("\n%c", &ch);
  }while((ch=='y')||(ch=='Y'));
  printf("感谢您的使用,欢迎下次使用!\n");
 }
 free(p);
 free(p1);
 free(p2);
 return 0;
}

 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:84447次
    • 积分:1113
    • 等级:
    • 排名:千里之外
    • 原创:23篇
    • 转载:27篇
    • 译文:0篇
    • 评论:3条
    文章分类
    最新评论