void deleteInfo(List* list)
{
printf("请输入待删除商品的代号:");
char s[12];
scanf("%s", s);
while (!hasExist(list, s))
{
printf("该商品不存在,请重新输入或输入#退出\n");
scanf("%s", s);
if (strcmp("#", s) == 0)
return;
}
node* pro = list->head;
node* ptr;
if (strcmp(pro->no, s) == 0)
{
ptr = pro;
}
else {
while (pro != NULL)
{
if (strcmp(pro->link->no, s) == 0)
break;
pro = pro->link;
}
node* ptr = pro->link;
}
printf("------该商品信息-------\n");
printf("代号:%s\n", ptr->no);
printf("姓名:%s\n", ptr->name);
for (int i = 0; i < 12; i++)
if (ptr->sales[i] != 0)
printf("%d月销售额:%.2f\n", i + 1, ptr->sales[i]);
printf("总销售额:%.2f\n", ptr->total);
printf("----------------------\n");
printf("请按'1'确认删除,其余键返回主菜单\n");
if (getch() == '1')
{
if (pro == ptr)
{
list->head = list->end = NULL;
free(ptr);
printf("删除成功!\n请按任意键返回");
getch();
}
else
{
pro->link = ptr->link;
free(ptr);
printf("删除成功!\n请按任意键返回");
getch();
}
}
else
return;
}
void showTotal(List* list)
{
float tal = 0;
node* ptr = list->head;
while (ptr != NULL)
{
tal += ptr->total;
ptr = ptr->link;
}
printf("------------------\n");
printf("总销售额为%.2f\n", tal);
printf("-------------------\n");
printf("请按任意键返回\n");
getch();
}
void findMaxMin(List* list)
{
float maxMonth, minMonth;
char* maxNo, *minNo;
float maxYear, minYear;
char* maxYearNo, *minYearNo;
node* ptr = list->head;
if (ptr != NULL)
{
minMonth = maxMonth = ptr->sales[0];
maxNo = minNo = ptr->no;
maxYear = minYear = ptr->total;
maxYearNo = minYearNo = ptr->no;
}
else
return;
while (ptr != NULL)
{
for (int i = 0; i < 12; i++)
{
if (minMonth > ptr->sales[i])
{
minMonth = ptr->sales[i];
minNo = ptr->no;
}
if (maxMonth < ptr->sales[i])
{
maxMonth = ptr->sales[i];
maxNo = ptr->no;
}
}
if (maxYear < ptr->total)
{
maxYear = ptr->total;
maxYearNo = ptr->no;
}
if (minYear > ptr->total)
{
minYear = ptr->total;
minYearNo = ptr->no;
}
ptr = ptr->link;
}
printf("-------------------------------------");
printf("最大月销售额:%.2f 代号:%s\n", maxMonth, maxNo);
printf("最小月销售额:%.2f 代号:%s\n", minMonth, minNo);
printf("最大年销售总额:%.2f 代号:%s\n", maxYear, maxYearNo);
printf("最小年销售总额:%.2f 代号:%s\n", minYear, minYearNo);
printf("-------------------------------------");
getch();
}