您的位置:

使用c语言编程汽车,c语言汽车动画编程

本文目录一览:

C语言编程:请编写一个程序,定义一个轿车销售结构体类型,

enum Color //定义颜色

{

RED,

GREEN,

COIN,

WHITE

};

typedef struct Car//定义轿车

{

char name[20];

char shape;

Color color;

int salesPrice;

}Car;

c语言编程 汽车租赁问题

亲测可以运行 自己的课程设计  搞得很累 代码如下我的课程设计 汽车租赁系统c语言

#includestdio.h 

#includestdlib.h 

#includestring.h 

#define MaxNum  20 

                            

typedef struct A{ 

int No;  /*车辆编号*/ 

char Type; /*车类型*/ 

int Payment;/*租费*/ 

int fine;   /*罚金*/ 

struct A *next;/*指向下一个结点*/ 

} car; 

                            

typedef struct B{ 

int No; /*顾客编号*/ 

char Name[20]; /*顾客姓名*/ 

char License;  /*执照类别*/ 

int carNo;    /*租凭的车辆编号*/ 

int  Day;    /*租的天数*/ 

int DelayDay;/*延迟的天数*/ 

struct B *next; 

} client; 

                            

struct C{/*这个结构体是车辆链表的头结点,A,B,C每种类型有一种*/ 

char Type;/*车辆型号*/ 

int avl; /*可用数*/ 

car *head;/*指向车辆结点*/ 

} headNode[3]={{'A',MaxNum,NULL},{'B',MaxNum,NULL},{'C',MaxNum,NULL}} ; 

                            

client *allClien=NULL; 

int pay[3]={400,300,200},fine[3]={600,500,400}; 

void init();/*初始化*/ 

int menu();/*简单菜单界面*/ 

void search();/*查询*/ 

void carSc(); /*查询车辆*/ 

void clientSc();/*查询顾客*/ 

void rent(); /*租车*/ 

void giveback();/*还车*/ 

void addCli(client *cli);/*向顾客链表增加顾客*/ 

client* delCli(int clientNo);/*从顾客链表删除一个顾客*/ 

void addCar(char carType,int carNo); 

car* delCar(char type); 

void Exit();/*退出*/ 

                            

void main() 

 init(); 

  while(1) 

  { 

    switch(menu()) 

    { 

      case 1:search();break; 

      case 2:rent();break; 

      case 3:giveback();break; 

      case 4:Exit(); 

      default:; 

    } 

  } 

                            

void init() 

  int i=0; 

  car *ptr,*pa,*pb,*pc; 

  headNode[0].head=NULL,headNode[1].head=NULL,headNode[2].head=NULL; 

                             

        ptr=(car *)malloc(sizeof(car)); 

        ptr-No=100; 

        ptr-Type='A'; 

        ptr-Payment=400; 

        ptr-fine=600; 

        headNode[0].head=ptr; 

        pa=ptr; 

        pa-next=NULL; 

                            

        for( i=1;i20;i++){ 

            ptr=(car *)malloc(sizeof(car)); 

            ptr-No=100+i; 

            ptr-Type='A'; 

            ptr-Payment=400; 

            ptr-fine=600; 

            pa-next=ptr; 

            pa=ptr; 

            pa-next=NULL; 

                            

  } 

        free(ptr); 

                            

        ptr=(car *)malloc(sizeof(car)); 

        ptr-No=200; 

        ptr-Type='B'; 

        ptr-Payment=300; 

        ptr-fine=500; 

        headNode[1].head=ptr; 

        pb=ptr; 

        pb-next=NULL; 

                            

        for( i=1;i20;i++){ 

            ptr=(car *)malloc(sizeof(car)); 

            ptr-No=200+i; 

            ptr-Type='A'; 

            ptr-Payment=400; 

            ptr-fine=600; 

            pb-next=ptr; 

            pb=ptr; 

            pb-next=NULL; 

                            

  } 

        free(ptr); 

                            

                            

        ptr=(car *)malloc(sizeof(car)); 

        ptr-No=300; 

        ptr-Type='C'; 

        ptr-Payment=200; 

        ptr-fine=400; 

        headNode[2].head=ptr; 

        pc=ptr; 

        pc-next=NULL; 

                            

        for( i=1;i20;i++){ 

            ptr=(car *)malloc(sizeof(car)); 

            ptr-No=300+i; 

            ptr-Type='A'; 

            ptr-Payment=400; 

            ptr-fine=600; 

            pc-next=ptr; 

            pc=ptr; 

            pc-next=NULL; 

                            

  } 

        free(ptr); 

                            

