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

📄 supermarket.cpp

📁 用C语言编程实现 简单超市管理功能。包括 商品的管理(添加、修改、删除、查找)、商品的销售.可作为学习C语言和C语言课程设计的参考.
💻 CPP
📖 第 1 页 / 共 3 页
字号:
        printf("已从输入商品函数返回\n\n\n");
        fflush(stdin);
        return(0);
        //返回结束标志
    }
    
    system("cls");
    fflush(stdin);
    return(1);
    //返回成功标志
}
//删除结点函数
int delect(SELL*phead)   
{
	struct sell*del=NULL;
	struct sell *cc;
	if(phead==head)
    { 
		cc=head;
		head=head->next;
	    free(cc);
	}
	if(head!=NULL&&head!=phead)
    for(del=head;del->next!=NULL&&del->next!=phead;del=del->next);//找出要删除节点的前一个指针
    if(del!=NULL&&del->next!=NULL)
    {
		del->next=phead->next ;
        free(phead);
	}
    if(del!=NULL)
    return(1);
    else 
    return(0);
}
//按类型查找菜单函数
void formfindmenu()
{
    char choice='1' ;
    while(choice!='0')
    {
        
        printf("              ***欢迎使用类型查找***\n");
        printf("         ==================================\n");
        printf("          1.生活用品        2.食品\n");
        printf("          3.文化用品       4.上一级菜单\n");
        printf("          0.退出\n");
        printf("         ===================================\n");
        
		printf(">");
        choice=getchar();
        
		fflush(stdin);
        switch(choice)
        {
            case '1' :
            system("cls");
            livefind(head);
            break ;
            case '2' :
            system("cls");
            foodfind();
            break ;
            case '3' :
            system("cls");
            pefind();
            break ;
            case '4' :
            system("cls");
            return;
            break ;
            case '0' :
            printf("   谢谢你的使用!");
            printf("\n");
            system("pause");
            exit(0);
            break ;
            default :
            system("cls");
            return;
        }
    }
}
void datefind()
{
    int n=0 ;
    struct sell*pian ;
    if(head==NULL)
    {
        printf("没有记录\n\n\n");
        return;
    }
    char dat[8];
    printf("输入你要查找的日期\n>");
    scanf("%s",dat);
    fflush(stdin);
    printf("\n\n");
    for(pian=head;pian->next!=NULL;pian=pian->next)
    {
        
        
        if(!strcmp(dat,pian->date))
        {
            if(0==n)
            {
                printf("   商品名字     价格      编号     数量       日期     种类\n");
                n++;
            }
            printf("%10s%10.2f%10d%",pian->name,pian->price,pian->number);
            printf("%10d%10s%10c",pian->amount,pian->date,pian->kind);
            printf("\n");
            printf("  ______________________________________________________________\n");
        }
    }
	if(0==n)
    printf("没有找到\n");

}
void foodfind()
{
    int n=0 ;
    int foodfindadd ;
    struct sell*foodpian ;
    if(head==NULL)
    {
        printf("还没有此记录!\n\n");
        printf("输入1输入记录,其它返回菜单\n");
        scanf("%d",&foodfindadd);
        fflush(stdin);
        system("cls");
        if(1==foodfindadd)
        {
            while(1)
            {
                if(!creat(head))
                break ;
            }
        }
        return;
    }
    for(foodpian=head;foodpian->next!=NULL;foodpian=foodpian->next)
    {
        if(foodpian->kind=='B')
        {
            
            if(0==n)
            {
                printf("   商品名字     价格      编号     数量       日期     种类\n");
                n++;
            }
            printf("%10s%10.2f%10d%",foodpian->name,foodpian->price,foodpian->number);
            printf("%15d%10d%10c",foodpian->amount,foodpian->date,foodpian->kind);
			printf("\n");
            printf("  ______________________________________________________________\n");
        }
    }
    if(0==n)
    printf("没有记录!\n\n");
}
//对输入的字符加密
void addpassword(char answer[])
{
    int i=0 ;
    //加密
    for(i=0;i<6&&answer[i]!='\0';i++)
	if(answer[i]+i+3<='z')
    answer[i]=answer[i]+i+3 ;
    for(i=0;i<20&&answer[i]!='\0';i++)
    {
        if(answer[i]>='a'&&answer[i]<='z')
        answer[i]=answer[i]-'a'+'A' ;
        else if(answer[i]>='A'&&answer[i]<='Z')
        answer[i]=answer[i]+'a'-'A' ;
    }
	//for(i=0;i<6;i++)
	//printf("%c",answer[i]);
	//system("pause");
}
//按编号查找 传入的是编号  返回值为地址
struct sell*sfind(int Number)
{
    struct sell*pians ;
    if(head==NULL)
    {
        printf("没有记录!\n");
        printf("\n");
        printf("\n");
        return(NULL);
    }
    for(pians=head;pians->next!=NULL;pians=pians->next)
    {
        if(pians->number==Number)
        {
            printf("   商品名字     价格      编号      数量       日期      种类\n");
            printf("%10s%10.2f%10d%",pians->name,pians->price,pians->number);
            printf("%10d%10s%10c",pians->amount,pians->date,pians->kind);
			printf("\n");
            printf("  ______________________________________________________________\n");
            return(pians);
        }
    }
	if(pians->next==NULL)
	{
		printf("没有找到!");
		fflush(stdin);
	    system("pause");
	}
    return(NULL);
}
//售货系统
int sell()
{   
	system("color 27");
    struct sell*p ,*savep[100];    //save[i]是用来保存购物篮里的商品的
	int count=0;             //记录有多少个商品
    int a ,j,i=0;
    float get,gip;        //get收款数  gip找款
	float money=0;        
    int number ;
    for(j=0;j<=100;j++)
	savep[j]=NULL;
	printf("                &&&&&<>售货窗口<>&&&&&\n\n");
    printf("☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆\n");
while(0!=number)
{	
	printf("请输入商品的编号(-1时回到上一级菜单,0收款):       ");
    printf("购物篮里有%d件商品\n>",count);
    scanf("%d",&number);
    
    //如果输入-1,就返回结束标志0
    if(-1==number)return(0);
    if(0==number)break;
    else 		
    p=sfind(number);
	system("cls");
	if(NULL==p)
    {
        system("cls");
        printf("货仓中还没有此商品记录!\n");
		if(refer==-2) continue;
        printf("是否添加商品记录?\n\n"); 
        printf("输入1加入,-2不再提示,其它返回\n");
        scanf("%d",&a);
        fflush(stdin);
        system("cls");
        if(1==a)
        {
            while(1)
            {
                if(!creat(head))
                break ;
            }
			fflush(stdin);
        }
        if(-2==a)
        {
			refer=-2;
            system("pause");
		}
    }
    else 
    {
        if(0==count)
		{
			printf("   商品名字     价格      编号     现有数量\n");
			
		}
		savep[count]=p;
		count++;
		if(count>100)break;
        printf("%10s",p->name);
        printf("%10.2f",p->price);
        printf("%10d",p->number);
        printf("%10d\n",p->amount-count);
		p->amount=p->amount-count;   //改变内存中此商品的数量的
		if(p->amount<=0)
		{	printf("此商品已卖完!");
		    delect(p);           //删除卖完的商品记录
		}
		printf("\n");
		money=money+p->price;
	}    
        
}
	while(savep[i]!=NULL)
	{
        if(0==i)
		printf("   商品名字     价格      编号     现有数量\n");
		p=savep[i];
		printf("%10s",p->name);
        printf("%10.2f",p->price);
        printf("%10d",p->number);
        printf("%10d\n",p->amount);
        i++;
	}
        printf("应收款:%10.2f\n",money);
        printf("输入收款数:\n>");
		scanf("%f",&get);
        system("cls");
        gip=get-money;
		money=0;
        printf("应找回%5.2f元\n",gip);
		system("pause");
		return(1);
}
void livefind(struct sell*phead)
{
    struct sell*livefindpian ;
    int count=0 ;
    if(head==NULL)
    {
        int livefindadd ;
        printf("没有记录!\n");
        printf("输入数1表示加入商品,其它不加入并返回到菜单\n");
        scanf("%d",&livefindadd);
        fflush(stdin);
        system("cls");
        if(1==livefindadd)
        {
            while(1)
            {
                if(!creat(head))
                break ;
            }
        }
        return;
     }
    else 
    printf("   商品名字     价格      编号     数量       日期       种类\n");
    for(livefindpian=head;livefindpian->next!=NULL;livefindpian=livefindpian->next)
    {
        if(livefindpian->kind=='A')
        {
            printf("%10s%10.2f",livefindpian->name,livefindpian->price);
            printf("%10d",livefindpian->number);
            printf("%10d%10s",livefindpian->amount,livefindpian->date);
            printf("%10c",livefindpian->kind);
            printf("\n");
            printf("  ______________________________________________________________\n");
            count++;
        }
     }
    if(count==0)
    printf("没有记录!");
    printf("\n\n");
}
//实质上是文化用品
void pefind()
{
    struct sell*pefindpian ;
    if(head==NULL)
    {
        int pefindadd ;
        printf("没有记录\n\n");
        printf("输入1加入数据,其它返回上一级菜单\n");
        scanf("%d",&pefindadd);
        if(pefindadd==1)
        {
            pefindadd=creat(head);
            if(pefindadd==1)
            printf("添加成功!\n");
        }
        else 
       return;
    }
    else 
    printf("   商品名字     价格      编号     数量       日期\n");
    for(pefindpian=head;pefindpian->next!=NULL;pefindpian=pefindpian->next)
    {
        if(pefindpian->kind=='C')
        {
            printf("%10s%10.2f",pefindpian->name,pefindpian->price);
            printf("%10d",pefindpian->number);
            printf("%10d%10d",pefindpian->amount,pefindpian->date);
			printf("\n");
            printf("  ______________________________________________________________\n");
        }
        
    }
    if(pefindpian==NULL)
    printf("没有记录\n\n");
    printf("\n");
    printf("\n");
}
void pricefind()
{
    int n=0 ;
    struct sell *pricefindpian ;
	float fprice1=0;           //起始价格
	float fprice2=0;           //结束价格
    if(head==NULL)
    {
        printf("数据库没有数据\n\n");
		system("pause");
		system("cls");
        return;
    }
	else
	{
		do
		{printf("输入要查找的价格范围:\n");
		 printf("起始价格:>");
		 scanf("%f",&fprice1);
		 printf("终止价格:>");
		 scanf("%f",&fprice2);
		 fflush(stdin);
		  if(fprice1>fprice2)
		  { 
			 printf("起始价格不能大于终止格\n");
			 system("pause");
		     system("cls");
		  }
		}  while(fprice1>fprice2);
    for(pricefindpian=head;pricefindpian->next!=NULL;pricefindpian=pricefindpian->next)
    {
        if(pricefindpian->price>=fprice1&&pricefindpian->price<=fprice2)
        {
            one_display(pricefindpian);
        }
     }
	}
    if(head==NULL)
    {
		printf("没有记录!\n\n");
	    system("pause");
	}
	if(0==n)
	{
		printf("没有记录!\n\n");
		system("pause");
	}
	printf("\n按任意键继续!");
	getch();
	system("cls");
    printf("\n");
    printf("\n");
}
//产品分析系统
void clever()
{
    printf("栏目建设中......\n");
    printf("\n");
    printf("对不起,此功能还没写好,因为它涉及的方面和知识太多,");
	printf("因此所需的时间和精力相当大,本人还要学习其它功课,此模块留待日后完善!谢谢凉解!");
	printf("我认为一个好的超市系统应该具有人工智能,");
	printf("具有产品销售分析统计等功能,所以在这里加了一个智能模块,但没写好敬请原凉!");
    system("pause");
}
void read()
{   
    int i=0;
	struct sell *pt;
	FILE*fp ;
	FILE*fp1;
	int on;
    if((fp1=fopen("fname1","rb"))==NULL)
	{

⌨️ 快捷键说明

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