struct product
{
   char name[20];
   float price;
   float sales;
   char intro[30];
} list[10]={
{ "Huawei", 1599.90, 150.5, "62G内存" },
{"Apple", 3899.90, 350.5, "人脸识别"},
{"Opple", 999.90, 666.5, "音乐手机"}};

int n=3;

main()
{
	int choice;
	do{
	   printf("\n1.显示商品 \n2.添加商品\n3.删除商品\n4.列表排序\n5.退出");
      
	   printf("请选择操作: ");
       scanf("%d", &choice);
  

	switch(choice)
	{
	case 1: show(); break;
	case 2: add();  break;
	case 3: del();  break;
    case 4: sort();
	}
	


	}while(choice!=5);
  return 0;
}


show()
{
	int i;
	
	printf("\n%-20s %-20s %-20s %-20s", "名称","单价","数量","简介\n");
	printf("\n----------------------------------------------------------------------");
    for(i=0;i<n;i++)
		printf("\n%-20s %-20.2f %-20.2f %-20s", list[i].name, list[i].price, list[i].sales, list[i].intro );
    
}

add()
{
	
	printf("\n请输入商品信息（各项数据以空格分隔 ）:\n"); 
	scanf("%s %f %f %s", list[n].name, &list[n].price, &list[n].sales, list[n].intro);
	n++;
	show();

}


del()
{  
	int i,j;
	char remove[20];
	printf("请输入要删除的商品名称: ");
	scanf("%s", remove);
	for(i=0;i<n;i++)
	{
		if(!strcmp(list[i].name, remove))
		{for(j=i;j<=n;j++) 
			  list[j]=list[j+1]; 
		}	
	
	}
	n--;
	show();
}


sort()
{
	int i,j;
	struct product temp;
    for(j=0;j<n-1;i++)
		for(i=0;i<n-1-j;i++)
		if(list[i].price>list[i+1].price)
		{void swap(struct cj *a , struct cj *b) 
{ 
 struct cj temp ;  
 temp = *a ;  
 *a = *b ;  
 *b = temp ; 
 return ; 
} 

		
		}
    
}