⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 manage the foods.txt

📁 这是一个有关货物管理的系统
💻 TXT
字号:
#include <stdio.h> 
#include <string.h> 
#include <malloc.h>

struct product 
{ 
char p_num[12]; 
char name[12]; 
char spec[12]; 
int amount; 
int price; 
int s_price; 
struct product *next; 
}; 
struct product *head; 

struct in_product 
{ 
char num[12]; 
char p_num[12]; 
char name[12]; 
int amount; 
int price; 
int t_price; 
struct in_product *next; 
}; 
struct in_product *ihead; 

struct out_product 
{ 
char num[12]; 
char p_num[12]; 
char name[12]; 
int amount; 
int price; 
int t_price; 
struct out_product *next; 
}; 
struct out_product *ohead; 

struct quit_product 
{ 
char num[12]; 
char p_num[12]; 
char name[12]; 
int amount; 
int price; 
int t_price; 
struct quit_product *next; 
}; 
struct quit_product *qhead; 

int init() 
{ 
head=NULL;
ihead=NULL;
ohead=NULL;
qhead=NULL; 
printf("0: Quit\n"); 
printf("1: Enter the information of in product\n"); 
printf("2: Enter the information of out product\n"); 
printf("3: Enter the information of quit product\n"); 
printf("4: Total the information of product\n"); 
} 

int menu() 
{ 
printf("1:insert data\n"); 
printf("2:delete data\n"); 
printf("3:modify data\n"); 
printf("4:select data\n"); 
printf("Other to quit\n"); 
} 

int menu2() 
{ 
printf("0: Quit\n"); 
printf("1: Enter the information of in product\n"); 
printf("2: Enter the information of out product\n"); 
printf("3: Enter the information of quit product\n"); 
printf("4: Total the information of product\n"); 
} 

int insert_product() 
{ 
struct product * p1,* p; 
p1=(struct product *)malloc(sizeof(struct product)); 
p=head; 
if (p==NULL)/*开始没有数据*/  
{ 
printf("Enter the data of product\n"); 
printf("Include the spbh,name,style,num,price,sale_price of product\n"); 
scanf("%s%s%s%d%d%d", &p1->p_num,&p1->name,&p1->spec,&p1->amount,&p1->price,&p1->s_price); 
 head=p1; 
head->next=NULL; 
return 0; 
} 
while(p->next!=NULL)/*把指针移到链表末端,在链表末端插入数据*/ 
p=p->next; 
p->next=p1; 
printf("Enter the data\n"); 
scanf("%s,%s,%s,%d,%d,%d",&p1->num,&p1->p_num,&p1->name,&p1->amount,&p1->price,&p1->t_price); 
p1->next=NULL; 
} 

int in_insert() 
{ 
struct in_product * p1,* p;  
p1=(struct in_product *)malloc(sizeof(struct in_product));  
p=ihead; 
if (p==NULL)/*开始没有数据*/  
{ 
printf("Enter the data of in product\n"); 
printf("Include the rkbh,spbh,name,number,price,total_price\n"); 
scanf("%s%s%s%d%d%d", 
&p1->num,&p1->p_num,&p1->name,&p1->amount,&p1->price,&p1->t_price); 
ihead=p1; 
ihead->next=NULL; 
return 0; 
} 
while(p->next!=NULL)/*把指针移到链表末端,在链表末端插入数据*/ 
p=p->next; 
p->next=p1; 
printf("Enter the data\n"); 
scanf("%s%s%s%d%d%d", 
&p1->num,&p1->p_num,&p1->name,&p1->amount,&p1->price,&p1->t_price); 
p1->next=NULL; 
} 

int in_modify() 
{ 
char m_num[12]; 
struct in_product * p;  
p=ihead; 
printf("Enter the modify num\n"); 
scanf("%s",&m_num); 
if (p==NULL)/*开始没有数据*/ 
{ 
printf("Sorry! No data can be found\n"); 
return 0; 
} 
while(p!=NULL) 
{ 
if (strcmp(p->num,m_num)==0) 
{ 
printf("Enter the new data without num\n"); 
scanf("%s%s%d%d%d", 
&p->p_num,&p->name,&p->amount,&p->price,&p->t_price); 
printf("One data had modified\n"); 
return 0; 
} 
p=p->next; 
} 
printf("Sorry! No num has found\n"); 
} 

int in_select() 
{ 
char s_num[12]; 
struct in_product * p;  
p=ihead; 
printf("Enter the select num\n"); 
scanf("%s",&s_num); 
while(p!=NULL) 
{ 
if (strcmp(p->num,s_num)==0) 
{ 
printf("The data you want is:\n"); 
printf(" %s %s %s %d %d %d\n", 
p->num,p->p_num,p->name,p->amount,p->price,p->t_price); 
return 0; 
} 
p=p->next; 
} 
printf("Sorry! No num has found\n"); 
} 

