c语言程序编写超市代码(用c语言编写的代码程序)

今天给各位分享c语言程序编写超市代码的知识,其中也会对用c语言编写的代码程序进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

1、C语言如何用C-Free编写一个超市收银软件,就是能买东西,完了进行结账2、求一个简单的C语言超市收银系统3、C语言的关于超市的代码4、用c语言设计一个超市管理系统程序,要求能添加商品,能查询商品,能购买商品,能展示商品。5、用c语言编写一个程序,某超市举行店庆活动,所有商品9.5折销售。根据商品单价p,计算商品实付金额c6、C语言编写“超市结账系统” 急急急!!!

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)可以选择不同的显示结果,可以显示出变量的变化过程,方便调试。点击“继续”结束调试。

c语言程序编写超市代码(用c语言编写的代码程序)

求一个简单的C语言超市收银系统

这里没有商品信息,需要自己编码添加。

#include stdio.h

#include string.h

typedef struct ln //会员信息

{

char id[20];//会员账号

char key[20];//会员密码

int sum;//会员积分

struct ln *next;

} member;

struct lm//商品信息

{

int id;//商品编号

char name[50];//商品名称

int stock;//商品库存

} goods[1000];

member *registe(member *t);//注册;

void buy();

int main()

{

member *head=(member *)malloc(sizeof(member));

strcpy(head-id, “0”), strcpy(head-key, “0”);//超市管理员

head-next=NULL;

int i, a, n, boo=0;

while(1)

{

printf(” 注册会员请按1:\n”);

printf(” 会员直接登录请按2:\n”);

printf(” 退出请按0:\n”);

scanf(“%d”, a);

if(a==0) break;

if(a==1) head=registe(head);

else if(a==2) boo=login(head);

if(boo) break;

}

if(a boo==1)

{

printf(” 尊贵的会员,您登录成功!\n”);

buy();

}

printf(” 已经安全退出\n”);

}

member *registe(member *t)//注册

