商品結賬c語言,c語言結賬系統

本文目錄一覽:

用c語言製作商店商品管理系統

#include stdio.h

#include conio.h

#include bios.h

#include dos.h

#include malloc.h

#define NULL 0

#define LEN sizeof(struct mcd)

struct data /*聲明一個日期的結構體類型*/

{

int year;

int month;

int day;

};

struct mcd /*聲明有關商品信息的結構體類型*/

{

int code; /*編 號*/

char name[12]; /*品 名*/

long price; /*單 價*/

int num; /*數 量*/

char place[20]; /*產 地*/

struct data putdate; /*入庫時間*/

struct data selldate; /*銷售時間*/

struct mcd * next; /*運用指針處理鏈表*/

};

int n; /*記錄鏈表有幾條數據*/

struct mcd *head; /*聲明鏈表頭的指針*/

creat() /*輸入商品信息的函數*/

{

struct mcd *p1,*p2;

n=0;

p1=p2=(struct mcd *)malloc(LEN); /*開闢一個新單元存放信息*/

head=p1;

loop: {

clrscr();

printf(“商品錄入系統\n”);

printf(“錄入號:%d\n”,n+1);

printf(“編 碼:”);

scanf(“%d”,p1-code);

printf(“品 名:”);

scanf(“%s”,p1-name);

printf(“單 價:”);

scanf(“%ld”,p1-price);

printf(“數 量:”);

scanf(“%d”,p1-num);

printf(“產 地:”);

scanf(“%s”,p1-place);

printf(“入庫時間:”);

scanf(“%d-%d-%d”,p1-putdate.year,p1-putdate.month,p1-putdate.day);

}

while(p1-num!=0)

{

n=n+1;

if(n==1)head=p1;

else p2-next=p1;

p2=p1;

p1=(struct mcd *)malloc(LEN);

goto loop;

}

p2-next=NULL;

main();

}

print() /*輸出數據列表的函數*/

{

int m=0;

struct mcd *p;

clrscr();

printf(“編 號||品 名||單 價||數 量|| 產 地 ||入 庫 時 間\n”);

p=head;

if(head!=NULL)

do

{

printf(“%-10d%-14s%-12ld%-10d%-22s%-4d-%-2d-%-2d\n”,p-code,p-name,p-price,p-num,p-place,p-putdate.year,p-putdate.month,p-putdate.day);

p=p-next;

m=m+1;

if(m%23==0){gotoxy(10,25);printf(“按任意鍵繼續.”);getch();}

}while(p!=NULL);

getch();

main();

}

sell()

{

int code,m=3,ch;

long sum=0;

struct mcd *p1;

struct date today;

getdate(today);

clrscr();

printf(“商品銷售系統\n”);

printf(“編 號||||品 名|||| 產 地 ||||單 價(元)||||出 售 時 間\n”);

loop:

do{

gotoxy(23,25);

printf(“按任意鍵繼續,F2結帳,ESC鍵退出”);

ch=bioskey(0);

}while(0);

switch(ch)

{

case 15360:{

if(sum==0)

{

gotoxy(1,m);printf(“還沒有購買商品!”);

getch();

sell();

break;

}

else {

gotoxy(1,m);

printf(“——————————————————————————“);

gotoxy(47,m+1);

printf(“總價: %-12ld元”,sum);

getch();

main();

break;

}

}

case 283:{main();break;}

default:

{

gotoxy(23,25);

printf(“請輸入商品編碼,會顯示商品信息”);

gotoxy(1,m);

scanf(“%d”,code);

if(head==NULL)

{

printf(“你還沒有進貨.”);

getch();

main();

break;

}

p1=head;

while(code!=p1-codep1-next!=NULL)

{p1=p1-next;}

if(code==p1-code)

{

gotoxy(13,m);

printf(“%-16s%-24s%-16ld%4d-%2d-%2d”,p1-name,p1-place,p1-price,today.da_year,today.da_mon,today.da_day);

m=m+1;

p1-num=p1-num-1;

sum=sum+p1-price;

}

}

goto loop;

}

}

go()

{

int ch;

clrscr();

printf(“請問你要進行什麼操作?\n1,插入;2,刪除;3,什麼也不做;\n”);

loop:

do{

ch=bioskey(0);

}while(0);

switch(ch)

{

case 561:insert();break;

case 818:del();break;

case 1075:main();break;

case 283:break;

default:{gotoxy(1,3);printf(“請按數字鍵選擇!”);goto loop;}

}

getch();

main();

}

insert()

