停车场

#include<stdio.h>
#include<time.h>
#define OK        0   
#define ERROR    -1  


int gettime()
{
struct tm *ptr;
time_t t;
t=time(NULL);
return t;
}
int interface()
{
printf("\t\t**********Welcom to our parking**********\n");
printf("\t\t1:\tpark\n");
printf("\t\t2:\tleave\n");
printf("\t\t3:\tdisplay\n");
printf("\t\t4:\tquit\n");
}
//stop area
struct tcq
{
int tcq[20];
int tcqtime[20];
int top;
};
//set stop area to empty
int tcq_InitStack (struct tcq *s)
{
if (s == NULL)
{
return ERROR;
}
s->top = -1;
return OK;
}


int tcq_StackEmpty(struct tcq *s)
{
if (s == NULL)
{
return ERROR;      // 错误返回-1  
}

return s->top == -1;   // 相等返回1 不相等返回0
}


int tcq_StackFull(struct tcq *s)
{
if (s == NULL)
{
return ERROR;
}

return s->top == 19;
}


int tcq_Push(struct tcq *s, int data)
{
if (s == NULL)
{
return ERROR;
}
// 判断是否满栈
if (tcq_StackFull(s))
{
return ERROR;
}
s->top++;
s->tcq[s->top] = data;
s->tcqtime[s->top] = gettime();
// printf("time is%d\n",s->tcqtime[s->top]);
printf("success,and the cparking area number is%d\tthe car number is%d\n",s->top,s->tcq[s->top]);
return OK;
}
//back to hcq
int tcq_Pop(struct tcq *s)
{
if (s == NULL)
{
return ERROR;
}
// 判断是否空栈
if (tcq_StackEmpty(s))
{
return ERROR;
}
// printf("the back top is%d\nand the car number is%d\n",s->top,s->tcq[s->top]);
int data = s->tcq[s->top--];
// printf("%d\n",s->tcq[s->top]);
return data;
}


