国产亚洲精品福利在线无卡一,国产精久久一区二区三区,亚洲精品无码国模,精品久久久久久无码专区不卡

當(dāng)前位置: 首頁 > news >正文

遵義公司網(wǎng)站制作哪家好百度推廣登錄首頁網(wǎng)址

遵義公司網(wǎng)站制作哪家好,百度推廣登錄首頁網(wǎng)址,網(wǎng)站網(wǎng)頁怎么設(shè)計,青海高端網(wǎng)站建設(shè)從一個簡單的超市收銀系統(tǒng)&#xff0c;我們來練習(xí)一個系統(tǒng)如何設(shè)計&#xff0c;然后如何實現(xiàn)的思路。 在Ubuntu環(huán)境下使用C語言編寫一個簡單的超市收銀系統(tǒng)。以下是一個基本的示例&#xff0c;涵蓋了商品管理、購物車、交易處理等功能。 代碼 #include <stdio.h> #inc…

從一個簡單的超市收銀系統(tǒng),我們來練習(xí)一個系統(tǒng)如何設(shè)計,然后如何實現(xiàn)的思路。

在Ubuntu環(huán)境下使用C語言編寫一個簡單的超市收銀系統(tǒng)。以下是一個基本的示例,涵蓋了商品管理、購物車、交易處理等功能。

代碼

#include <stdio.h>
#include <stdlib.h>// 商品結(jié)構(gòu)體
struct Product {int id;char name[50];float price;
};// 購物車項結(jié)構(gòu)體
struct ShoppingCartItem {struct Product product;int quantity;
};// 交易結(jié)構(gòu)體
struct Transaction {struct ShoppingCartItem *items;int itemCount;
};// 商品管理結(jié)構(gòu)體
struct Inventory {struct Product *products;int productCount;
};// 初始化商品管理系統(tǒng)
struct Inventory initializeInventory() {struct Inventory inventory;inventory.products = NULL;inventory.productCount = 0;return inventory;
}// 添加商品到庫存
void addProduct(struct Inventory *inventory, struct Product product) {inventory->products = realloc(inventory->products, (inventory->productCount + 1) * sizeof(struct Product));inventory->products[inventory->productCount++] = product;
}// 顯示庫存信息
void displayInventory(struct Inventory inventory) {printf("Inventory:\n");for (int i = 0; i < inventory.productCount; ++i) {printf("%d. %s - $%.2f\n", inventory.products[i].id, inventory.products[i].name, inventory.products[i].price);}
}// 獲取商品信息
struct Product getProductInfo(struct Inventory inventory, int productId) {for (int i = 0; i < inventory.productCount; ++i) {if (inventory.products[i].id == productId) {return inventory.products[i];}}struct Product notFound;notFound.id = -1;return notFound;
}// 初始化交易
struct Transaction initializeTransaction() {struct Transaction transaction;transaction.items = NULL;transaction.itemCount = 0;return transaction;
}// 添加商品到購物車
void addToCart(struct Transaction *transaction, struct Product product, int quantity) {transaction->items = realloc(transaction->items, (transaction->itemCount + 1) * sizeof(struct ShoppingCartItem));transaction->items[transaction->itemCount].product = product;transaction->items[transaction->itemCount].quantity = quantity;++transaction->itemCount;printf("Added %d %s(s) to the cart.\n", quantity, product.name);
}// 顯示購物車
void displayCart(struct Transaction transaction) {float total = 0.0;printf("Shopping Cart:\n");for (int i = 0; i < transaction.itemCount; ++i) {struct ShoppingCartItem item = transaction.items[i];printf("%s - Quantity: %d\n", item.product.name, item.quantity);total += item.product.price * item.quantity;}printf("Total Price: $%.2f\n", total);
}// 完成交易
void completeTransaction(struct Transaction transaction) {printf("Transaction completed. Thank you!\n");free(transaction.items);
}int main() {struct Inventory inventory = initializeInventory();// 添加一些商品addProduct(&inventory, (struct Product){1, "Milk", 2.5});addProduct(&inventory, (struct Product){2, "Bread", 1.0});addProduct(&inventory, (struct Product){3, "Eggs", 3.0});struct Transaction transaction = initializeTransaction();// 超市收銀系統(tǒng)while (1) {displayInventory(inventory);int productId;printf("Enter product ID to add to cart (or 0 to finish): ");scanf("%d", &productId);if (productId == 0) {break;}struct Product product = getProductInfo(inventory, productId);if (product.id != -1) {int quantity;printf("Enter quantity: ");scanf("%d", &quantity);addToCart(&transaction, product, quantity);} else {printf("Product not found.\n");}}displayCart(transaction);completeTransaction(transaction);// 釋放資源free(inventory.products);return 0;
}

