根据题目给出数据,定义枚举类型和数据结构。然后编写输入数据的函数(也可以考虑写死)。然后就是一些查询函数,外面要写个循环,因为查询是对于一辆车的
代码:
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
//车辆名称枚举
enum eCarName
{
ACKERMANN=1,
MECANUM,
CCGT,
ELEMENTO,
AMGONE
};
//车辆状态枚举
enum eCarState
{
STOP=1,
ORIGIN,
CURRENT,
LIGHT,
SCURVED
};
//定义车辆结构
typedef struct CAR
{
eCarName name;
eCarState state;
double price; //价格
char level; //等级
};
//打印函数
void count(struct CAR car[])
{
int i = 0;
printf("显示所有车辆信息\n");
printf("#####################\n");
for ( i = 0; i < 8; i++)
{
if (car[i].name == ACKERMANN)
printf("ACKERMANN,");
else if (car[i].name == MECANUM)
printf("MECANUM,");
else if (car[i].name == CCGT)
printf("CCGT,");
else if (car[i].name == ELEMENTO)
printf("ELEMENTO,");
else if (car[i].name == AMGONE)
printf("AMGONE,");
if (car[i].state == STOP)
printf("STOP,");
else if (car[i].state == ORIGIN)
printf("ORIGIN,");
else if (car[i].state == CURRENT)
printf("CURRENT,");
else if (car[i].state == LIGHT)
printf("LIGHT,");
else if (car[i].state == SCURVED)
printf("SCURVED,");
printf("%.2lf,%c\n", car[i].price, car[i].level);
}
}
//查询函数
void priceCom(struct CAR car[])
{
int i = 0;
printf("车辆价格大于2000\n");
printf("#####################\n");
for ( i = 0; i < 8; i++)
{
if (car[i].price > 2000)
{
if (car[i].name == ACKERMANN)
printf("ACKERMANN,");
else if (car[i].name == MECANUM)
printf("MECANUM,");
else if (car[i].name == CCGT)
printf("CCGT,");
else if (car[i].name == ELEMENTO)
printf("ELEMENTO,");
else if (car[i].name == AMGONE)
printf("AMGONE,");
if (car[i].state == STOP)
printf("STOP,");
else if (car[i].state == ORIGIN)
printf("ORIGIN,");
else if (car[i].state == CURRENT)
printf("CURRENT,");
else if (car[i].state == LIGHT)
printf("LIGHT,");
else if (car[i].state == SCURVED)
printf("SCURVED,");
printf("%.2lf,%c\n", car[i].price, car[i].level);
}
}
}
//查询状态
void statusCom(struct CAR car[], int sta)
{
int i;
eCarState state;
switch (sta)
{
case 1:state = STOP; break;
case 2:state = ORIGIN; break;
case 3:state = CURRENT; break;
case 4:state = LIGHT; break;
case 5:state = SCURVED; break;
}
for (i = 0; i < 8; i++)
{
if (car[i].state == state)
{
if (car[i].name == ACKERMANN)
printf("ACKERMANN,");
else if (car[i].name == MECANUM)
printf("MECANUM,");
else if (car[i].name == CCGT)
printf("CCGT,");
else if (car[i].name == ELEMENTO)
printf("ELEMENTO,");
else if (car[i].name == AMGONE)
printf("AMGONE,");
if (car[i].state == STOP)
printf("STOP,");
else if (car[i].state == ORIGIN)
printf("ORIGIN,");
else if (car[i].state == CURRENT)
printf("CURRENT,");
else if (car[i].state == LIGHT)
printf("LIGHT,");
else if (car[i].state == SCURVED)
printf("SCURVED,");
printf("%.2lf,%c\n", car[i].price, car[i].level);
}
}
}
int main()
{
struct CAR a[8] = { {ACKERMANN,ORIGIN,1000,'a'},{MECANUM,STOP,5000,'a'},
{CCGT,CURRENT,100,'b'},{ELEMENTO,LIGHT,2100,'c'},
{CCGT,ORIGIN,1300,'d'},{MECANUM,STOP,6200,'b'},
{CCGT,CURRENT,1500,'a'},{ELEMENTO,LIGHT,4800,'a'} };
int sta;
count(a); //打印函数
priceCom(a); //
printf("按照状态查询车辆\n");
printf("#####################\n");
printf("请输入状态:");
scanf("%d", &sta);
statusCom(a, sta);
return 0;
}
您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!