无码av一区二区三区无码,在线观看老湿视频福利,日韩经典三级片,成 人色 网 站 欧美大片在线观看

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

便利店商品管理系統(tǒng)(C語言版)

2023-05-23 13:09 作者:Developer999  | 我要投稿

#include <stdio.h>

#include <stdlib.h>

#include <string.h>


typedef struct {

? ? int id;? ? ? ? ? ? ?// 商品編號

? ? char name[20];? ? ? // 商品名稱

? ? float price;? ? ? ? // 商品價格

? ? int quantity;? ? ? ?// 商品數(shù)量

} Product;


// 添加新商品到庫存列表

void addProduct(Product* productList, int* count) {

? ? printf("添加新品:\n");


? ? productList[*count].id = *count + 1;


? ? printf("請輸入商品名字:");

? ? scanf("%s", productList[*count].name);

? ??

? ? printf("請輸入價格:");

? ? scanf("%f", &productList[*count].price);


? ? printf("請輸入數(shù)量:");

? ? scanf("%d", &productList[*count].quantity);


? ? (*count)++;

? ? printf("添加成功!\n");

}


// 顯示庫存列表

void displayProducts(Product* productList, int count) {

? ? printf("庫存列表:\n\n");

? ? printf("編號\t名稱\t價格\t數(shù)量\n");

? ? for (int i = 0; i < count; i++) {

? ? ? ? printf("%d\t%s\t%.1f\t%d\n", productList[i].id, productList[i].name,?

? ? ? ? ? ? productList[i].price, productList[i].quantity);

? ? }

}


// 刪除指定編號的商品

void removeProduct(Product* productList, int* count) {

? ? int productId;

? ? displayProducts(productList, *count);

? ? printf("輸入編號刪除:");

? ? scanf("%d", &productId);


? ? if (productId <= 0 || productId > *count) {

? ? ? ? printf("無效編號!\n");

? ? ? ? return;

? ? }


? ? for (int i = productId-1; i < *count-1; i++) {

? ? ? ? productList[i] = productList[i+1];

? ? }

? ? (*count)--;

? ? printf("刪除成功!\n");

}


// 修改指定編號的商品

void updateProduct(Product* productList, int count) {

? ? int productId;

? ? displayProducts(productList, count);

? ? printf("輸入編號修改:");

? ? scanf("%d", &productId);


? ? if (productId <= 0 || productId > count) {

? ? ? ? printf("無效編號!\n");

? ? ? ? return;

? ? }


? ? printf("請輸入名稱:");

? ? scanf("%s", productList[productId-1].name);

? ? printf("請輸入價格:");

? ? scanf("%f", &productList[productId-1].price);

? ? printf("請輸入數(shù)量:");

? ? scanf("%d", &productList[productId-1].quantity);

? ? printf("修改成功!\n");

}


// 超市管理系統(tǒng)主函數(shù)

int main() {

? ? Product productList[100]; // 最多存儲100個商品

? ? int productCount = 0;? ? ?// 實際商品數(shù)量

? ? int choice;


? ? while (1) {

? ? ? ? printf("------------------\n");

? ? ? ? printf("1. 添加新商品\n");

? ? ? ? printf("2. 查看庫存列表\n");

? ? ? ? printf("3. 刪除指定商品\n");

? ? ? ? printf("4. 修改指定商品\n");

? ? ? ? printf("5. 退出程序\n");

? ? ? ? printf("------------------\n");


? ? ? ? printf("請選擇您的操作:");

? ? ? ? scanf("%d", &choice);


? ? ? ? switch (choice) {

? ? ? ? ? ? case 1:

? ? ? ? ? ? ? ? addProduct(productList, &productCount);

? ? ? ? ? ? ? ? break;

? ? ? ? ? ? case 2:

? ? ? ? ? ? ? ? displayProducts(productList, productCount);

? ? ? ? ? ? ? ? break;

? ? ? ? ? ? case 3:

? ? ? ? ? ? ? ? removeProduct(productList, &productCount);

? ? ? ? ? ? ? ? break;

? ? ? ? ? ? case 4:

? ? ? ? ? ? ? ? updateProduct(productList, productCount);

? ? ? ? ? ? ? ? break;

? ? ? ? ? ? case 5:

? ? ? ? ? ? ? ? printf("感謝使用!\n");

? ? ? ? ? ? ? ? exit(0);

? ? ? ? ? ? default:

? ? ? ? ? ? ? ? printf("無效選擇!\n");

? ? ? ? }

? ? }


? ? return 0;

}


便利店商品管理系統(tǒng)(C語言版)的評論 (共 條)

分享到微博請遵守國家法律
田林县| 石阡县| 社旗县| 瑞金市| 柘城县| 保德县| 渑池县| 海城市| 阜康市| 济宁市| 罗源县| 同江市| 东乡族自治县| 喀喇沁旗| 和静县| 安化县| 鄂托克前旗| 西畴县| 黄石市| 南投县| 万年县| 女性| 新民市| 陆河县| 连江县| 无棣县| 桃源县| 洮南市| 门源| 金华市| 郎溪县| 开原市| 古浪县| 会昌县| 神池县| 黑山县| 永和县| 枣阳市| 高清| 亚东县| 房山区|