編譯:

gcc supermarket.c -o supermarket
./supermarket

程序設(shè)計的詳細(xì)過程:

步驟 1: 定義數(shù)據(jù)模型

在程序設(shè)計的起始階段,定義了程序需要用到的數(shù)據(jù)模型,包括商品、購物車項和交易。使用結(jié)構(gòu)體表示這些概念,其中包括商品(Product)、購物車項(ShoppingCartItem)和交易(Transaction)。

struct Product {int id;char name[50];float price;
};struct ShoppingCartItem {struct Product product;int quantity;
};struct Transaction {struct ShoppingCartItem *items;int itemCount;
};

步驟 2: 商品管理

設(shè)計商品管理系統(tǒng),包括添加商品到庫存和獲取商品信息的功能。使用結(jié)構(gòu)體 Inventory 來保存商品信息,并定義相應(yīng)的函數(shù)。

struct Inventory {struct Product *products;int productCount;
};// 添加商品到庫存
void addProduct(struct Inventory *inventory, struct Product product) {// 通過realloc動態(tài)分配內(nèi)存以保存商品inventory->products = realloc(inventory->products, (inventory->productCount + 1) * sizeof(struct Product));inventory->products[inventory->productCount++] = product;
}// 獲取商品信息
struct Product getProductInfo(struct Inventory inventory, int productId) {for (int i = 0; i < inventory.productCount; ++i) {if (inventory.products[i].id == productId) {return inventory.products[i];}}struct Product notFound;notFound.id = -1;return notFound;
}

步驟 3: 用戶界面

設(shè)計用戶界面,實現(xiàn)基本的用戶交互,允許用戶選擇商品并添加到購物車。使用結(jié)構(gòu)體 CashierUI 和相應(yīng)的函數(shù)。

struct CashierUI {struct Inventory inventory;struct Transaction transaction;
};// 顯示庫存信息
void displayInventory(struct Inventory inventory) {// 輸出商品列表
}// 添加商品到購物車
void addToCart(struct Transaction *transaction, struct Product product, int quantity) {// 將商品添加到購物車
}// 顯示購物車信息
void displayCart(struct Transaction transaction) {// 輸出購物車內(nèi)容
}// 完成交易
void completeTransaction(struct Transaction transaction) {// 輸出總價和完成交易信息
}

步驟 4: 交易處理

實現(xiàn)交易處理功能,計算購物車中商品的總價并完成交易。

// 初始化交易
struct Transaction initializeTransaction() {struct Transaction transaction;transaction.items = NULL;transaction.itemCount = 0;return transaction;
}// 完成交易
void completeTransaction(struct Transaction transaction) {// 輸出總價和完成交易信息// 釋放購物車內(nèi)存free(transaction.items);
}

步驟 5: 主程序

在主程序中,創(chuàng)建超市收銀系統(tǒng)實例,添加一些商品,然后啟動收銀系統(tǒng)。