int in_delete() 
{ 
char d_num[12]; 
struct in_product * p1,* p;  
p=ihead; 
printf("Enter the delete num\n"); 
scanf("%s",&d_num); 
if (p==NULL)/*开始没有数据*/  
{ 
printf("No data can be found\n"); 
return 0; 
} 
if (strcmp(p->num,d_num)==0 && p->next==NULL)/*链表只有一个数据,且是要删除的*/ 
{ 
ihead=NULL; 
printf("One data has been deleted\n"); 
return 0; 
} 
if (strcmp(p->num,d_num)==0 && p->next!=NULL)/*要删除的数据在链表的头上*/ 
{ 
ihead=ihead->next; 
printf("One data has been deleted\n"); 
return 0; 
} 
while(p->next!=NULL) 
{ 
p1=p->next; 
if (strcmp(p1->num,d_num)==0) 
{ 
p->next=p1->next;  
printf("One data has been deleted\n"); 
return 0; 
} 
p=p->next; 
} 
printf("Sorry! No num has found\n"); 
} 

int out_insert() 
{ 
struct out_product * p1,* p;  
p1=(struct out_product *)malloc(sizeof(struct out_product));  
p=ohead; 
if (p==NULL)/*开始没有数据*/  
{ 
printf("Enter the data of out product\n"); 
printf("Include the ckbh,spbh,name,number,price,total_price\n"); 
scanf("%s%s%s%d%d%d", 
&p1->num,&p1->p_num,&p1->name,&p1->amount,&p1->price,&p1->t_price); 
ohead=p1; 
ohead->next=NULL; 
return 0; 
} 
while(p->next!=NULL)/*把指针移到链表末端,在链表末端插入数据*/ 
p=p->next; 
p->next=p1; 
printf("Enter the data\n"); 
scanf("%s%s%s%d%d%d", 
&p1->num,&p1->p_num,&p1->name,&p1->amount,&p1->price,&p1->t_price); 
 p1->next=NULL; 
} 

int out_modify() 
{ 
char m_num[12]; 
struct out_product * p;  
p=ohead; 
printf("Enter the modify num\n"); 
scanf("%s",&m_num); 
if (p==NULL)/*开始没有数据*/ 
{ 
printf("Sorry! No data can be found\n"); 
return 0; 
} 
while(p!=NULL) 
{ 
if (strcmp(p->num,m_num)==0)  
{ 
printf("Enter the new data without num\n"); 
scanf("%s%s%d%d%d", 
&p->p_num,&p->name,&p->amount,&p->price,&p->t_price); 
printf("One data had modified\n"); 
return 0; 
} 
p=p->next; 
} 
printf("Sorry! No num has found\n"); 
} 

int out_select() 
{ 
char s_num[12]; 
struct out_product * p;  
p=ohead; 
printf("Enter the select num\n"); 
scanf("%s",&s_num); 
while(p!=NULL) 
{ 
if (strcmp(s_num,p->num)==0) 
{ 
printf("The data you want is:\n"); 
printf(" %s %s %s %d %d %d\n", 
p->num,p->p_num,p->name,p->amount,p->price,p->t_price); 
return 0; 
} 
p=p->next; 
} 
printf("Sorry! No num has found\n"); 
} 

int out_delete() 
{ 
char d_num[12]; 
struct out_product * p1,* p;  
p=ohead; 
printf("Enter the delete num\n"); 
scanf("%s",&d_num); 
if (p==NULL)/*开始没有数据*/  
{ 
printf("No data can be found\n"); 
return 0; 
} 
if (strcmp(p->num,d_num)==0 && p->next==NULL)/*链表只有一个数据,且是要删除的*/ 
{ 
ohead=NULL; 
printf("One data has been deleted\n"); 
return 0; 
} 
if (strcmp(p->num,d_num)==0 && p->next!=NULL)/*要删除的数据在链表的头上*/ 
{ 
ohead=ohead->next; 
printf("One data has been deleted\n"); 
return 0; 
} 
while(p->next!=NULL) 
{ 
p1=p->next; 
if (strcmp(p1->num,d_num)==0) 
{ 
p->next=p1->next;  
printf("One data has been deleted\n"); 
return 0; 
} 
p=p->next; 
} 
printf("Sorry! No num has found\n"); 
} 

int quit_insert() 
{ 
struct quit_product * p1,* p;  
p1=(struct quit_product *)malloc(sizeof(struct quit_product));  
p=qhead; 
if (p==NULL)/*开始没有数据*/  
{ 
printf("Enter the data of quit product\n"); 
printf("Include the thbh,spbh,name,number,price,total_price\n"); 
scanf("%s%s%s%d%d%d", 
&p1->num,&p1->p_num,&p1->name,&p1->amount,&p1->price,&p1->t_price); 
qhead=p1; 
qhead->next=NULL; 
return 0; 
} 
while(p->next!=NULL)/*把指针移到链表末端,在链表末端插入数据*/ 
p=p->next; 
p->next=p1; 
printf("Enter the data\n"); 
scanf("%s%s%s%d%d%d", 
&p1->num,&p1->p_num,&p1->name,&p1->amount,&p1->price,&p1->t_price); 
p1->next=NULL; 
} 