{

struct mcd *p0,*p1,*p2;

p0=p1=p2=(struct mcd*)malloc(LEN);

p1=head;

clrscr();

printf(“請輸入要插入的商品的信息:\n”);

printf(“編 碼:”);

scanf(“%d”,p0-code);

printf(“品 名:”);

scanf(“%s”,p0-name);

printf(“單 價:”);

scanf(“%ld”,p0-price);

printf(“數 量:”);

scanf(“%d”,p0-num);

printf(“產 地:”);

scanf(“%s”,p0-place);

printf(“入庫時間:”);

scanf(“%d-%d-%d”,p0-putdate.year,p0-putdate.month,p0-putdate.day);

if(head==NULL)

{

head=p0;

p0-next=NULL;

}

else

{

while((p0-codep1-code)(p1-next!=NULL))

{

p2=p1;

p1=p1-next;

}

if(p0-code=p1-code)

{

if(head==p1)head=p0;

else p2-next=p0;

p0-next=p1;

}

else

{

p1-next=p0;p0-next=NULL;

}

}

n=n+1;

print();

}

del()

{

int code;

struct mcd *p1,*p2;

clrscr();

printf(“請輸入要刪除商品的編號:”);

scanf(“%d”,code);

if(head==NULL)

{

printf(“你還沒有進貨.”);

getch();

main();

}

p1=head;

while(code!=p1-codep1-next!=NULL)

{

p2=p1;

p1=p1-next;

}

if(code==p1-code)

{

if(code==head)head=p1-next;

else p2-next=p1-next;

n=n-1;

print();

}

else

{

printf(“找不到這條商品信息.”);

getch();

print();

}

}

main()

{

do{

clrscr();

printf(” . : : \n”);

printf(” ‘. :””””: : : :””:””:\n”);

printf(” ‘. : : :””” :””” : : :\n”);

printf(” ……………. : : :’, :’, ””’:””’: : :\n”);

printf(” ‘. .’ : : : ‘, : ‘, : :….:….:\n”);

printf(” ‘. .’ : : ,’ ,’ : : : :\n”);

printf(” ‘.’ : : ‘, : : : :\n”);

printf(“………:……….. :……..: : ‘, : :….:….:\n”);

printf(” …………… :”””””””’: ””:”” : \n”);

printf(” : , , : :”””: :”””: ,’ : : \n”);

printf(” : , , : : : : : :””””’: : ,’ : \n”);

printf(” : , , : : : : : : : : ,’ ….:…. \n”);

printf(” :, :”””’: : : : : : : : :,’ : \n”);

printf(” : : : : : : : : :””””” ,’ : \n”);

printf(” : : : : : : : : :………. ,’ : \n”);

printf(” : :…….: : : : : : : : ‘ : \n”);

printf(” : : : : : : : : ……:…..\n”);

printf(” : ..: :……: :……: :………: \n”);

gotoxy(60,19);

printf(“趙飛宇製造 V1.0”);

gotoxy(10,21);

printf(“1,銷售系統;2,進貨系統;3,查看列表;4,插入刪除;5,銷售盈虧;6,幫助文檔”);

gotoxy(32,24);

printf(“按ESC鍵退出”);

key();

}while(0);

}

key()

{

int ch;

loop:

do{

ch=bioskey(0);

}while(0);

switch(ch)

{

case 561:sell();break;

case 818:creat();break;

case 1075:print();break;

case 1332:go();break;

case 283:break;

default:

{

gotoxy(30,22);

printf(“請按數字鍵選擇!”);

goto loop;

}

}

}

運用c語言程序寫一個超市收銀情況

#include stdio.h

#include stdlib.h

#define DIS 0.7

typedef struct buyrecond{

int id; //序號

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

float unitprice; //單價

int num; //數量

} BuyRecond;

typedef struct buylist{

BuyRecond *list;

int maxSize;

int size;

} BuyList;

//建立線性表

BuyList *createList(int maxsize);

void destroyList(BuyList *list);

//向表內添加元素

int appendRecond(BuyList *list,BuyRecond *recond);

//顯示線性表

void displayList(BuyList *list);

int main()

{

int e;

BuyList *buyTab;

buyTab = createList(3);

e=1;

while(e!=0){

BuyRecond rec;

printf(“輸入第%d種商品名稱(輸入-1結束輸入):”,e);

gets(rec.name);

if(rec.name[0]==’-‘ rec.name[1]==’1′ rec.name[2]==’\0’)

break;

printf(“輸入第%d種商品單價:”,e);

scanf(“%f”,rec.unitprice);

printf(“輸入第%d種商品數量:”,e);

scanf(“%d”,rec.num);

getchar();

if(!appendRecond(buyTab,rec))

break;

}

displayList(buyTab);

destroyList(buyTab);

getchar();

return 0;

}