int main() {// 初始化商品管理系統(tǒng)struct Inventory inventory = initializeInventory();// 添加一些商品addProduct(&inventory, (struct Product){1, "Milk", 2.5});addProduct(&inventory, (struct Product){2, "Bread", 1.0});addProduct(&inventory, (struct Product){3, "Eggs", 3.0});// 初始化交易struct Transaction transaction = initializeTransaction();// 超市收銀系統(tǒng)while (1) {// 顯示庫存信息displayInventory(inventory);int productId;printf("Enter product ID to add to cart (or 0 to finish): ");scanf("%d", &productId);if (productId == 0) {break;}// 獲取商品信息struct Product product = getProductInfo(inventory, productId);if (product.id != -1) {int quantity;printf("Enter quantity: ");scanf("%d", &quantity);// 添加商品到購物車addToCart(&transaction, product, quantity);} else {printf("Product not found.\n");}}// 顯示購物車displayCart(transaction);// 完成交易completeTransaction(transaction);// 釋放資源free(inventory.products);return 0;
}

這個設(shè)計過程包括了程序的整體結(jié)構(gòu)、數(shù)據(jù)模型的定義、功能的實現(xiàn)以及用戶界面的設(shè)計。當(dāng)設(shè)計一個更大規(guī)模的系統(tǒng)時,可能需要考慮更多的功能,例如支付處理、庫存管理、用戶認(rèn)證等。這個簡化的例子提供了一個基本的框架,可以根據(jù)實際需求進行擴展。

http://m.aloenet.com.cn/news/30127.html

相關(guān)文章:

  • 如何將網(wǎng)站指向404微信5000人接推廣費用
  • 網(wǎng)站如何做促銷活動推廣引流話術(shù)
  • 山東網(wǎng)站建設(shè)公司武漢做seo公司
  • 網(wǎng)站建設(shè)歸工商局管還是工信局管查關(guān)鍵詞排名軟件
  • 代做網(wǎng)站排名谷歌優(yōu)化推廣
  • 網(wǎng)站建設(shè)哪家最專業(yè)長沙網(wǎng)絡(luò)營銷學(xué)校
  • 定制開發(fā)app到底要多少錢百度搜索引擎優(yōu)化指南最新版
  • 南海網(wǎng)站建設(shè)公司蘇州網(wǎng)站優(yōu)化排名推廣
  • 怎么查看網(wǎng)站收錄東營seo
  • 哪個新聞網(wǎng)站好友情鏈接是啥意思
  • 做美工一般要收藏哪些網(wǎng)站友情鏈接軟件
  • wordpress tag 收錄肇慶seo按天收費
  • 衡水企業(yè)做網(wǎng)站多少錢使用百度地圖導(dǎo)航收費嗎
  • 長沙銘萬做網(wǎng)站上海網(wǎng)站快速排名優(yōu)化
  • 服裝廠網(wǎng)站模板營銷策劃公司名稱
  • 網(wǎng)站公安備案多久審核app推廣兼職是詐騙嗎
  • 廣州互聯(lián)網(wǎng)項目工作室seo外包公司怎么樣
  • h5網(wǎng)站建設(shè)的具體內(nèi)容企業(yè)營銷網(wǎng)站
  • 上海網(wǎng)站建設(shè)管理推廣的渠道和方法有哪些
  • 鄭州建設(shè)企業(yè)網(wǎng)站百度一下 你就知道官方
  • ??谄髽I(yè)網(wǎng)站建設(shè)愛站網(wǎng)關(guān)鍵詞挖掘查詢工具
  • p2p網(wǎng)站開發(fā)的多少錢一個產(chǎn)品的網(wǎng)絡(luò)營銷方案
  • 大氣集團網(wǎng)站源碼科學(xué)新概念seo外鏈平臺
  • 網(wǎng)站建設(shè)圖文百度網(wǎng)頁網(wǎng)址
  • 做網(wǎng)站購買服務(wù)器國外常用的seo站長工具
  • 企業(yè)網(wǎng)站建設(shè) 西寧公司網(wǎng)站域名續(xù)費一年多少錢
  • 外貿(mào)免費開發(fā)網(wǎng)站建設(shè)網(wǎng)絡(luò)廣告營銷方案策劃內(nèi)容
  • 佛山建站專寧波抖音seo搜索優(yōu)化軟件
  • 日文設(shè)計網(wǎng)站自動點擊器下載
  • 海南??诰W(wǎng)站開發(fā)公司怎么進行網(wǎng)站推廣