设计要求:根据货品的输入代码,统计货品价格,并打印清单,能有找零功能。
如果有资源谢谢分享一下。1204935800
C语言编写的收银台结算程序。
答案:4 悬赏:0 手机版
解决时间 2021-01-25 00:24
- 提问者网友:寂寞撕碎了回忆
- 2021-01-24 16:54
最佳答案
- 五星知识达人网友:爱难随人意
- 2021-01-24 17:43
//以下是参考代码有相似结构,数据结构自己设计一下。
//如果没参考价值,手下留情,别点不采纳。
#define MAXPARKINGPOS 100
#define MAXPRICETYPE 3
#define MAXLINE 4096
struct detail
{
char num[MAXLINE];
char name[MAXLINE];
double pricePerHour;
time_t start;
time_t end;
double period;
double cost;
};
static int currentParkingNum = 0;
static struct detail detailBuf[MAXPARKINGPOS];
static double priceBuf[MAXPRICETYPE] = {11.0,22.0,33.0};
int main(void) {
char buf[MAXLINE];
struct detail *myParking;
int iChoice,leavingIndex,i,numEexisted;
struct tm *begin,*end;
while(true) {
selectService:
printf("Service type,what is your choice?\n1.park\n2.leave\n3.exit\n");
gets(buf);
if(strcmp(buf,"3") == 0) {
return 0;
}
if(strcmp(buf,"1") == 0) {
//park
if(currentParkingNum == MAXPARKINGPOS) {
printf("Sorry,not empty!\n\n");
continue;
}
myParking = detailBuf+currentParkingNum;
printf("your name:\n");
gets(myParking->name);
printf("your parking num:\n");
gets(myParking->num);
numEexisted = 0;
for(i=0;i
if(strcmp(detailBuf[i].num,myParking->num) == 0) {
numEexisted =1;
break;
}
}
if(numEexisted != 0) {
printf("The car %s is in\n\n",myParking->num);
goto selectService;
}
selectPrice:
printf("Service cost,what is your choice?\n");
for(int i=0;i < MAXPRICETYPE; i++) {
printf("%d.$%.2f per hour\n",i+1,priceBuf[i]);
}
gets(buf);
iChoice = atoi(buf);
if(!(iChoice >= 1 && iChoice <=MAXPRICETYPE)) {
printf("Your choice is incorrect!\n\n");
goto selectPrice;
}
myParking->pricePerHour=priceBuf[iChoice-1];
time(&myParking->start);
currentParkingNum++;
printf("Parcking ok!\n\n");
}else if(strcmp(buf,"2") == 0) {
//leave
printf("your parking num:\n");
gets(buf);
myParking = NULL;
for(i=0;i
if(strcmp(detailBuf[i].num,buf) == 0) {
myParking = &detailBuf[i];
leavingIndex = i;
break;
}
}
if(myParking ==NULL) {
printf("Cannot find your car!\n\n");
continue;
}
myParking->end = time(&myParking->end);
myParking->period = difftime(myParking->end,myParking->start);
myParking->cost= myParking->period/3600.0*myParking->pricePerHour;
printf("****** Cost Details ******\n");
printf("name:%s\n",myParking->name);
printf("number:%s\n",myParking->num);
printf("price:%.2f\n",myParking->pricePerHour);
begin = localtime(&myParking->start);
strftime(buf,sizeof(buf),"%Y-%m-%d %H:%M:%S",begin);
printf("begin:%s\n",buf);
end = localtime(&myParking->end);
strftime(buf,sizeof(buf),"%Y-%m-%d %H:%M:%S",end);
printf("end:%s\n",buf);
printf("period:%.2f hour(s)\n",myParking->period/3600.0);
printf("cost:$%.2f\n",myParking->cost);
printf("service:$%.2f per hour\n",myParking->pricePerHour);
for(i = leavingIndex; i < currentParkingNum;i++) {
if(i+1 < currentParkingNum) {
detailBuf[i]=detailBuf[i+1];
}
}
detailBuf[currentParkingNum-1].cost=0.0;
detailBuf[currentParkingNum-1].end=0;
detailBuf[currentParkingNum-1].name[0]='\0';
detailBuf[currentParkingNum-1].num[0]='\0';
detailBuf[currentParkingNum-1].period=0.0;
detailBuf[currentParkingNum-1].pricePerHour=0.0;
detailBuf[currentParkingNum-1].start=0;
currentParkingNum--;
printf("Leaving ok!\n\n");
}else{
printf("Your choice is incorrect!\n\n");
continue;
}
}
return 0;
}
//如果没参考价值,手下留情,别点不采纳。
#define MAXPARKINGPOS 100
#define MAXPRICETYPE 3
#define MAXLINE 4096
struct detail
{
char num[MAXLINE];
char name[MAXLINE];
double pricePerHour;
time_t start;
time_t end;
double period;
double cost;
};
static int currentParkingNum = 0;
static struct detail detailBuf[MAXPARKINGPOS];
static double priceBuf[MAXPRICETYPE] = {11.0,22.0,33.0};
int main(void) {
char buf[MAXLINE];
struct detail *myParking;
int iChoice,leavingIndex,i,numEexisted;
struct tm *begin,*end;
while(true) {
selectService:
printf("Service type,what is your choice?\n1.park\n2.leave\n3.exit\n");
gets(buf);
if(strcmp(buf,"3") == 0) {
return 0;
}
if(strcmp(buf,"1") == 0) {
//park
if(currentParkingNum == MAXPARKINGPOS) {
printf("Sorry,not empty!\n\n");
continue;
}
myParking = detailBuf+currentParkingNum;
printf("your name:\n");
gets(myParking->name);
printf("your parking num:\n");
gets(myParking->num);
numEexisted = 0;
for(i=0;i
numEexisted =1;
break;
}
}
if(numEexisted != 0) {
printf("The car %s is in\n\n",myParking->num);
goto selectService;
}
selectPrice:
printf("Service cost,what is your choice?\n");
for(int i=0;i < MAXPRICETYPE; i++) {
printf("%d.$%.2f per hour\n",i+1,priceBuf[i]);
}
gets(buf);
iChoice = atoi(buf);
if(!(iChoice >= 1 && iChoice <=MAXPRICETYPE)) {
printf("Your choice is incorrect!\n\n");
goto selectPrice;
}
myParking->pricePerHour=priceBuf[iChoice-1];
time(&myParking->start);
currentParkingNum++;
printf("Parcking ok!\n\n");
}else if(strcmp(buf,"2") == 0) {
//leave
printf("your parking num:\n");
gets(buf);
myParking = NULL;
for(i=0;i
myParking = &detailBuf[i];
leavingIndex = i;
break;
}
}
if(myParking ==NULL) {
printf("Cannot find your car!\n\n");
continue;
}
myParking->end = time(&myParking->end);
myParking->period = difftime(myParking->end,myParking->start);
myParking->cost= myParking->period/3600.0*myParking->pricePerHour;
printf("****** Cost Details ******\n");
printf("name:%s\n",myParking->name);
printf("number:%s\n",myParking->num);
printf("price:%.2f\n",myParking->pricePerHour);
begin = localtime(&myParking->start);
strftime(buf,sizeof(buf),"%Y-%m-%d %H:%M:%S",begin);
printf("begin:%s\n",buf);
end = localtime(&myParking->end);
strftime(buf,sizeof(buf),"%Y-%m-%d %H:%M:%S",end);
printf("end:%s\n",buf);
printf("period:%.2f hour(s)\n",myParking->period/3600.0);
printf("cost:$%.2f\n",myParking->cost);
printf("service:$%.2f per hour\n",myParking->pricePerHour);
for(i = leavingIndex; i < currentParkingNum;i++) {
if(i+1 < currentParkingNum) {
detailBuf[i]=detailBuf[i+1];
}
}
detailBuf[currentParkingNum-1].cost=0.0;
detailBuf[currentParkingNum-1].end=0;
detailBuf[currentParkingNum-1].name[0]='\0';
detailBuf[currentParkingNum-1].num[0]='\0';
detailBuf[currentParkingNum-1].period=0.0;
detailBuf[currentParkingNum-1].pricePerHour=0.0;
detailBuf[currentParkingNum-1].start=0;
currentParkingNum--;
printf("Leaving ok!\n\n");
}else{
printf("Your choice is incorrect!\n\n");
continue;
}
}
return 0;
}
全部回答
- 1楼网友:青灯有味
- 2021-01-24 21:19
很简单:
因为看到有会员积分 所以要有个用户数据表 节日折扣表
设计好某日的折扣 到了 节日 就给每个商品都打折
会员积分设计好 消费多少 加多少积分
- 2楼网友:白昼之月
- 2021-01-24 20:30
C++的要不要?
C的太麻烦了,除非就实现简单的功能
- 3楼网友:深街酒徒
- 2021-01-24 19:16
建立商品库
建立出售库
每刷一毛,查询商品库,记录出售库。。。。。直到结算,开始新一笔。。。。。。。。。。如此循环
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