{

printf(” 现在开始会员注册\n\n”);

char id[20], key[20];

member *p, *q, *r;

p=t;

while(p-next) p=p-next;//寻找链表中最后一个结点

while(1)

{

printf(” 请输入您注册的账号,密码:\n”);

scanf(“%s %s”, id, key);

q=t;

while(q)//判断该账号是否已经被注册

{

if(strcmp(q-id, id)==0) break;

else q=q-next;

}

C语言的关于超市的代码

case ‘1’:if (number1 – n 10);这句中case后面的1不用打引号,直接跟数字就可以了,单引号一般用于其字符的ascll码,后面的几句case也是同一个问题

用c语言设计一个超市管理系统程序,要求能添加商品,能查询商品,能购买商品,能展示商品。

超市管理系统

*/

#includestdio.h

#includestring.h

//欢迎界面//

void welcome();

//功能浏览//

void mainMenu();

//购物结算//

void saleCalc();

//进货管理//

void addGoods();

//修改信息

void updateGoods();

//显示商品//

void showGoods();

//删除商品//

void deleteGoods();

//查询商品//

int searchGoods();

//购买结算

void saleCalc();

//更新库存//

void updateGoodsNum(int number,char name[50]);

//结构体

struct goods

{

char name[50];//商品名称

int num;//商品数量

float price;//商品价格

};

int count;//商品种类数量

goods list[1000];//声明goods的变量数组

char name[50];

void main()//主函数

{

int num;

welcome();

do{

mainMenu();

printf(“请选择功能:”);

scanf(“%d”,num);

switch(num)

{

case 1:

saleCalc();

break;

case 2:

addGoods();

break;

case 3:

updateGoods();

break;

case 4:

showGoods();

break;

case 5:

deleteGoods();

break;

case 0:

break;

}

}while(num!=0);

}

void welcome()//欢迎界面

{

printf(“————————————————————————-\n”);

printf(“****************欢迎使用超市管理系统*******************\n”);

printf(“————————————————————————-\n”);

}

void mainMenu()//功能浏览界面

{

printf(“****1.购物结算****\n”);

printf(“****2.进货管理****\n”);

printf(“****3.修改商品****\n”);

printf(“****4.显示商品****\n”);

printf(“****5.删除商品****\n”);

printf(“****0.退出系统****\n”);

}

//查询信息

int searchGoods()//查询商品信息

{

printf(“请输入您要购买商品的名字:”);

scanf(“%s”,name);

for(int i=0;icount;i++)

{

if(stricmp(name,list[i].name)==0)

{

return 1;

}

else

{

printf(“对不起了,没有找到%c商品\n”,name);

return -1;

}

}

}

//购物结算

void saleCalc()//购物结算

{

int number,i,s;

float priceGoods=0,sum=0,money;

char c=’ ‘;

s=searchGoods();

do

{

if(s==-1)

{

s=searchGoods();

}else

{

printf(“该商品b存在”);

for(i=0;icount;i++)

{

if(strcmp(name,list[i].name)==0)

{

priceGoods=list[i].price;

break;

}

}

printf(“请输入您要购买的数量:”);

scanf(“%d”,number);

sum=priceGoods*number;

updateGoodsNum(-number,name);

printf(“是否继续购买(y/n)”);

fflush(stdin);

c=getchar();

}

}while(c==’y’||c==’Y’);

printf(“本次消费总金额为:%.2f”,sum);

printf(“请输入您的实际付款金额:”);

scanf(“%f”,money);

printf(“找零:%.2f\n”,money-sum);

}

//进货管理

void addGoods() //商品的录入

{

int i=0;

char c=’ ‘;

do

{

printf(“请输入商品的名称:”);

fflush(stdin);

scanf(“%s”,list[i].name);

printf(“请输入商品的数量:”);

scanf(“%d”,list[i].num);

printf(“请输入商品的单价:”);

scanf(“%f”,list[i].price);

printf(“是否继续(y/n)”);

fflush(stdin);

c=getchar();

}while(c==’Y’||c==’y’);

}

//更新库存

void updateGoodsNum(int number,char name[50])

{

int i;

for(i=0;icount;i++)

{

list[i].num+=number;//list[i].num=list[i].num+number

}

}

//显示货物信息

void showGoods()

{

printf(“商品名称\t数量\t单价\n”);

for(int i=0;icount;i++)

{

printf(“%s\t%d\t%.2f\n”,list[i].name,list[i].num,list[i].price);

}

}

//修改商品信息

void updateGoods()

{

int i;

printf(“请输入您要修改商品的名字:”);

scanf(“%s”,name);

for(i=0;icount;i++)

{

if(strcmp(name,list[i].name)==0)

{

printf(“请输入新的商品名字:”);

scanf(“%s”,list[i].name);

printf(“请输入您要修改商品的数量:”);

scanf(“%d”,list[i].num);

printf(“请输入您要修改商品的单价:”);

scanf(“%f”,list[i].price);

}

else

{

printf(“对不起,没有找到该商品信息!”);

}

}

}

//删除商品信息

void deleteGoods()

{

int index=-1;

printf(“请输入您要删除的商品名字:”);

scanf(“%s”,name);

for(int i=0;icount;i++)

{

if(strcmp(name,list[i].name)==0)

{

index=i;

}

}if(index==-1)

{

printf(“对不起!没有找到您要删除的商品信息!”);

}

else{

for(int i=index;icount;i++)

{

list[i]=list[i+1];

}

}

}

用c语言编写一个程序,某超市举行店庆活动,所有商品9.5折销售。根据商品单价p,计算商品实付金额c

#include stdio.h

int main()

{

    double p,c;

    scanf(“%lf”,p);

    c=p*0.95;

    printf(“%.2lf\n”, c);

    return 0;

}

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语言编写的代码程序、c语言程序编写超市代码的信息别忘了在本站进行查找喔。

本文来自投稿,不代表【】观点,发布者:【

本文地址: ,如若转载,请注明出处!

举报投诉邮箱:253000106@qq.com

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2024年4月1日 04:34:34
下一篇 2024年4月1日 04:42:50

相关推荐

  • c语言改写模式,c语言实现修改功能

    c语言程序修改? 1、这个程序有4个错误,我都加粗了,第一个是m没有赋初值,第二个是while表达式中的ch=getchar()需要括号括起来,第三个是m=m*10+ch-0中的0也需要用单引号括起来,第四个是第2个while中为m!=0。 2、define容易造成误会,因为不符合一般的编程习惯,false 0, true 1;scanf放在你的那个地方是达…

    2024年5月23日
    4100
  • c语言控制代码的换码序列,c语言交换代码

    求C语言编程大神解答一下下面这个编程代码? k==5,用5去除125余0,所以r=125%5中r为0。由于!0为1,所以执行while循环体:先打印出5(k的值),再n=n/k==125/5=25;由于251则再打印出*号。这一循环结果输出是5*。 下面是我的代码,三个函数分别对应三个问题。 在实现基本要求的前提下,拓展了可以从键盘输入的功能,以下为各题代码…

    2024年5月23日
    5800
  • c语言扫描io脚状态,c语言端口扫描

    求51单片机的上升沿和下降沿C语言检测程序列子,端口就是普通IO口。 上升沿触发是当信号有上升沿时的开关动作,当电位由低变高而触发输出变化的就叫上升沿触发。也就是当测到的信号电位是从低到高也就是上升时就触发,叫做上升沿触发。 单片机怎么计算1s内下降沿的个数的C语言程序或者计算两个下降沿的时间(检测脉冲频率)计算1s内下降沿的个数方法是,一个定时器设置定时1…

    2024年5月23日
    4500
  • c语言mallloc使用的简单介绍

    C语言中使用malloc必须加#includemallo.h? 1、在C语言中使用malloc函数进行动态内存分配。malloc的全称是memory allocation,中文叫动态内存分配。原型:extern void malloc(unsigned int num_bytes);功能:分配长度为num_bytes字节的内存块。 2、你可以看一下C语言那本…

    2024年5月23日
    4500
  • c语言三位小数,C语言三位小数

    怎样用C++语言输出精确到小数点后三位的数? 1、用C++语言输出精确到小数点后三位的数,可以参考下面给出的代码:coutsetiosflags(ios:fixed)setprecision(3)。其中 setiosflags中set是设置的意思。ios是iostream的缩写,即输入输出流。flags是标志的意思。 2、要精确到小数点后若干位,则数据类型为…

    2024年5月23日
    7500
  • c语言21点游戏,二十一点游戏代码c语言

    如何使用C语言编写简单小游戏? 1、数学知识:长方形的面积S=a*b 长方形周长L=2*(a+b)其中a b分别为长方形的宽和高。算法分析:长方形面积及周长均依赖于宽和高,所以先要输入宽高值,然后根据公式计算,输出结果即可。 2、/*也不知道你是什么级别的,我是一个新手,刚接触编程语言,以下是我自己变得一个小程序,在所有c语言的编译器(vc++0、turbo…

    2024年5月23日
    6500
  • c语言当中的null,C语言当中的符号

    C/C++中,NULL和null的区别是什么? nul 和 null要看编译器,不同的编译器有所区别。 所以C或者C++中都使用一个特殊定义NULL表示无效值,其本质就是未定义具体数据类型的0值。 null是是什么都没有的意思。在java中表示空对象。 本意是“空的;元素只有零的”意思。计算机中通常表示空值,无结果,或是空集合。\x0d\x0a在ASCII码…

    2024年5月23日
    4700
  • 包含c语言对txt文件命名的词条

    如何在C语言编程里面修改源文件名字 如果你是在WINDOWS的话,简单了,随便用个编辑器,比如记事本,然后写c源程序,保存到你想要保存的位置。如果你在DOS下,可以用edit,写好以后,按alt键,选择文件菜单,然后保存。 用open打开文件,注意操作模式使用“修改”或者“添加” 用write或者fprintf向文件中写入你的内容。 用close关闭文件。 …

    2024年5月23日
    5000
  • 学c语言编程,学c语言编程用什么软件

    编程开发必须要学C语言吗? 1、要学习。编程开发的学习内容主要包括c语言、python和c+语言。C语言作为一种简单灵活的高级编程语言,它是一个面向过程的语言,一般是作为计算机专业的基础入门语言课程。 2、C语言。对于刚接触编程的人来说,先学习C语言是非常重要的。C语言可以说是是计算机编程语言的鼻祖,其他的编程语言几乎全是由C语言变化衍生出来的。 3、不需要…

    2024年5月23日
    3500
  • 黑客代码软件学习推荐歌曲的简单介绍

    我想自学编程代码,,目地是“黑”网站,开发出破解代码。有没有这方面的… 这个迭代周期不应该以周为周期或以月为周期发生,而是应该以日为周期。知识等待使用的时间越久,知识这把斧头就越钝。等待学习新知识的时间越长,你就越难以将其融入到代码中。 我认为这个问题问得本身就显得有点矛盾,想学却担心自己看不懂代码学不来,试问哪个编程人员不是从零开始的。坚定信念…

    2024年5月23日
    4800

发表回复

登录后才能评论



关注微信