安卓版的c语言实现简单的数码产品销售管理系统代码

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// 定义数码产品结构体
typedef struct {
char name[50];
int modelNumber;
float price;
int quantity;
} DigitalProduct;

// 显示菜单
void showMenu() {
printf(“1. 添加数码产品\n”);
printf(“2. 销售数码产品\n”);
printf(“3. 查看库存\n”);
printf(“4. 修改数码产品信息\n”);
printf(“5. 退出\n”);
}

// 添加数码产品
void addProduct(DigitalProduct *products, int *numProducts) {
DigitalProduct newProduct;
printf(“请输入数码产品名称: “);
scanf(”%s”, newProduct.name);
printf(“请输入数码产品型号: “);
scanf(”%d”, &newProduct.modelNumber);
printf(“请输入数码产品价格: “);
scanf(”%f”, &newProduct.price);
printf(“请输入数码产品数量: “);
scanf(”%d”, &newProduct.quantity);

products[*numProducts] = newProduct;
(*numProducts)++;

}

// 销售数码产品
void sellProduct(DigitalProduct *products, int numProducts) {
int choice;
printf(“请选择要销售的数码产品编号: “);
scanf(”%d”, &choice);

if (choice >= 1 && choice <= numProducts) {
    int quantityToSell;
    printf("请输入要销售的数量: ");
    scanf("%d", &quantityToSell);

    if (quantityToSell <= products[choice - 1].quantity) {
        products[choice - 1].quantity -= quantityToSell;
        printf("销售成功!\n");
    } else {
        printf("库存不足,销售失败!\n");
    }
} else {
    printf("无效的选择!\n");
}

}

// 查看库存
void viewInventory(DigitalProduct *products, int numProducts) {
printf(“库存列表:\n”);
for (int i = 0; i < numProducts; i++) {
printf("%d. %s - 型号: %d - 价格: %.2f - 数量: %d\n", i + 1, products[i].name, products[i].modelNumber, products[i].price, products[i].quantity);
}
}

// 修改数码产品信息
void modifyProduct(DigitalProduct *products, int numProducts) {
int choice;
printf(“请选择要修改的数码产品编号: “);
scanf(”%d”, &choice);

if (choice >= 1 && choice <= numProducts) {
    printf("请输入新的数码产品名称(按 Enter 键保持不变): ");
    char newName[50];
    scanf("%s", newName);
    if (strlen(newName) > 0) {
        strcpy(products[choice - 1].name, newName);
    }

    printf("请输入新的数码产品型号(按 Enter 键保持不变): ");
    int newModelNumber;
    scanf("%d", &newModelNumber);
    if (newModelNumber!= 0) {
        products[choice - 1].modelNumber = newModelNumber;
    }

    printf("请输入新的数码产品价格(按 Enter 键保持不变): ");
    float newPrice;
    scanf("%f", &newPrice);
    if (newPrice!= 0) {
        products[choice - 1].price = newPrice;
    }

    printf("请输入新的数码产品数量(按 Enter 键保持不变): ");
    int newQuantity;
    scanf("%d", &newQuantity);
    if (newQuantity!= 0) {
        products[choice - 1].quantity = newQuantity;
    }

    printf("修改成功!\n");
} else {
    printf("无效的选择!\n");
}

}

int main() {
DigitalProduct products[100]; // 假设最多存储 100 种数码产品
int numProducts = 0;
int choice;

do {
    showMenu();
    printf("请选择操作: ");
    scanf("%d", &choice);

    switch (choice) {
        case 1:
            addProduct(products, &numProducts);
            break;
        case 2:
            sellProduct(products, numProducts);
            break;
        case 3:
            viewInventory(products, numProducts);
            break;
        case 4:
            modifyProduct(products, numProducts);
            break;
        case 5:
            printf("退出程序\n");
            break;
        default:
            printf("无效的选择,请重新输入!\n");
    }
} while (choice!= 5);

return 0;

}

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

EYYLTV

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

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

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

打赏作者

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

抵扣说明:

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

余额充值