(C语言代码分享):车辆信息管理系统源代码来了。

简介: (C语言代码分享):车辆信息管理系统源代码来了。


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct vehicle
{
  int num;
  char tpy[20];
  char ppai[30];
  char chepai[20];
  char gongsi[30];
  struct vehicle *next;
};
int n;
struct vehicle *w;
int main()
{
  struct vehicle *start(); //初始化信息 
  void print(struct vehicle *h); //输出函数 
  void log(); //登录界面
  void user();//用户登录
  void control();//管理员登录
  struct vehicle *refers(struct vehicle *h);//按编码查询 
  struct vehicle *VEH(struct vehicle *h);//按车型查询 
  void adds();//插入全操作 
  void dels();//删除全操作 
  struct vehicle *change(struct vehicle *h);//更改操作 
  struct vehicle *head; //定义结构体类型变量 
  int inp1,inp2,inp3;
  head=start(); //暂存初始信息 
A:  log();
  scanf("%d",&inp1);
  if(inp1==1)
  {
    user();
    scanf("%d",&inp2);  
    switch(inp2)
    {
      case 1:print(head);goto A;break;
      case 2:refers(w);goto A;break;
      case 3:VEH(w);goto A;break;
      default:break;
    }
  } 
  if(inp1==2)
  {
    control();
    scanf("%d",&inp3);
    switch(inp3)
    {
      case 1:adds();goto A;break;
      case 2:dels();goto A;break;
      case 3:change(w);goto A;break;
      default:break;
    }
  }
  if(inp1==3)
  {
    printf("\n\n你已退出!欢迎使用!");
  }
  return 0;
}
struct vehicle *start() //初始化信息函数 
{
  struct vehicle *a1,*a2,*b1,*b2,*c1,*c2;
  a1=(struct vehicle *)malloc(sizeof(struct vehicle));
  a1->num = 10201;strcpy(a1->tpy,"轿车");strcpy(a1->ppai,"宝马sss");
  strcpy(a1->chepai,"川B28393");strcpy(a1->gongsi,"宝马有限公司"); 
  a2=(struct vehicle *)malloc(sizeof(struct vehicle));
  a2->num = 10203;strcpy(a2->tpy,"轿车");strcpy(a2->ppai,"奔驰s");
  strcpy(a2->chepai,"川B23849");strcpy(a2->gongsi,"奔驰有限公司");
  b1=(struct vehicle *)malloc(sizeof(struct vehicle));
  b1->num = 10204;strcpy(b1->tpy,"客车");strcpy(b1->ppai,"金杯tpy");
  strcpy(b1->chepai,"川B24799");strcpy(b1->gongsi,"金杯有限公司");
  b2=(struct vehicle *)malloc(sizeof(struct vehicle));
  b2->num = 10206;strcpy(b2->tpy,"客车");strcpy(b2->ppai,"宇通tpy");
  strcpy(b2->chepai,"川B93889");strcpy(b2->gongsi,"宇通有限公司");
  c1=(struct vehicle *)malloc(sizeof(struct vehicle));
  c1->num = 10208;strcpy(c1->tpy,"货车");strcpy(c1->ppai,"东风t");
  strcpy(c1->chepai,"川B62834");strcpy(c1->gongsi,"东风有限公司");
  c2=(struct vehicle *)malloc(sizeof(struct vehicle));
  c2->num = 10211;strcpy(c2->tpy,"货车");strcpy(c2->ppai,"解放t");
  strcpy(c2->chepai,"川B24793");strcpy(c2->gongsi,"解放有限公司");
  w=a1;
  a1->next = a2;
  a2->next = b1;
  b1->next = b2;
  b2->next = c1;
  c1->next = c2;
  c2->next = NULL;
  return w;
}
void log() //登录界面 
{
  printf("\n\n\t******车辆信息管理系统*****");
  printf("\n\t\t1、用户登录");
  printf("\n\t\t2、管理员登录");
  printf("\n\t\t3、退出登录"); 
  printf("\n\n请输入你的操作:");
}
void user() //用户登录 
{
  printf("\n\n\t*********用户登录**********");
  printf("\n\t\t1、显示信息库");
  printf("\n\t\t2、按编号查询");
  printf("\n\t\t3、按类别查询");
  printf("\n\n请输入你的操作:"); 
} 
void control() //管理员登录 
{
  printf("\n\n\t********管理员登录**********");
  printf("\n\t\t1、添加车辆信息");
  printf("\n\t\t2、删除车辆信息");
  printf("\n\t\t3、更改车辆信息");
  printf("\n\n请输入你的操作:");
}
struct vehicle *refers(struct vehicle *h)//按编码查询 
{
  struct vehicle *p1,*p2,*p0;
  p2=p1=h;
  int num;
  int ch;
  p0=NULL;
  while(1)
  {
    printf("\n是否需要查询(Y/N): ");
    do{
      ch=getchar(); 
    } while(ch!='Y' && ch!='N');
    if(ch=='Y')
    {
      printf("\n请输入要查询的编号:");
      scanf("%d",&num); 
      while(p1->num!=num && p1->next!=NULL) 
      {
        p2=p1;
        p1=p1->next;
      }
      if(p1->num == num)
      {
        p0=p1;
        printf("\n车辆信息为:");
        printf("\n编码\t车型\t品牌\t\t车牌\t\t公司");
        printf("\n%d\t%s\t%s\t\t%s\t%s",p0->num,p0->tpy,p0->ppai,p0->chepai,p0->gongsi);
      }
      else{
        printf("\n未找到相关数据!");
      }
    }
    else{
      printf("\n查询完毕!你已退出!");
      break;
    }
  }
  return h;
}
struct vehicle *VEH(struct vehicle *h)//按车型查询 
{
  struct vehicle *p1,*p2;
  p2=p1=h;
  int retu,ch;
  while(1)
  {
    printf("\n是否需要查询(Y/N): ");
    do{
      ch=getchar(); 
    } while(ch!='Y' && ch!='N');
    if(ch=='Y')
    {
      char a[30];
      printf("\n请输入车型:");
      scanf("%s",&a);
      printf("\n车辆信息为:");
      printf("\n编码\t车型\t品牌\t\t车牌\t\t公司");
      p1=p2;
      while(1)
      {   
        retu=strcmp(a,p1->tpy);
        if(retu==0)
        {
          printf("\n%d\t%s\t%s\t\t%s\t%s",p1->num,p1->tpy,p1->ppai,p1->chepai,p1->gongsi);
        }
        if(p1->next==NULL)
        {
          break;
        } 
        p1=p1->next;
      }
    }
    else{
      printf("\n查询完毕!");
      break;
    } 
  }
  return h;
} 
void adds()//插入全操作 
{
  struct vehicle *add(struct vehicle *h,int num,char tpy[20],char ppai[30],char chepai[20],char gongsi[30]);
  void print(struct vehicle *h);
  int num;
  char tpy[20];
  char ppai[30];
  char chepai[20];
  char gongsi[30];
  int ch;
  while(1)
  {
    printf("\n是否需要添加(Y/N):");
    do{
      ch=getchar();
    }while(ch!='Y' && ch!='N');
    if(ch=='Y')
    {
      printf("\n请输入编码、车型、品牌、车牌、公司:");
      scanf("\n%d%s%s%s%s",&num,&tpy,&ppai,&chepai,&gongsi);
      w=add(w,num,tpy,ppai,chepai,gongsi);
    }else{
      printf("\n添加结束!");
      break;
    }
  }
  printf("你已退出!");
  print(w);
}
struct vehicle *add(struct vehicle *h,int num,char tpy[20],char ppai[30],char chepai[20],char gongsi[30])//插入关键
{
  struct vehicle *p1,*p2,*p0;
  p1=h;
  p2=NULL;
  while(p1!=NULL && p1->num<num) 
  {
    p2=p1;
    p1=p1->next;
  }
  p0=(struct vehicle *)malloc(sizeof(struct vehicle));
  p0->num = num;
  strcpy(p0->tpy,tpy);
  strcpy(p0->ppai,ppai);
  strcpy(p0->chepai,chepai);
  strcpy(p0->gongsi,gongsi);
  p0->next=p1;
  if(p2==NULL)
  {
    h=p0; 
  }else{
    p2->next=p0;
  }
  return h; 
} 
void dels()//删除全操作
{
  struct vehicle *del(struct vehicle *h,int num);
  void print(struct vehicle *h);
  int num;
  int ch;
  while(1)
  {
    printf("\n是否需要删除(Y/N): ");
    do{
      ch=getchar(); 
    } while(ch!='Y' && ch!='N');
    if(ch=='Y')
    {
      printf("\n请输入要删除的编号:");
      scanf("%d",&num);
      w=del(w,num);
    }
    else{
      printf("\n删除完毕!");
      break;
    } 
  }
  printf("你已退出!");
  print(w);
} 
struct vehicle *del(struct vehicle *h,int num)//删除操作 
{
  struct vehicle *p1,*p2;
  p1=p2=h;
  while(p1->next!=NULL && p1->num!=num)
  {
    p2=p1;
    p1=p1->next;
  }
  if(p1->num == num)
  {
    if(p1==h)
    {
      h=p1->next;
    }
    else{
      p2->next=p1->next;
    }
  }
  else{
    printf("\n未找到相关数据!");
  }
  return h;
}
struct vehicle *change(struct vehicle *h)//更改操作 
{
  struct vehicle *cas1(struct vehicle *h1);
  struct vehicle *cas2(struct vehicle *h1);
  struct vehicle *cas3(struct vehicle *h1);
  struct vehicle *cas4(struct vehicle *h1);
  struct vehicle *cas5(struct vehicle *h1);
  void print1(struct vehicle *h1);
  struct vehicle *p1,*p2,*p0;
  p2=p1=h;
  int num;
  int ch,input;
  p0=NULL;
  while(1)
  {
    printf("\n是否需要更改(Y/N): ");
    do{
      ch=getchar(); 
    } while(ch!='Y' && ch!='N');
    if(ch=='Y')
    {
      printf("\n请输入要更改的编号:");
      scanf("%d",&num); 
      while(p1->num!=num && p1->next!=NULL) 
      {
        p2=p1;
        p1=p1->next;
      }
      if(p1->num == num)
      {
        p0=p1;
        printf("\n编码\t车型\t品牌\t\t车牌\t\t公司");
        printf("\n%d\t%s\t%s\t\t%s\t%s",p0->num,p0->tpy,p0->ppai,p0->chepai,p0->gongsi);
        printf("\n*************执行操作******************"); 
        printf("\n1、编码 2、车型 3、品牌 4、车牌 5、公司");
        printf("\n请输入你的操作:");
        scanf("%d",&input); 
        switch(input)
        {
          case 1:p0=cas1(p0);print1(p0); break;
          case 2:p0=cas2(p0);print1(p0); break;
          case 3:p0=cas3(p0);print1(p0); break;
          case 4:p0=cas4(p0);print1(p0); break;
          case 5:p0=cas5(p0);print1(p0); break;
          default:printf("输入错误!");break; 
        }
      }
      else{
        printf("\n未找到相关数据!");
      }
    }
    else{
      printf("\n更改完毕!你已退出!");
      break;
    }
  }
  return h;
} 
struct vehicle *cas1(struct vehicle *h1)//编码更改 
{
  struct vehicle *p;
  p=h1;
  printf("请输入新的编号:");
  scanf("%d",&p->num );
  return p;
}
struct vehicle *cas2(struct vehicle *h1)//车型更改 
{
  struct vehicle *p;
  p=h1;
  char a[30];
  printf("请输入新的车型:");
  scanf("%s",&a);
  strcpy(p->tpy,a);
  return p;
}
struct vehicle *cas3(struct vehicle *h1)//品牌更改 
{
  struct vehicle *p;
  p=h1;
  char a[30];
  printf("请输入新的品牌:");
  scanf("%s",&a);
  strcpy(p->ppai,a);
  return p;
}
struct vehicle *cas4(struct vehicle *h1)//车牌更改 
{
  struct vehicle *p;
  p=h1;
  char a[30];
  printf("请输入新的车牌:");
  scanf("%s",&a);
  strcpy(p->chepai,a);
  return p;
}
struct vehicle *cas5(struct vehicle *h1)//公司更改 
{
  struct vehicle *p;
  p=h1;
  char a[30];
  printf("请输入新的公司:");
  scanf("%s",&a);
  strcpy(p->gongsi,a);
  return p;
}
void print1(struct vehicle *h1) //单个输出 
{
  struct vehicle *p;
  p=h1;
  printf("\n已更改!信息为:");
  printf("\n编码\t车型\t品牌\t\t车牌\t\t公司");
  printf("\n%d\t%s\t%s\t\t%s\t%s",p->num,p->tpy,p->ppai,p->chepai,p->gongsi); 
}
void print(struct vehicle *h) //输出函数 
{
  struct vehicle *p;
  p=h;
  if(h!=NULL)
  {
    printf("\n车辆信息为:");
    printf("\n编码\t车型\t品牌\t\t车牌\t\t公司");
    do{
      printf("\n%d\t%s\t%s\t\t%s\t%s",p->num,p->tpy,p->ppai,p->chepai,p->gongsi);
      p=p->next;
    }while(p!=NULL);
  }
}



