C语言超市商品管理系统不带文件操作完整源码

在这里插入图片描述
需要完整源码请看昵称练好
下面展示一些 内联代码片

// A code block
var foo = 'bar';
// An highlighted block
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_PRODUCTS 100

typedef struct {
    int id;
    char name[50];
    char category[50];
    char production_date[20];
    int shelf_life;
    char last_stock_date[20];
    int stock;
    double price;
} Product;


typedef struct {
    Product products[MAX_PRODUCTS];
    int count;
    int totalStock; // 记录总库存量
} Inventory;

void initInventory(Inventory *inventory) {
    inventory->count = 0;
    inventory->totalStock = 0;
}

void addProduct(Inventory *inventory, Product product) {
    if (inventory->count < MAX_PRODUCTS) {
        product.id = inventory->count + 1;
        inventory->products[inventory->count++] = product;
        inventory->totalStock += product.stock; // 更新总库存量
        printf("商品添加成功。\n");
    } else {
        printf("仓库已满,无法添加更多商品。\n");
    }
}

void displayProduct(Product product) {
    printf("商品名: %s\n", product.name);
    printf("所属类别: %s\n", product.category);
    printf("生产日期: %s\n", product.production_date);
    printf("保质期: %d天\n", product.shelf_life);
    printf("最新入库时间: %s\n", product.last_stock_date);
    printf("库存量: %d\n", product.stock);
    printf("价格: %.2f\n", product.price);
}

void searchProductByName(Inventory inventory, char *name) {
    int found = 0;
    for (int i = 0; i < inventory.count; i++) {
        if (strcmp(inventory.products[i].name, name) == 0) {
            displayProduct(inventory.products[i]);
            found = 1;
        }
    }
    if (!found) {
        printf("未找到该商品。\n");
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

徐瑶万正源码,可堪头相,徐福费

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值