BuyList *createList(int maxsize)

{

BuyList *pl = (BuyList *)malloc( sizeof(BuyList) );

pl-list = (BuyRecond *)calloc(maxsize, sizeof(BuyRecond));

pl-size = 0;

pl-maxSize = maxsize;

return pl;

}

void destroyList(BuyList *list)

{

free( list-list );

free( list );

}

int appendRecond(BuyList *list,BuyRecond *recond)

{

if(list-size == list-maxSize){

BuyRecond *p = (BuyRecond *)calloc(list-size * 2, sizeof(BuyRecond));

if(p==NULL){

printf(“內存分配失敗!無法添加元素。\n”);

return 0;

}

memcpy(p, list-list, list-size*sizeof(BuyRecond));

list-maxSize = list-size * 2;

free(list-list);

list-list = p;

}

recond-id=list-size+1;

list-list[list-size]=*recond;

list-size++;

return 1;

}

void displayList(BuyList *list)

{

int i;

float x;

printf(“\n%-4s %c%-20s %10s %10s %10s %10s\n”,

“項次”,’|’,”商品名稱”,”單價”,”數量”,”小計”,”優惠價”);

for(i=0;ilist-size;++i){

x=(list-list[i].num)*(list-list[i].unitprice);

printf(“%-4d %c%-20s %10.0f %10d %10.2f %10.2f\n”,

list-list[i].id,’|’,list-list[i].name,

list-list[i].unitprice,list-list[i].num,

x,x*DIS);

}

printf(“總計(%d項)\n”,list-size);

}

大一C語言:模擬超市售貨系統

給親些提示幫助吧,商品做一個結構體,包含價格,種類,庫存數量,條形碼,折扣。

超市的數據是按商品來的,和客人無關喔~超市不需要知道客人的情況,只需要知道商品的情況。

如果非要客人信息,那麼可以改成會員制度,那麼客人的結構體就是是否會員,購買日期,購買商品品種,購買數量,結賬價格。

最後還需要一個購買事件結構體,就是購買總額,結賬總額,找零總額。

接下來3大主要數據部分準備完畢,接下來就是過程編程了,就需要模擬一下購物過程來操作以上的3大數據結構就行了。

還有不懂請私信我私聊。

C語言編寫“超市結賬系統” 急急急!!!

#include

stdio.h

#include

fstream

#include

iostream

#include

string

#include

vector

#include

assert.h

using

namespace

std;

//

Item

info

base

class

class

ItemInfo{

public:

ItemInfo(){}

ItemInfo(string

barcode,

string

name,

float

price)

{

this-barcode

=

barcode;

this-name

=

name;

this-price

=

price;

}

ItemInfo(string

barcode)

{

this-barcode

=

barcode;

}

void

Display()

{

cout

barcode

“\t”name”\t”price

endl;

}

void

Input()

{

cout

“輸入條形碼:”

endl;

cin

barcode;

cout

“輸入名稱:”

endl;

cin

name;

cout

“輸入價格:”

endl;

cin

price;

}

void

Modify()

{

cout

“輸入名稱:”

endl;

cin

name;

cout

“輸入價格:”

endl;

cin

price;

}

friend

ostream

operator(ostream

stream,

ItemInfo

item){

stream

item.barcode

‘\t’

item.price

‘\t’

item.nameendl;

return

stream;

}

friend

istream

operator(istream

stream,

ItemInfo

item){

stream

item.barcode

item.price

item.name;

return

stream;

}

public:

string

barcode;

string

name;

float

price;

};

//

Interface

class

class

DataProvider{

public:

virtual

void

GetFullData(string

barcode,

string

name,

float

price)

=

0;

};

//

Purchase

item

class

class

ItemPurchaseInfo

:

public

ItemInfo{

public:

ItemPurchaseInfo():ItemInfo(){}

ItemPurchaseInfo(string

barcode,

int

count=1)

:

ItemInfo(barcode)

{

this-count

=

count;

}

//

Rember

to

call

this

when

barcode

set

void

GetFullData(DataProvider

aPro)

{

aPro.GetFullData(barcode,

name,

price);

}

void

Input()

{

cout

“輸入條形碼:”

endl;

cin

barcode;

cout

“輸入數量:”

endl;

cin

count;

}

void

Display()

{

cout

barcode

“\t”name”\t”price”\t”count

endl;

}

public:

string

barcode;

int

count;

};

//

Item

list

class

class

ItemList