相关文章
|
1月前
|
NoSQL 编译器 程序员
【C语言】揭秘GCC:从平凡到卓越的编译艺术,一场代码与效率的激情碰撞,探索那些不为人知的秘密武器,让你的程序瞬间提速百倍!
【8月更文挑战第20天】GCC,GNU Compiler Collection,是GNU项目中的开源编译器集合,支持C、C++等多种语言。作为C语言程序员的重要工具,GCC具备跨平台性、高度可配置性及丰富的优化选项等特点。通过简单示例,如编译“Hello, GCC!”程序 (`gcc -o hello hello.c`),展示了GCC的基础用法及不同优化级别(`-O0`, `-O1`, `-O3`)对性能的影响。GCC还支持生成调试信息(`-g`),便于使用GDB等工具进行调试。尽管有如Microsoft Visual C++、Clang等竞品,GCC仍因其灵活性和强大的功能被广泛采用。
65 1
|
1月前
|
存储 C语言
【C语言】基础刷题训练4(含全面分析和代码改进示例)
【C语言】基础刷题训练4(含全面分析和代码改进示例)
|
11天前
|
存储 算法 C语言
数据结构基础详解(C语言):单链表_定义_初始化_插入_删除_查找_建立操作_纯c语言代码注释讲解
本文详细介绍了单链表的理论知识,涵盖单链表的定义、优点与缺点,并通过示例代码讲解了单链表的初始化、插入、删除、查找等核心操作。文中还具体分析了按位序插入、指定节点前后插入、按位序删除及按值查找等算法实现,并提供了尾插法和头插法建立单链表的方法,帮助读者深入理解单链表的基本原理与应用技巧。
|
11天前
|
存储 C语言 C++
数据结构基础详解(C语言) 顺序表:顺序表静态分配和动态分配增删改查基本操作的基本介绍及c语言代码实现
本文介绍了顺序表的定义及其在C/C++中的实现方法。顺序表通过连续存储空间实现线性表,使逻辑上相邻的元素在物理位置上也相邻。文章详细描述了静态分配与动态分配两种方式下的顺序表定义、初始化、插入、删除、查找等基本操作,并提供了具体代码示例。静态分配方式下顺序表的长度固定,而动态分配则可根据需求调整大小。此外,还总结了顺序表的优点,如随机访问效率高、存储密度大,以及缺点,如扩展不便和插入删除操作成本高等特点。
|
11天前
|
存储 C语言
数据结构基础详解(C语言): 栈与队列的详解附完整代码
栈是一种仅允许在一端进行插入和删除操作的线性表,常用于解决括号匹配、函数调用等问题。栈分为顺序栈和链栈,顺序栈使用数组存储,链栈基于单链表实现。栈的主要操作包括初始化、销毁、入栈、出栈等。栈的应用广泛,如表达式求值、递归等场景。栈的顺序存储结构由数组和栈顶指针构成,链栈则基于单链表的头插法实现。
|
11天前
|
存储 算法 C语言
C语言手撕实战代码_二叉排序树(二叉搜索树)_构建_删除_插入操作详解
这份二叉排序树习题集涵盖了二叉搜索树(BST)的基本操作,包括构建、查找、删除等核心功能。通过多个具体示例,如构建BST、查找节点所在层数、删除特定节点及查找小于某个关键字的所有节点等,帮助读者深入理解二叉排序树的工作原理与应用技巧。此外,还介绍了如何将一棵二叉树分解为两棵满足特定条件的BST,以及删除所有关键字小于指定值的节点等高级操作。每个题目均配有详细解释与代码实现,便于学习与实践。
|
11天前
|
存储 算法 C语言
C语言手撕实战代码_二叉树_构造二叉树_层序遍历二叉树_二叉树深度的超详细代码实现
这段代码和文本介绍了一系列二叉树相关的问题及其解决方案。其中包括根据前序和中序序列构建二叉树、通过层次遍历序列和中序序列创建二叉树、计算二叉树节点数量、叶子节点数量、度为1的节点数量、二叉树高度、特定节点子树深度、判断两棵树是否相似、将叶子节点链接成双向链表、计算算术表达式的值、判断是否为完全二叉树以及求二叉树的最大宽度等。每道题目均提供了详细的算法思路及相应的C/C++代码实现,帮助读者理解和掌握二叉树的基本操作与应用。
|
11天前
|
存储 算法 C语言
C语言手撕实战代码_循环单链表和循环双链表
本文档详细介绍了用C语言实现循环单链表和循环双链表的相关算法。包括循环单链表的建立、逆转、左移、拆分及合并等操作;以及双链表的建立、遍历、排序和循环双链表的重组。通过具体示例和代码片段,展示了每种算法的实现思路与步骤,帮助读者深入理解并掌握这些数据结构的基本操作方法。
|
11天前
|
算法 C语言 开发者
C语言手撕实战代码_单链表
本文档详细介绍了使用C语言实现单链表的各种基本操作和经典算法。内容涵盖单链表的构建、插入、查找、合并及特殊操作,如头插法和尾插法构建单链表、插入元素、查找倒数第m个节点、合并两个有序链表等。每部分均配有详细的代码示例和注释,帮助读者更好地理解和掌握单链表的编程技巧。此外,还提供了判断子链、查找公共后缀等进阶题目,适合初学者和有一定基础的开发者学习参考。
|
11天前
|
存储 算法 C语言
C语言手撕数据结构代码_顺序表_静态存储_动态存储
本文介绍了基于静态和动态存储的顺序表操作实现,涵盖创建、删除、插入、合并、求交集与差集、逆置及循环移动等常见操作。通过详细的C语言代码示例,展示了如何高效地处理顺序表数据结构的各种问题。