栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

C语言实现水果超市信息管理系统

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C语言实现水果超市信息管理系统

//writer: jiandandian245
//time 2021.07.01
#include
#include
#include

typedef struct fruit_node{    
char fruitname[100];  // 水果名称
int  flag;        // 每种水果对应编号
float   price;        // 价格
float   stock    ;        // 库存
struct fruit_node*next;               
}Fruit_Node;

typedef struct transaction_node{  //水果交易信息
char fruitname[10];  //水果名称
int flag ;        //标号
float  Totalprice;     //交易总价
struct transaction_node *next;
}transaction;
 
Fruit_Node* Create_fruit() ;                                     //创建
Fruit_Node* Insert_fruit(Fruit_Node*head);                       //插入水果信息
Fruit_Node* Delete_fruit(Fruit_Node*head, int flag,int &flag5);            // 删除
void print_fruit(Fruit_Node*head);                               //遍历
int  calculation(int flag,float weight,Fruit_Node*head);            //购买计算   
int menu();                

   
int main()
{
    Fruit_Node* head;
    int chioce;
    int flag;
    float weight;
    int flag2;
    int flag3=1;
    float result=0;
    float money=0;
    int flag4;    
    int flag5=1;
    printf("tip:输入1先建立在进行后续操作n");
    printf("******欢迎使用水果超市信息管理系统******n");
    
 do{  
    chioce=menu();
        switch(chioce)
        {
        case 1:  // 创建
        head=Create_fruit();
            break;
        case 2:   //增加水果信息
        head=Insert_fruit(head);    
            break;
        case 3:  //删除水果信息
        printf("输入你要删除的水果编号:") ;
        scanf("%d",&flag);
        head =Delete_fruit(head,flag,flag5);
        if(flag5!=0)
        {
          printf("已删除%d号水果信息n",flag);
          printf("n");
        }
            break;
        case 4:  //查询
        print_fruit(head);
            break;
        case 5:       //购买水果
        do{
        print_fruit(head);
        printf("n");         
        printf("输入需要购买的水果的编号和重量n");
        scanf("%d",&flag2);
        scanf("%f",&weight);
        if(weight<0)
        {
            printf("输入重量非法n");
        }
        else {
        money=calculation(flag2,weight,head);
        printf("当前应付%.2fn",money);
        }
        result=money+result;
        
        printf ("是否继续购买1:是   0:否n");
        scanf("%d",&flag3);
        }while(flag3!=0);
        printf("最终总金额为:%fn",result);
            break;    
     }
     printf("是否继续操作 1继续 0退出n");
     scanf("%d",&flag4);
     printf("n");
     printf("n");
  }while(chioce!=0&&flag4!=0);
    
        
    return 0;
 }
 
int menu() //菜单
{    
    char chioce[20];
    int flag=1;
    printf("1:*******创建************n");
    printf("2:*****增加水果信息******n");
    printf("3:*****删除水果信息******n");
    printf("4:*****查询水果信息******n");
    printf("5:*********购买**********n");
    printf("0:*********退出**********n");
    scanf("%s",chioce);
    while(flag)
    {
        if(strlen(chioce)!=1)
        {
            printf("输入错误,请重新输入!n");
            scanf("%s",chioce);
            continue;
        }
        switch(chioce[0])
        {
        case '0':
        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
    
             flag=0;
            break;
        default:
            printf("输入错误,请重新输入!n");
            scanf("%s",chioce);
            break;
        }
    }
    
    return chioce[0]-'0';
}

Fruit_Node* Create_fruit()
{
    Fruit_Node* head;
    int size=sizeof(Fruit_Node);
    head=(Fruit_Node*)malloc(size);
    head->next=NULL;
    return head;
}

Fruit_Node* Insert_fruit(Fruit_Node*head)
{
    int size=sizeof(Fruit_Node);
    Fruit_Node* tail;
    tail=head;
    while(tail->next!=NULL)
    {
       tail=tail->next;
    }    
    int flag=1;
    char name[10];
    int  bianhao;
    float price;
    float stock;
    do{
        printf("输入水果名称 编号 价格 库存n");
        scanf("%s%d%f%f",name,&bianhao,&price,&stock);
        Fruit_Node* newnode;
        newnode=(Fruit_Node*)malloc(size);
        newnode->flag=bianhao;
        strcpy(newnode->fruitname,name);
        newnode->price=price;
        newnode->stock=stock;
        tail->next=newnode;
        tail=newnode;
        tail->next=NULL;
       printf("是否继续加入:1;是    0:否n");
       scanf("%d",&flag);
    }while(flag!=0);
    
    return head;
}

void print_fruit(Fruit_Node*head)
{
       Fruit_Node* p;
       p=head->next;
       printf("  名称  编号  价格  库存n");
       while(p!=NULL)
       {         
          printf("  %s  %d    %.2f$  %.2fkg  n",p->fruitname,p->flag,p->price,p->stock);
          p=p->next;           
    }
}

Fruit_Node* Delete_fruit(Fruit_Node*head, int flag,int &flag5)
{
       Fruit_Node* p,*q;
       
       p=head;
       q=p->next;
    while(1)
    {
        if(q->flag==flag)
        {
            p->next=q->next;
            free(q);
            break;
        }
        if(q->next==NULL)
        {
            printf("未找到要删除的水果n");    
            printf("n");
            flag5=0;
            break;
        
        }
        p=q;
        q=q->next;            
    }
    return head;
}

int  calculation(int flag,float weight,Fruit_Node*head)
{
    float result;
    float price;
    Fruit_Node* p, *q;
    p=head;
    q=p->next;
    if(head->next==NULL)
    printf("库存中无所要水果n");     
    int a=0;
    while(1)
    {
        if(q->flag==flag)
        {
            price=q->price;
            a=1;
            break;
        }
        if(q==NULL)
        {
            printf("库存中无所要水果n");
            return 0;
        }
         p=q;
        q=q->next;
    }
    if(a==1&&q->stock>=weight)
    {
      result=price*weight;
      q->stock=q->stock-weight;
      return result;    
    }
    if(a==1&&q->stock     {
        printf("库存不足n");
        return 0;    
    }  
}


 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/975069.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号