{

public:

ItemList(){items.clear();}

friend

ostream

operator(ostream

stream,

ItemList

list){

unsigned

int

count

=

list.items.size();

stream

countendl;

for(unsigned

int

i(0);icount;i++)

stream

list.items.at(i);

return

stream;

}

friend

istream

operator(istream

stream,

ItemList

list){

unsigned

int

count(0);

stream

count;

list.items.clear();

for(unsigned

int

i(0);icount;i++){

ItemInfo

item;

stream

item;

list.items.insert(list.items.end(),

item);

}

return

stream;

}

void

Add(ItemInfo

item)

{

items.insert(items.end(),

item);

}

void

Modify()

{

string

barcode;

cout

“輸入條形碼:”

endl;

cin

barcode;

for(unsigned

int

i(0);iitems.size();i++)

{

if(items.at(i).barcode

==

barcode

)

{

items.at(i).Modify();

}

}

}

public:

vectorItemInfo

items;

};

//

Purchase

item

list

class

class

PurchaseItemList

{

public:

PurchaseItemList(){items.clear();}

void

Add(ItemPurchaseInfo

item)

{items.insert(items.end(),

item);}

public:

vectorItemPurchaseInfo

items;

};

//

Implements

the

interface

class

class

Cashier

:

public

DataProvider

{

public:

Cashier()

:

purchase(),

stock(){}

~Cashier(){}

public:

//

User

funcs

void

CheckIn(){

purchase.items.clear();

int

opt(0);

do

{

unsigned

int

i(0);

ItemPurchaseInfo

ipi;

ipi.Input();

purchase.Add(ipi);

cout

“按0退出,任意鍵繼續”

endl;

cin

opt;

}

while(opt);

}

void

CheckOut(){

for(unsigned

int

i(0);

i

purchase.items.size();

i++)

{

purchase.items.at(i).GetFullData(

*this

);

}

float

checkin(0);

cout

“輸入收款數:”

endl;

cin

checkin;

DisplayList(checkin);

}

void

Display()

{

cout

endl”商品清單

stock.items.size()

endl;

cout

“————————————–“

endl;

for(unsigned

int

i(0);i

stock.items.size();

i++){

stock.items.at(i).Display();

}

cout

“————————————–“

endl;

}

void

DisplayList(float

checkin)

{

cout

endl”購物小票清單”

endl;

cout

“————————————–“

endl;

float

total(0.0);

for(unsigned

int

i(0);

i

purchase.items.size();

i++)

{

purchase.items.at(i).Display();

total

+=

purchase.items.at(i).price

*

purchase.items.at(i).count;

}

cout

“————————————–“

endl;

cout

“貨款合計:”

total

“元”

endl;

cout

“收款數:”

checkin

“元”

endl;

float

change(checkin-total);

assert(

change

=

0.0);

cout

“找零:”

change

“元”

endl

endl;

}

friend

ostream

operator(ostream

stream,

Cashier

c){

stream

c.stock;

return

stream;

}

friend

istream

operator(istream

stream,

Cashier

c){

c.stock.items.clear();

stream

c.stock;

return

stream;

}

public:

//

interface

func

void

GetFullData(string

barcode,

string

name,

floatprice)

{

//

go

through

stock

and

find

the

item

by

barcode

matching

for(unsigned

int

i(0);

i

stock.items.size();

i++)

{

if(stock.items.at(i).barcode

==

barcode)

{

name

=

stock.items.at(i).name;

price

=

stock.items.at(i).price;

}

}

}

public:

PurchaseItemList

purchase;

ItemList

stock;

};

int

main()

{

int

opt(0);

Cashier

cashier;

ifstream

fin(“data.bin”,

ios::in

|

ios::binary);

fin.seekg(0,

ios::beg);

//cashier.stock.Load(fin);

fin

cashier;

fin.close();

ofstream

fout;

ItemInfo

item;

do{

cout

“1.

新購買”

endl;

cout

“2.

輸入新商品信息”

endl;

cout

“3.

修改商品信息”

endl;

cout

“4.

顯示商品信息”

endl;

cout

“0.

退出”

endl;

cin

opt;

switch(opt)

{

case

1:

cashier.CheckIn();

cashier.CheckOut();

break;

case

2:

item.Input();

cashier.stock.Add(item);

fout.open(“data.bin”,

ios::out|

ios::binary);

fout.seekp(0,ios::beg);

fout

cashier;

fout.close();

break;

case

3:

cashier.stock.Modify();

fout.open(“data.bin”,

ios::out|

ios::app

|

ios::binary);

fout

cashier;

fout.close();

break;

case

4:

cashier.Display();

break;

default:

break;

}

}

while(opt);

return

0;

}