int quit_modify() 
{ 
char m_num[12]; 
struct quit_product * p;  
p=qhead; 
printf("Enter the modify num\n"); 
scanf("%s",&m_num); 
if (p==NULL)/*开始没有数据*/ 
{ 
printf("Sorry! No data can be found\n"); 
return 0; 
} 
while(p!=NULL) 
{ 
if (strcmp(p->num,m_num)==0)  
{ 
printf("Enter the new data without num\n"); 
scanf("%s%s%d%d%d", 
&p->p_num,&p->name,&p->amount,&p->price,&p->t_price); 
printf("One data had modified\n"); 
return 0; 
} 
p=p->next; 
} 
printf("Sorry! No num has found\n"); 
} 

int quit_select() 
{ 
char s_num[12]; 
struct quit_product * p;  
p=qhead; 
printf("Enter the select num\n"); 
scanf("%s",&s_num); 
while(p!=NULL) 
{ 
if (strcmp(s_num,p->num)==0) 
{ 
printf("The data you want is:\n"); 
printf(" %s %s %s %d %d %d\n", 
p->num,p->p_num,p->name,p->amount,p->price,p->t_price); 
 return 0; 
} 
p=p->next; 
} 
printf("Sorry! No num has found\n"); 
} 

int quit_delete() 
{ 
char d_num[12]; 
struct quit_product * p1,* p;  
p=qhead; 
printf("Enter the delete num\n"); 
scanf("%s",&d_num); 
if (p==NULL)/*开始没有数据*/  
{ 
printf("No data can be found\n"); 
return 0; 
} 
if (strcmp(p->num,d_num)==0 && p->next==NULL)/*链表只有一个数据,且是要删除的*/ 
{ 
qhead=NULL; 
printf("One data has been deleted\n"); 
return 0; 
} 
if (strcmp(p->num,d_num)==0 && p->next!=NULL)/*要删除的数据在链表的头上*/ 
{ 
qhead=qhead->next; 
printf("One data has been deleted\n"); 
return 0; 
} 
while(p->next!=NULL) 
{ 
p1=p->next; 
if (strcmp(p1->num,d_num)==0) 
{ 
p->next=p1->next;  
printf("One data has been deleted\n"); 
return 0; 
} 
p=p->next; 
} 
printf("Sorry! No num has found\n"); 
} 

int total() 
{ 
int in_num=0,in_price=0; 
int out_num=0,out_price=0; 
int num=0,price=0; 
struct in_product *ip; 
struct out_product *op; 
struct product *p; 
ip=ihead; 
while(ip!=NULL) 
{ 
in_num+=ip->amount; 
in_price+=ip->t_price; 
ip=ip->next; 
} 
op=ohead; 
while(op!=NULL) 
{ 
out_num+=op->amount; 
out_price+=op->t_price; 
op=op->next; 
} 
p=head; 
while(p!=NULL) 
{ 
num+=p->amount; 
price+=p->s_price; 
p=p->next; 
} 
printf("The in product's total number and total price is:\n"); 
printf("%d %d\n",in_num,in_price); 
printf("The out product's total number and total price is:\n"); 
printf("%d %d\n",out_num,out_price); 
printf("The product's total number and total price is:\n"); 
printf("%d %d\n",num,price); 
} 

int in_case() 
{ 
int choice; 
printf("The information of in product:\n"); 
while(1) 
{ 
printf("Enter the choice\n"); 
scanf("%d",&choice); 
switch(choice) 
{ 
case 1: in_insert();insert_product();break; 
case 2: in_delete();break; 
case 3: in_modify();break; 
case 4: in_select();break; 
default: return 0; 
} 
menu(); 
} 
} 

int out_case() 
{ 
int choice; 
printf("The information of out product:\n"); 
while(1) 
{ 
printf("Enter the choice\n"); 
scanf("%d",&choice); 
switch(choice) 
{ 
case 1: out_insert();break; 
case 2: out_delete();break; 
case 3: out_modify();break; 
case 4: out_select();break; 
default:return 0; 
} 
menu(); 
} 
} 

int quit_case() 
{ 
int choice; 
printf("The information of quit product:\n"); 
while(1) 
{ 
printf("Enter the choice\n"); 
scanf("%d",&choice); 
switch(choice) 
{ 
case 1: quit_insert();break; 
case 2: quit_delete();break; 
case 3: quit_modify();break; 
case 4: quit_select();break; 
default: return 0; 
} 
menu(); 
} 
} 

int main() 
{ 
int choice; 
init(); 
while(1) 
{ 
scanf("%d",&choice); 
switch(choice) 
{ 
case 0: return 0; 
case 1: menu();in_case(); break; 
case 2: menu();out_case();break; 
case 3: menu();quit_case();break; 
case 4:total();break; 
} 
menu2(); 
} 
} 
 
 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -