最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(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語言版)的評論 (共 條)

分享到微博請遵守國家法律
荥经县| 双辽市| 清新县| 台北县| 海伦市| 石景山区| 宁安市| 营口市| 绥中县| 固始县| 九江县| 鄂伦春自治旗| 高尔夫| 厦门市| 和顺县| 五常市| 德令哈市| 彭州市| 湖州市| 吉木萨尔县| 山丹县| 永靖县| 上林县| 凌海市| 长春市| 南昌市| 巩留县| 老河口市| 育儿| 繁峙县| 娱乐| 清涧县| 二连浩特市| 青冈县| 万宁市| 呼玛县| 阿拉善左旗| 安徽省| 通许县| 龙陵县| 贡山|