C語言如何用C-Free編寫一個超市收銀軟件,就是能買東西,完了進行結賬

因為C++兼容C語言的,所以在VisualStudio2010新建一個C++項目就可以實現編寫一個C語言程序方法如下:1、電腦上安裝微軟公司的VS2010,可以從dreamspark上下載正版或通過其他途徑獲得,安裝即可。2、打開VS20103、可以通過點擊文件–新建–項目建立工程或者點擊歡迎頁的“新建項目”建立工程。4、彈出對話框,勾選“空項目”建立工程,工程名可任意填英文字符,如project1,其他不用填。5、建立工程後,在右側有一個“解決方案資源管理器”,找到源文件,右擊,再左擊添加–新建項–C++文件,這樣就在工程project1下建立了一個源文件,名稱比如為源.cpp,就可以編輯代碼了。如果你已經用其他字符編輯軟件寫好了C++源程序,也可以右擊源文件,左擊–現有項,在文件夾中找到你的源程序添加到工程下。6、編輯好了源文件,就可以運行或調試了,初學者是寫簡單的程序,所以只用一個源文件就行了。點擊調試–開始運行(不調試)就直接編譯運行,有錯誤的話系統會提示。7、如果要調試,可以點擊調試–逐語句(F10)或逐過程(F11)8、調試前點擊調試–窗口(也就是watch)可以選擇不同的顯示結果,可以顯示出變量的變化過程,方便調試。點擊“繼續”結束調試。

原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/288784.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
小藍的頭像小藍
上一篇 2024-12-24 03:00
下一篇 2024-12-24 03:00

相關推薦

  • Deepin系統分區設置教程

    本教程將會詳細介紹Deepin系統如何進行分區設置,分享多種方式讓您了解如何規劃您的硬盤。 一、分區的基本知識 在進行Deepin系統分區設置之前,我們需要了解一些基本分區概念。 …

    編程 2025-04-29
  • AES加密解密算法的C語言實現

    AES(Advanced Encryption Standard)是一種對稱加密算法,可用於對數據進行加密和解密。在本篇文章中,我們將介紹C語言中如何實現AES算法,並對實現過程進…

    編程 2025-04-29
  • 學習Python對學習C語言有幫助嗎?

    Python和C語言是兩種非常受歡迎的編程語言,在程序開發中都扮演着非常重要的角色。那麼,學習Python對學習C語言有幫助嗎?答案是肯定的。在本文中,我們將從多個角度探討Pyth…

    編程 2025-04-29
  • Java任務下發回滾系統的設計與實現

    本文將介紹一個Java任務下發回滾系統的設計與實現。該系統可以用於執行複雜的任務,包括可回滾的任務,及時恢復任務失敗前的狀態。系統使用Java語言進行開發,可以支持多種類型的任務。…

    編程 2025-04-29
  • 如何在樹莓派上安裝Windows 7系統?

    隨着樹莓派的普及,許多用戶想在樹莓派上安裝Windows 7操作系統。 一、準備工作 在開始之前,需要準備以下材料: 1.樹莓派4B一台; 2.一張8GB以上的SD卡; 3.下載並…

    編程 2025-04-29
  • Python被稱為膠水語言

    Python作為一種跨平台的解釋性高級語言,最大的特點是被稱為”膠水語言”。 一、簡單易學 Python的語法簡單易學,更加人性化,這使得它成為了初學者的入…

    編程 2025-04-29
  • OpenJudge答案1.6的C語言實現

    本文將從多個方面詳細闡述OpenJudge答案1.6在C語言中的實現方法,幫助初學者更好地學習和理解。 一、需求概述 OpenJudge答案1.6的要求是,輸入兩個整數a和b,輸出…

    編程 2025-04-29
  • Python按位運算符和C語言

    本文將從多個方面詳細闡述Python按位運算符和C語言的相關內容,並給出相應的代碼示例。 一、概述 Python是一種動態的、面向對象的編程語言,其按位運算符是用於按位操作的運算符…

    編程 2025-04-29
  • 分銷系統開發搭建

    本文主要介紹如何搭建一套完整的分銷系統,從需求分析、技術選型、開發、部署等方面進行說明。 一、需求分析 在進行分銷系統的開發之前,我們首先需要對系統進行需求分析。一般來說,分銷系統…

    編程 2025-04-29
  • Python語言由荷蘭人為中心的全能編程開發工程師

    Python語言是一種高級語言,很多編程開發工程師都喜歡使用Python語言進行開發。Python語言的創始人是荷蘭人Guido van Rossum,他在1989年聖誕節期間開始…

    編程 2025-04-28

發表回復

登錄後才能評論