int menu() 

   int choice; 

                            

   printf("\n\n\n选择服务:1.查询   2.租车   3.归还   4.退出\n"); 

                            

   scanf("%d",choice); 

                            

   while(choice!=1choice!=2choice!=3choice!=4) 

   { 

     printf("\n输入有误,重新输入:"); 

     scanf("%d",choice); 

   } 

   return choice; 

                            

void search() 

  int choice; 

  printf("\n你想查询:1.汽车    2.顾客    3.返回  \n"); 

  scanf("%d",choice); 

                            

  while(choice!=1choice!=2choice!=3) 

  { 

    printf("\n输入有误,重新输入:"); 

    scanf("%d",choice); 

  } 

                            

  switch(choice) 

  { 

    case 1:carSc(); break; 

    case 2:clientSc(); break; 

    case 3: ; 

    default:; 

  } 

                            

void carSc() 

  printf("\n\n所有汽车信息:\n"); 

  printf("\nA类汽车还剩%d辆.\nB类汽车还剩%d辆.\nC类汽车还剩%d辆.", 

           headNode[0].avl,headNode[1].avl,headNode[2].avl); 

                            

                            

void clientSc() 

   client *ptr=allClien; 

   printf("\n\n所有顾客信息:\n"); 

                            

   while(ptr!=NULL) 

   { printf("\n\n顾客编号:%d",ptr-No); 

     printf("\n顾客姓名:%s",ptr-Name); 

     printf("\n驾照类型:%c",ptr-License); 

     printf("\n租赁车号:%d",ptr-carNo); 

     printf("\n租赁天数:%d",ptr-Day); 

     printf("\n延迟天数:%d",ptr-DelayDay); 

                            

     ptr=ptr-next; 

   } 

                            

void addCli(client *cli) 

if(allClien==NULL) 

  allClien=cli; 

else 

  cli-next=allClien; 

  allClien=cli; 

                            

client* delCli(int clientNo) 

   client *ptr,*prePtr;; 

   ptr=allClien; 

   while(ptr!=NULLptr-No!=clientNo) 

   { prePtr=ptr; 

     ptr=ptr-next; 

   } 

   if(ptr!=NULL) 

   { 

     if(ptr==allClien) 

     { 

       allClien=NULL; 

      } 

     else 

     { 

       prePtr-next=ptr-next; 

     } 

   } 

   return ptr; 

                            

void rent() 

   char name[20],type,Yes_No; 

   int num,day,No; 

   car *carPtr; 

   client *cli; 

                            

printf("\n\n输入执照类型(A/B/C):"); 

   scanf("%c",type); 

   while(type!='A'type!='B'type!='C') 

   { 

     printf("输入有误,重新输入:"); 

  scanf("%c",type); 

   } 

   if(type=='A') 

     num=headNode[0].avl; 

   else if(type=='B') 

     num=headNode[1].avl; 

   else 

     num=headNode[2].avl; 

                            

   printf("\n%c类汽车还剩%d辆,是否要租凭(Y/N):",type,num); 

   scanf("%c",Yes_No); 

   while(Yes_No!='Y'Yes_No!='N'Yes_No!='y'Yes_No!='n') 

   { 

     printf("Y或N:"); 

     scanf("%c",Yes_No); 

   } 

                            

 /*增加顾客*/ 

   if(Yes_No=='Y'||Yes_No=='y') 

   { 

     printf("\n输入你的名字:"); 

                            

     scanf("%s",name); 

                            

     printf("\n输入你的租赁天数:"); 

     scanf("%d",day); 

   } 

   No=rand()%60+200; 

   carPtr=delCar(type); 

                            

   cli=(client *)malloc(sizeof(client)); 

   cli-No=No; 

   strcpy(cli-Name,name); 

   cli-License=type; 

   cli-carNo=carPtr-No; 

   cli-Day=day; 

   cli-DelayDay=0; 

   cli-next=NULL; 

   addCli(cli); 

                            

  /*移出一辆车*/ 

   printf("\n你的顾客编号是:%d",No); 

   printf("\n你所租赁的汽车是%c类车,车号是:%d",type,carPtr-No); 

   printf("\n你的租赁天数是%d天.",day); 

                            

                            

