#include
#include
#include
#define SIZE 20
typedef struct goods{
char good_name[SIZE];
float price;
float count;
float sum;
}GOOD;
typedef struct menu{
char super_name[SIZE];
char name[SIZE];
char money_type[SIZE];
}MENU;
typedef struct node{
GOOD data;
struct node *next;
}LIST, *LISTP;
int create(LISTP * head, GOOD *tmp)
{
LISTP cur = (LISTP)malloc(sizeof(*cur));
if(cur == NULL)
{
printf("error\n");
return -1;
}
cur->data = *tmp;
cur->next = NULL;
cur->next = *head;
*head = cur;
return 0;
}
int time_self()
{
int y,m,d;
time_t _time;
struct tm* time_info = {0};
time(&_time);
time_info = localtime(&_time);
y = 1900+time_info->tm_year;
m = time_info->tm_mon+1;
d = time_info->tm_mday;
printf("日期:%d-%d-%d\n",y,m,d);
return 0;
}
int print_self(LISTP head,MENU q)
{
LISTP p = head;
float top=0;
printf("\33[1;1H ");
system("clear");
printf("============================================================\n");
print_super(q);
while(p != NULL)
{
top +=p->data.sum;
print_goods(p->data);
p = p->next;
}
time_self();
printf("---------------------------------------------------\n");
printf("总和:%.2f\n",top);
printf("===========================================================\n");
return 0;
}
int print_goods(GOOD p)
{
printf("商品:%-10s\t单价:%-10.2f\t数量:%-10.2f\t总价:%-10.2f\n",
p.good_name,
p.price,
p.count,
p.sum
);
return 0;
}
int print_super(MENU super)
{
printf("\t\t\t超市:%s\n收银员:%-10s\n币种:%-10s\n",
super.super_name,
super.name,
super.money_type);
return 0;
};
int destroy(LISTP *head)
{
int i = 0;
LISTP p;
while(*head != NULL)
{
p = *head;
*head = p->next;
free(p);
i++;
}
return i;
}
int main()
{
LISTP head = NULL;
GOOD gd;
MENU super;
char yz;
system("clear");
printf("请输入超市名:");
scanf("%s",super.super_name);
printf("请输入收银员名:");
scanf("%s",super.name);
printf("请输入默认币种:");
scanf("%s",super.money_type);
while('Q'!=yz)
{
printf("请输入商品名称:");
scanf("%s",gd.good_name);
printf("请输入商品单价:");
scanf("%f",&gd.price);
printf("请输入货物数量:");
scanf("%f",&gd.count);
getchar();
gd.sum=gd.price*gd.count;
create(&head, &gd);
printf("回车商品属性,输入Q退出\n");
scanf("%c",&yz);
}
print_self(head,super);
destroy(&head);
return 0;
}
阅读(648) | 评论(0) | 转发(0) |