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

📄 supermarket.cpp

📁 用C语言编程实现 简单超市管理功能。包括 商品的管理(添加、修改、删除、查找)、商品的销售.可作为学习C语言和C语言课程设计的参考.
💻 CPP
📖 第 1 页 / 共 3 页
字号:
//在 VC6.0 下编译
//作者:邹英斌
//邮箱:qvb20974151@163.com
//复制、传播 请不要修改作者信息
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<conio.h>
struct sell 
{
    char name[20];
	
    float price ;
    int number ;
    int amount ;
    char date[8];
    char kind ;
    float gain;
    struct sell*next ;
};
struct users 
{
    char user_name[20];
    char user_password[7];
    char user_kind ;
    struct users*next ;
}
present ;
struct users *user_head=NULL,*pre ;
typedef sell SELL ;
struct sell*phead,*head=NULL ;
int mm=0;
int creatcount=0;   //记录输入了多少个商品
int refer;         //用来保存是否提示的指令,在sell窗口中
void addpassword(char answer[]);  //对输入数据转换
void display(SELL*phead);
void goods();
int creat(SELL*head);
int delect(SELL*phead);
int change(SELL*phead);           //修改键表函数
void find();
void datefind();
void foodfind();
void livefind(struct sell*phead);
void pefind();
void pricefind();
struct sell*sfind(int Number);     //按编号查找
void formfindmenu();               //按类型查找菜单函数
int sell();
void clever();
void read();
void save();
int delect(SELL*phead);
int xiugai(SELL*phead);
void banchuan();
void user();
void user_read();
void user_add();
void user_del();
void user_modify_password();
//以上函数声明

// * 主函数*//
void main()
{
    system("color 18");
	banchuan();               //版权说明函数
	user_read();          //密码输入函数
	read();                   //从文件中读数据进内存函数
    char choice='1' ;
    while(choice!='0')        //显示主控菜单
    {
        system("color 18");
        system("cls");
        printf("                    ****※欢迎使用超市理货系统※****\n");
        printf("         ********************************************************\n");
        printf("                1.商品管理            2.用户管理\n");
        printf("                3.智能系统            4.销售服务\n");
        printf("                0.退出\n");
        printf("         ********************************************************\n");
        printf("请输入你的选择\n>");
        choice=getchar();
        fflush(stdin);
        
        switch(choice)
        {
            case '1' :
            system("cls");
            goods();            //商品管理菜单函数
            break ;
            case '2' :
            system("cls");
            user();
            break ;
            case '3' :
            system("cls");
            clever();
            break ;
            case '4' :
            system("cls");
            while(1)
            {
                int g ;
                g=sell();
                if(0==g)
				{
                save(); 
				break ;
				}
            }
            break ;
            case '0' :
            printf("   谢谢你的使用!");
            printf("\n");
            system("pause");
            exit(0);
            default :
            printf("输入有错,请在1到4间选择:\n");
			getch();
        }
    }
}
//商品函数显示子菜单
void goods()
{   
	FILE  *fp;
	FILE *fp1;
	char c;
	int xu,t,delone;        //修改时输入修改的编号
	struct sell *xiu;
	struct sell *de;       //删除节点用的指针
    char choice='1' ;
    while(choice!='0')
    {
        
        system("cls");
        printf("                   ****商品管理****\n");
        printf("           ======================================\n");
        printf("             1.查找         2.输入新商品\n");
        printf("             0.退出         3.返回上一级菜单\n");
        printf("             4.浏览         5.修改\n");
		printf("             6.删除         7.删除所有并退出\n");
        printf("           ======================================\n");
        printf("输入你的选择:\n>");
        choice=getchar();
        fflush(stdin);
        switch(choice)
        {
            case '0' :
            printf("   谢谢你的使用!");
            printf("\n");
            system("pause");
            exit(0);
            break ;
            case '1' :
            system("cls");
            find();
            break ;
            case '2' :
			{
			int m;
			creatcount=0;    //每次输入商品时,先把记录输入多少个的creatcount赋为0
            system("cls");
			printf("确实要加入商品记录吗?\n");
			printf("输入1确认,其它返回\n>");
			scanf("%d",&m);
			fflush(stdin);
			if(1!=m)break;
			system("cls");
            printf("\n商品的种类说明: ");
            //创建链表
            while(1)
            {
                printf("  A.生活用品  B.食品");
                printf("  C.文化用品  D.其它\n\n");
                //根据返回值判断是否应退出创建 
                if(!creat(head))break ;
            }
			printf("要保存你的输入吗?y  or  n\n");
			c=getchar();
			fflush(stdin);
			if(c=='y')
				save();
                break ;
			}break;
            case '3' :
            return;
            break ;
            case '4' :
            system("cls");
            display(head);
			printf("\n");
            system("pause");
            break ;
			case '5':
			system("cls");
			printf("输入要修改的编号:\n>");
			scanf("%d",&xu);
			fflush(stdin);
			xiu=sfind(xu);
			if(xiu!=NULL)
			t=xiugai(xiu);
			fflush(stdin);
			if(1==t)
			{
				printf("修改成功!\n");
				save();
			    system("pause");
			}break;
			case '6':
				if(present.user_kind!='A')
				{
					printf("指令无法执行!只有管理员才能执行此操作");
					printf("即将返回上一级菜单\n");
					system("pause");
					return;
				}
				printf("输入你要删除的编号:\n>");
				scanf("%d",&delone);
				fflush(stdin);
				de=sfind(delone);
				
				if(de!=NULL)
				{   
					printf("确实要删除吗?输入y确认,其它返回");
				    c=getchar();
				    fflush(stdin);
				    if(c=='y')
					if(!delect(de))
					{
						printf("删除失败!\n");
						system("pause");
                        break;
					}
					save();
				}
				else
					printf("删除不成功!");
				system("pause");
                 break;
			case '7':
				if(present.user_kind!='A')
				{
                   printf("对不起!你不是管理员,不能执行这项操作\n");
				   printf("即将返回上一级菜单!");
		           system("pause");
                   return ;
				}
			printf("确实要删除吗?输入y确认\n");
			c=getchar();
			if(c=='y')
			{
				fp=fopen("fname","wb+");
				fclose(fp);
				fp1=fopen("fname1","wb+");
				fclose(fp1);
				printf("程序即将退出,请重新运行程序!");
				exit(0);
			}
			break;
            default :
            printf("选择有错,请选择1或2:\n");
            system("pause");
            break ;
        }
    }
}
//密码函数

