You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

302 lines
7.8 KiB

6 years ago
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define SIZE 100
struct product//<2F><><EFBFBD>ݽṹ
{
long number; //<2F><>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD>
char name[20]; //<2F><>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD>
float inprice; //<2F><>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD>
float outprice; //<2F><>Ʒ<EFBFBD>ۼ<EFBFBD>
int count; //<2F><>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD>
} ;
int main(){
system("color 8A");
FILE *fp;
void Remined();//<2F><>ӡ<EFBFBD><EFBFBD><E5B5A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void menu();//<2F>˵<EFBFBD><CBB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void In();//<2F><>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void Out();//<2F><>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void Add();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><C6B7>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void Del();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><C6B7>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void Sale();//<2F><><EFBFBD><EFBFBD>ͳ<EFBFBD>ƺ<EFBFBD><C6BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void Exit();//<2F>˳<EFBFBD><CBB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
fp=fopen("<EFBFBD><EFBFBD>Ʒ<EFBFBD><EFBFBD>Ϣ","a+");//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><C6B7>Ϣ<EFBFBD>ļ<EFBFBD>
fclose(fp);
fp=fopen("<EFBFBD>","w+");//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
fclose(fp);
menu();
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD>
void Add(){
FILE *fp;
char m;
struct product inf;
void menu();
//¼<><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
printf("<=====<3D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD>=====>\n");//<2F><><EFBFBD><EFBFBD>
scanf("%ld",&inf.number);
printf("<=====<3D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD>=====>\n");//<2F><><EFBFBD><EFBFBD>
scanf("%d",&inf.count);
printf("<=====<3D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD>=====>\n");
scanf("%f",&inf.inprice);
printf("<=====<3D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD>ۼ<EFBFBD>=====>\n");
scanf("%f",&inf.outprice);
printf("<=====<3D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD>=====>\n");
scanf("%s",&inf.name);
fp=fopen("<EFBFBD><EFBFBD>Ʒ<EFBFBD><EFBFBD>Ϣ","a+");
if(fp==NULL)
printf("");
fwrite(&inf,sizeof(struct product),1,fp);
fclose(fp);
//ѯ<><D1AF><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
printf("<=====<3D>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><20><> <20><><EFBFBD><EFBFBD>'Y';<3B><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD> <20><><EFBFBD><EFBFBD>'N'=====>\n");
getchar();
m=getchar();
if(m=='Y'||m=='y')
Add();
if(m=='N'||m=='n')
menu();
}
//<2F><><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3>
void In(){
FILE *fp;
void menu();
int i,b;
char m;
long number;
int count;
struct product inf[SIZE];
struct product inf1;
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD>ĸ<EFBFBD><C4B8><EFBFBD><EFBFBD><EFBFBD>Ϣ
fp=fopen("<EFBFBD><EFBFBD>Ʒ<EFBFBD><EFBFBD>Ϣ","r");
if((fp=fopen("<EFBFBD><EFBFBD>Ʒ<EFBFBD><EFBFBD>Ϣ","r"))==NULL)
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><EFBFBD>Ϣ<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
printf("<=====<3D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD>=====>\n");//<2F><><EFBFBD><EFBFBD>
scanf("%ld",&number);
printf("<=====<3D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD>=====>\n");//<2F><><EFBFBD><EFBFBD>
scanf("%d",&count);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD>ļ<EFBFBD><C4BC>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸<EFBFBD>
i=0;
while(fread(&inf1,sizeof(struct product),1,fp)!=(int)NULL){
if(inf1.number!=number){
inf[i].number=inf1.number;
strcpy(inf[i].name,inf1.name);
inf[i].inprice=inf1.inprice;
inf[i].outprice=inf1.outprice;
inf[i].count=inf1.count;
i++;
}
else{
inf[i].number=inf1.number;
inf[i].inprice=inf1.inprice;
inf[i].outprice=inf1.outprice;
inf[i].count=count+inf1.count;
strcpy(inf[i].name,inf1.name);
i++;
}
}
fclose(fp);
if((fp=fopen("<EFBFBD><EFBFBD>Ʒ<EFBFBD><EFBFBD>Ϣ","w+"))==NULL)
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><EFBFBD>Ϣ<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
for(b=0;b<i;b++){
if(fwrite(&inf[b],sizeof(struct product),1,fp)==!1)
printf("д<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><EFBFBD>Ϣ<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
} fclose(fp);
//ѯ<><D1AF><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
printf("<=====<3D>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><20><> <20><><EFBFBD><EFBFBD>'Y';<3B><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD> <20><><EFBFBD><EFBFBD>'N'=====>\n");
getchar();
m=getchar();
if(m=='Y'||m=='y')
In();
if(m=='N'||m=='n')
menu();
}
//<2F><><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3>
void Out(){
FILE *fp;
void menu();
char m;
float money=0;
long number;
int count,i,b;
struct product inf[SIZE],inf1;
struct product list;
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD>ĸ<EFBFBD><C4B8><EFBFBD><EFBFBD><EFBFBD>Ϣ
if((fp=fopen("<EFBFBD><EFBFBD>Ʒ<EFBFBD><EFBFBD>Ϣ","rb"))==NULL)
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><EFBFBD>Ϣ<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
printf("<=====<3D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD>=====>\n");//<2F><><EFBFBD><EFBFBD>
scanf("%ld",&number);
printf("<=====<3D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD>=====>\n");//<2F><><EFBFBD><EFBFBD>
scanf("%d",&count);
i=0;
while(fread(&inf1,sizeof(struct product),1,fp)!=(int)NULL){
if(inf1.number!=number){
inf[i].number=inf1.number;
strcpy(inf[i].name,inf1.name);
inf[i].inprice=inf1.inprice;
inf[i].outprice=inf1.outprice;
inf[i].count=inf1.count;
i++;
}
else{
inf[i].number=number;
inf[i].inprice=inf1.inprice;
inf[i].outprice=inf1.outprice;
inf[i].count=(inf1.count-count);
strcpy(inf[i].name,inf1.name);
list.number=number;
list.count=count;
list.inprice=inf1.inprice;
list.outprice=inf1.outprice;
strcpy(list.name,inf1.name);
money=(list.count)*(list.outprice);
i++;
}
}
fclose(fp);
if((fp=fopen("<EFBFBD><EFBFBD>Ʒ<EFBFBD><EFBFBD>Ϣ","w+"))==NULL)
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><EFBFBD>Ϣ<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
for(b=0;b<i;b++){
if(fwrite(&inf[b],sizeof(struct product),1,fp)==(int)NULL)
printf("д<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><EFBFBD>Ϣ<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
} fclose(fp);
fp=fopen("<EFBFBD>","a+");
fwrite(&list,sizeof(struct product),1,fp);
fclose(fp);
printf("<=====<3D>Ƿ<EFBFBD><C7B7><EFBFBD>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E5B5A5><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>'Y';<3B><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD> <20><><EFBFBD><EFBFBD>'N'=====>\n");
getchar();
m=getchar();
if(m=='y'||m=='Y')
printf("<EFBFBD><EFBFBD>Ʒ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>ۼ<EFBFBD> <20><><EFBFBD><EFBFBD>\n");
printf("%3l%s%3.lf%3.lf\n",list.number,list.name,list.inprice,list.outprice,money);
printf("<=====<3D>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EBA3BF> <20><><EFBFBD><EFBFBD>'Y'<27><>'y';<3B><> <20><><EFBFBD><EFBFBD>'N'<27><>'n'=====>\n");
getchar();
m=getchar();
if(m=='y'||m=='Y')
Out();
if(m=='N'||m=='n')
menu();
}
//<2F><><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3>
void Del(){
int i,b;
void menu();
long number;
struct product inf[SIZE],infd;
char m;
FILE *fp;
printf("<=====<3D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD>=====>\n"),
scanf("%ld",&number);
fp=fopen("<EFBFBD><EFBFBD>Ʒ<EFBFBD><EFBFBD>Ϣ","r");
if(fp=NULL)
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
//<2F><><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>ݶ<EFBFBD><DDB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4>
i=0;
while(fread(&infd,sizeof(struct product),1,fp)!=(int)NULL)
{
if(infd.number!=number){
inf[i].number=infd.number;
inf[i].count=infd.count;
inf[i].inprice=infd.inprice;
inf[i].outprice=infd.outprice;
strcpy(inf[i].name,infd.name);
i++;
}
}
fclose(fp);
if(fopen("<EFBFBD><EFBFBD>Ʒ<EFBFBD><EFBFBD>Ϣ","w+")==NULL)
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><EFBFBD>Ϣ<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
for(b=0;b<i;b++)
if(fwrite(&inf[b],sizeof(struct product),1,fp)==1)
printf("д<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><EFBFBD>Ϣ<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
fclose(fp);
//ѯ<><D1AF><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
printf("<=====<3D>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EBA3BF> <20><><EFBFBD><EFBFBD>'Y'<27><>'y';<3B><> <20><><EFBFBD><EFBFBD>'N'<27><>'n'=====>\n");
getchar();
m=getchar();
if(m=='Y'||m=='y')
Del();
if(m=='N'||m=='n')
menu();
}
//<2F>˳<EFBFBD>ģ<EFBFBD><C4A3>
void Exit(){
char m;
void menu();
printf("<=====<3D>Ƿ<EFBFBD>ȷ<EFBFBD>ϣ<EFBFBD> <20><> <20><><EFBFBD><EFBFBD>'Y'<27><>'y';<3B><> <20><><EFBFBD><EFBFBD>'N'<27><>'n'=====>\n");
getchar();
m=getchar();
if(m=='Y'||m=='y')
exit(1);
if(m=='N'||m=='n')
menu();
}
//<2F>嵥ģ<E5B5A5><C4A3>
void Sale()
{
char m;
void menu();
struct product list;
FILE *fp;
printf("<=====ȷ<>ϴ<EFBFBD>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>y; <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>n=====>\n");
getchar();
m=getchar();
if(m=='Y'||m=='y'){
fp=fopen("<EFBFBD>","r");
printf("<EFBFBD><EFBFBD>Ʒ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD> <20><>Ʒ<EFBFBD>ۼ<EFBFBD> <20>ܽ<EFBFBD><DCBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
while(fread(&list,sizeof(struct product),1,fp)!=(int)NULL)
printf("%s %5ld %3.lf %3.lf %d\n",list.name,list.number,list.outprice,(list.count*list.outprice),list.count);
}
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ز˵<EFBFBD>\n");
getchar();
getchar();
menu();
if(m=='n'||m=='N')
menu();
}
//<2F><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><E6BAAF>
void Remined(){
struct product list1;
FILE *fp;
void menu();
fp=fopen("<EFBFBD><EFBFBD>Ʒ<EFBFBD><EFBFBD>Ϣ","r");
printf("<EFBFBD><EFBFBD>Ʒ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD> <20><>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD> <20><>Ʒ<EFBFBD>ۼ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
while(fread(&list1,sizeof(struct product),1,fp)!=(int)NULL)
printf("%ld %s %f %f %d\n",list1.number,list1.name,list1.inprice,list1.outprice,list1.count);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ز˵<EFBFBD>\n");
getchar();
getchar();
menu();
}
void menu()//<2F>˵<EFBFBD>ģ<EFBFBD><C4A3>
{
int choice;
printf("#######################################################################\n");
printf("# #\n");
printf("#------------------<2D><> ӭ <20><> <20><> <20><> <20><> <20><> <20><> <20><> <20><> ϵ ͳ----------------#\n");
printf("# #\n");
printf("#######################################################################\n");
printf("<=====<3D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫʹ<D2AA>õĹ<C3B5><C4B9>ܱ<EFBFBD><DCB1><EFBFBD>\n");
printf("0-------------<2D>˳<EFBFBD>\n");
printf("1-------------<2D><>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
printf("2-------------<2D><>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
printf("3-------------<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><C6B7>Ϣ\n");
printf("4-------------<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><C6B7>Ϣ\n");
printf("5-------------<2D><><EFBFBD><EFBFBD>ͳ<EFBFBD><CDB3>\n");
printf("6-------------<2D><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
scanf("%d",&choice);
switch(choice){
case 0:Exit();
case 1:In();break;
case 2:Out();break;
case 3:Add();break;
case 4:Del();break;
case 5:Sale();break;
case 6:Remined();break;
default:main();
}
}