//wait area
struct hcq
{
int hcq[20];
int front1;
int rear1;
};
//set hcq to empty
int hcq_InitQueue(struct hcq *q)
{
if (q == NULL)
{
return ERROR;
}
q->rear1 = 0;
q->front1 = 0;
return OK;
}
int hcq_QueueEmpty(struct hcq *q)
{
if (q == NULL)
{
return ERROR;
}

return q->rear1 == q->front1;
}
//full or not
int hcq_QueueFull(struct hcq *q)
{
if (q == NULL)
{
return ERROR;
}

return (q->rear1+1)%20 == q->front1;
}
//input
int hcq_EnQueue(struct hcq *q, int data)
{
if (q == NULL)
{
return ERROR;
}

if (hcq_QueueFull(q))
{
return ERROR;
}

q->rear1 = (q->rear1+1) % 20;
q->hcq[q->rear1] = data;
printf("hcq success\n");
return OK;
}
int hcq_DeQueue(struct hcq *q)
{
if (q == NULL)
{
return ERROR;
}

if (hcq_QueueEmpty(q))
{
return ERROR;
}

q->front1 = (q->front1+1) % 20;

return q->hcq[q->front1];
}
//back area
struct hcdd
{
int hcdd[20];
int top0;

};
//for hcdd to empty
int hcdd_InitStack (struct hcdd *s)
{
if (s == NULL)
{
return ERROR;
}

s->top0 = -1;

return OK;
}
int hcdd_StackEmpty(struct hcdd *s)
{
if (s == NULL)
{
return ERROR;      
}

return s->top0 == -1;   
}
int hcdd_StackFull(struct hcdd *s)
{
if (s == NULL)
{
return ERROR;
}

return s->top0 == 19;
}
int hcdd_Push(struct hcdd *s, int data)
{
if (s == NULL)
{
return ERROR;
}
// 判断是否满栈
if (hcdd_StackFull(s))
{
return ERROR;
}
s->hcdd[++s->top0] = data;
// printf("the number in buffer area is%d\n",data);
return OK;
}
int hcdd_Pop(struct hcdd *s)
{
if (s == NULL)
{
return ERROR;
}

// 判断是否空栈
if (hcdd_StackEmpty(s))
{
return ERROR;
}

int data = s->hcdd[s->top0--];
printf("the car number in buffer area is%d\n",data);
return data;
}
int Push(struct tcq *s)
{
if (s == NULL)
{
return ERROR;
}
// 判断是否满栈
if (tcq_StackFull(s))
{
return ERROR;
}
s->tcq[s->top] = 21;
printf("then the back car data\n");
return OK;
}
int research(struct tcq *s)
{
if (s == NULL)
{

return ERROR;
}
if(s->top == -1)
{
printf("no car\n");
}
int f=gettime();
int i;
int alltime;
int hourtime;
int minutetime;
for(i=s->top;i>=0;i--)
{
printf("the car number%d\n",s->tcq[i]);
alltime=f-(s->tcqtime[i]);
hourtime=alltime/3600;
minutetime=(alltime%3600)/60;
printf("the parking time is%dhour%dminute\n",hourtime,minutetime);

}
return OK;

int searchtime(struct tcq *s)
{
if (s == NULL)
{
return ERROR;
}
int f=gettime();
int alltime;
int hourtime;
int minutetime;
alltime=f-(s->tcqtime[s->top]);
hourtime=alltime/3600;
minutetime=(alltime%3600)/60;
printf("the time of this car stoped in our parking is%dhour%dminute\n",hourtime,minutetime);
    return OK;
}
int main()
{
struct tcq a;
tcq_InitStack (&a);
struct hcq b;
hcq_InitQueue (&b);
struct hcdd c;
hcdd_InitStack (&c);
char m[2];          //for case
int i = 0;          //for tcq
int j = 0;          //for hcq
int k;           //fo back car number
int d;              //for the number after back car number
while(1)
{
interface();
printf("please input your choice\n");
scanf("%s",m);
switch(m[0])
{
case '1':
{
// printf("help\n");
if(tcq_StackFull(&a))
{
printf("has full,please wait\n");
if(hcq_QueueFull(&b)==0)
{
j++;
hcq_EnQueue(&b, j);
printf("hcq success\n");
}
}
else
{
i++;
tcq_Push(&a, i);
printf("success\n");
}
};
break;
case '2':
{
int e;
printf("please input the car number:\n");
scanf("%d",&k);
for(d=i;d>k;d--)
{
e=tcq_Pop(&a);
// printf("%d\n",e);
hcdd_Push(&c, e);
}
// printf("then is the back car number\n");
searchtime(&a);
tcq_Pop(&a);
/* if(hcq_QueueEmpty(&b) == 0)
{
hcq_DeQueue(&b);
}
else
{*/
// Push(&a);
// }
for(d=i;d>k;d--)
{
e=hcdd_Pop(&c);
tcq_Push(&a, e);
}
if(hcq_QueueEmpty(&b) == 0)
{
i++;
hcq_DeQueue(&b);
tcq_Push(&a, i);
}
};
break;
case '3':
{
// while(tcq_Pop(&a))
// {
research(&a);
// }
};
break;

}
}


return 0;
}
内容概要:本文档详细介绍了Analog Devices公司生产的AD8436真均方根-直流(RMS-to-DC)转换器的技术细节及其应用场景。AD8436由三个独立模块构成:轨到轨FET输入放大器、高动态范围均方根计算内核和精密轨到轨输出放大器。该器件不仅体积小巧、功耗低,而且具有广泛的输入电压范围和快速响应特性。文档涵盖了AD8436的工作原理、配置选项、外部组件选择(如电容)、增益调节、单电源供电、电流互感器配置、接地故障检测、三相电源监测等方面的内容。此外,还特别强调了PCB设计注意事项和误差源分析,旨在帮助工程师更好地理解和应用这款高性能的RMS-DC转换器。 适合人群:从事模拟电路设计的专业工程师和技术人员,尤其是那些需要精确测量交流电信号均方根值的应用开发者。 使用场景及目标:①用于工业自动化、医疗设备、电力监控等领域,实现对交流电压或电流的精准测量;②适用于手持式数字万用表及其他便携式仪器仪表,提供高效的单电源解决方案;③在电流互感器配置中,用于检测微小的电流变化,保障电气安全;④应用于三相电力系统监控,优化建立时间和转换精度。 其他说明:为了确保最佳性能,文档推荐使用高质量的电容器件,并给出了详细的PCB布局指导。同时提醒用户关注电介质吸收和泄漏电流等因素对测量准确性的影响。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值