//查找函数
void find()
{
    char choice='1' ;
    while(choice!='0')
    {
        
        //system("cls");
        printf("                ****欢迎使用查找****\n");
        printf("           ====================================\n");
        printf("             1.按类型          2.按价格范围\n");
        printf("             3.按入库日期      4.按编号\n");
        printf("             5.返回上一级菜单  0.退出\n");
        printf("           ====================================\n");
        printf("输入你的选择:\n>");
        choice=getchar();
        fflush(stdin);
        switch(choice)
        {
            case '1' :
            system("cls");
            formfindmenu();
            //formfindmenu 按类型查找菜单函数
            break ;
            case '2' :
            system("cls");
            pricefind();
            break ;
            case '3' :
            system("cls");
            datefind();
            break ;
            case '4' :
            system("cls");
            int num ;
            printf("输入你要查找的编号\n>");
            scanf("%d",&num);
            fflush(stdin);
            if(sfind(num)==NULL)
			printf("没有记录!");
			printf("按任意键返回\n");
			getch();
			system("cls");
			printf("\n\n");
            break ;
            case '5' :
			return ;
            case '0' :
            printf("谢谢你的使用!\n");
            printf("\n");
			system("pause");
            exit(0);
            default :
            return ;
        }
    }
}
//显示函数
void display(SELL*phead)
{
    struct sell*pian ;
    if(phead==NULL)
    {
        printf("没有记录!\n");
        printf("请到商品管理处加入记录!\n");
		return ;
    }
    pian=phead ;
    printf("   商品名字     价格      编号     数量       日期      种类\n");
    for(;pian->next!=NULL;pian=pian->next)
    {
        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");
    }
}
//商品入库函数
int creat(SELL*phead)
{
    int on,rr=0,j=0;
    struct sell*pt ;
	struct sell * pp;
    if(phead==NULL)
    {
        phead=(struct sell*)malloc(sizeof(struct sell));
        phead->next=NULL ;   //为phead建立一无效头结点
    }
    pt=(struct sell*)malloc(sizeof(struct sell));
    if(pt==NULL)
    {
        printf("申请内存失败!");
        return(0);
    }
    printf("输入一个数据就按一次回车:            已输入%d\n",creatcount);
	printf("名字:");
    scanf("%s",pt->name);
	fflush(stdin);
	printf("进货价格:");
	while(1)
	{
		scanf("%f",&pt->gain);
	    fflush(stdin);
		if(pt->gain>0)break;
		else printf("只能输入数字!\n");
	}
    fflush(stdin);
	printf("销售价格:");
    while(1)
	{
		scanf("%f",&pt->price);
		fflush(stdin);
		if(pt->price>0)break;
		else printf("只能输入数字!\n");
	}
    while(1)
	{   
		printf("编号(整型):");
		scanf("%d",&pt->number);
	    fflush(stdin);
		for(pp=phead;pp->next!=NULL;pp=pp->next)
		if(pp->number==pt->number)
		{
			printf("请不要输入和以前商品相同编号!\n");
			fflush(stdin);
			rr=1;
		}
          if(pt->number>0&&rr!=1)break;
		  if(pt->number<0) printf("只能是整型数!\n");
		  rr=0;
	}
    fflush(stdin);
	printf("数量:");
     while(1)
	{
		scanf("%d",&pt->amount);
	    fflush(stdin);
		if(pt->amount>0)break;
		else printf("只能输入大于0的整数!\n");
	}
    fflush(stdin);
	printf("日期:>");
	while(1)
	{
        scanf("%s",pt->date);
        fflush(stdin);
		j=strlen(pt->date);
		if(j<=0||j>8)
		{
			printf("输入长度有误,请重新输入\n");
			continue;
		}
		for( ;pt->date[j-1]!='\0'&&j-1>=0;j--)
		{
	       if(pt->date[j-1]<'0'||pt->date[j-1]>'9')
		   {printf("输入错误,只能输入数字!\n");break;}
		}
		system("pause");
		if(j==0)break;
		else printf("日期:>");
		
	}
	printf("种类(A,B,C,D):");
	while(1)
    {
		scanf("%c",&pt->kind);
		if('A'==pt->kind)break;
		if('B'==pt->kind)break;
		if('C'==pt->kind)break;
		if('D'==pt->kind)break;
		printf("请输入正确种类符号:");
		fflush(stdin);
	}
        system("cls");
    creatcount++;        //用来记录输入商品个数的
    printf("已输入数据如下                               共输入%d件商品\n",creatcount);
    printf("   商品名字     价格      编号     数量       日期      种类\n");
    printf("%10s%10.2f%10d",pt->name,pt->price,pt->number);
    printf("%10d%10s%10c\n",pt->amount,pt->date,pt->kind);
    printf("输入1继续输入商品,其它键停止:\n");
    scanf("%d",&on);
    fflush(stdin);
    pt->next=phead ;
    head=pt ;
    if(1!=on)
    {
        system("cls");

⌨️ 快捷键说明

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