void giveback() 

  int No; 

  long int payment; 

  client *ptr; 

  printf("\n\n顾客编号:"); 

  scanf("%d",No); 

  if((ptr=delCli(No))==NULL) 

   printf("\n该顾客不存在,无法归还!"); 

  else 

   { 

     switch(ptr-License) 

     { 

       case 1:payment=ptr-Day*400+ptr-DelayDay*600;break; 

       case 2:payment=ptr-Day*300+ptr-DelayDay*500;break; 

       case 3:payment=ptr-Day*200+ptr-DelayDay*400;break; 

       default:; 

     } 

     printf("\n\n顾客姓名:%s",ptr-Name); 

     printf("\n驾照类型:%c",ptr-License); 

     printf("\n租赁车号:%d",ptr-carNo); 

     printf("\n租赁天数:%d",ptr-Day); 

     printf("\n延迟天数:%d",ptr-DelayDay); 

     printf("\n\n所需费用:%ld",payment); 

                            

     addCar(ptr-License,ptr-carNo); 

                            

     free(ptr); 

   } 

                            

                            

void addCar(char carType,int carNo) 

    car *ptr; 

    int index=carType-65; 

    ptr=headNode[index].head; 

    if(ptr==NULL) 

      {ptr=(car *)malloc(sizeof(car)); 

       headNode[index].head=ptr; 

       headNode[index].avl++; 

      } 

    else 

       {while(ptr-next) 

          ptr=ptr-next; 

         ptr-next=(car *)malloc(sizeof(car)); 

         ptr=ptr-next; 

         headNode[index].avl++; 

        } 

    ptr-No=carNo; 

    ptr-Type=carType; 

    ptr-Payment= pay[index]; 

    ptr-fine=fine[index]; 

    ptr-next=NULL; 

                            

car* delCar(char type) 

  car *rentcar; 

  car *pp; 

                                

  switch(type) 

  { 

  case 'A': 

            rentcar=headNode[0].head; 

             headNode[0].head=rentcar-next; 

             headNode[0].avl--; 

                            

             break; 

    case 'B':rentcar=headNode[1].head; 

             headNode[1].head=rentcar-next; 

             headNode[1].avl--; 

             break; 

    case 'C':rentcar=headNode[2].head; 

             headNode[2].head=rentcar-next; 

             headNode[2].avl--; 

             break; 

    default:; 

  } 

  return rentcar; 

                            

                            

void Exit() 

                            

   printf("\n欢迎使用.....888888888886666...."); 

   exit(0); 

}

使用c语言在方法中编写汽车减速,每次递减10分钟

你好,意思是不是速度每次递减10啊,我用循环语句,使速度每次递减10,直至速度为0。把源程序复制一下

#includestdio.h

#includestdlib.h

#includestring.h

int main()

{

int speed;

printf("please input the speed:\n");

scanf("%d",speed);

printf("begin slow down...\n");

while(speed=0)

{

printf("now the speed is:%d\n",speed);

speed=speed-10;

}

printf("now the speed is:0(the car stop)\n");

return 0;

}

运行结果如下,如果有什么不明白的还可以问我

C语言编程:定义一个汽车结构体?

按照题目要求编写的C语言汽车结构体程序如下

#includestdio.h

struct car{

float petrol;

}c1={0};

struct car refuel(struct car c){

c.petrol=c.petrol+2;

return c;

}

int main(){

int i;

for(i=0;i5;i++){

c1=refuel(c1);

printf("%.2f\n",c1.petrol);

}

return 0;

}

C语言编程:按题目要求从键盘输入乘车的起步价及行车公里数,输出车费?

按照题目要求编写的C语言程序如下

#includestdio.h

int main(){

int price,kilometre;

float payment;

printf("请输入起步价:");

scanf("%d",price);

printf("请输入行车公里数:");

scanf("%d",kilometre);

if(price==4){

payment=4+(kilometre-3)*1.2;

printf("应付车资为%.2f。",payment);

}else if(price==5){

payment=5+(kilometre-3)*1.5;

printf("应付车资为%.2f。",payment);

}else if(price==6){

payment=6+(kilometre-3)*1.8;

printf("应付车资为%.2f。",payment);

}else{

printf("无此起步价。");

}

return 0;

}