热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

超市c语言,C语言超市购物打折

本文目录一览:1、C语言编写的超市管理系统2、

本文目录一览:


  • 1、C语言编写的超市管理系统


  • 2、C语言的关于超市的代码


  • 3、C语言编写“超市结账系统” 急急急!!!

C语言编写的超市管理系统

有一个小型超市,出售N(N=10)种商品,设计并实现一个系统,完成下列功能:

1. 保存及输出。超市中的各种商品信息保存在指定文件中,可以把它们输出显示。

2. 计算并排序。计算每类商品的总价值(sum,单精度)及平均价(aver,单精度,输出一位小数),将每类商品按平均价从大到小的顺序排序打印出来。

3. 统计。统计输出库存量低于100的货号及类别。统计输出有两种以上(含两种)商品库存量低于100的商品类别。

1.2总体结构

本程序主要分为八个模块:主模块、信息输出修改模块、新建信息模块、排序模块、计算模块、统计模块1、统计模块2、打印模块。

1) 主模块:通过调用各分模块实现功能;

2) 信息输出修改模块:输出显示文件中商品信息内容,添加商品信息,删除商品信息,修改商品信息;

3) 新建商品信息模块:建立一个新结构体,为链表存信息用,并且将信息保存在指定的文件中;

4) 排序模块:把文件中顺序零乱的商品信息按单价的大小从高到低进行排序,放到链表里存储;

5) 计算模块:将所有商品的价格与库存量进行累加求和;

6) 打印模块:将商品信息按每类平均价格排序(从高到低)按顺序打印出来;

7) 统计模块1:统计库存量低于100的货名及类别;

8) 统计模块2:统计商品库存量有2种以上(含2种)低于100的商品类别。

附 录(程序清单)

#include "stdio.h" /*输入,输出头文件*/

#include "stdlib.h" /*申请空间头文件*/

#include "string.h" /*对字符串加工头文件*/

#include "conio.h" /*清屏头文件*/

FILE *fp;

int n=0; /*定义文件指针类型*/

int i,j,a[4],m; /*定义整数类型*/

float aver[4],sum[4],g[4],h; /*定义浮点类型*/

char c[5]="elec"; /*定义字符数组类型*/

char d[5]="comm"; /*定义字符数组类型*/

char e[5]="food"; /*定义字符数组类型*/

char f[5]="offi"; /*定义字符数组类型*/

struct good /*定义结构体*/

{

int num; /*商品编号*/

char name[20]; /*商品名称*/

char kind[40]; /*商品类型*/

float price; /*商品价格*/

char unit[10]; /*商品单位*/

int quantity; /*商品数量*/

struct good *next; /*定义结构体指针类型*/

}*head,*p1,*p2;

struct good *createlist() /*创建链表函数*/

{

struct good *head1,*p1,*p2; /*定义结构体指针类型*/

if((fp=fopen("goods message.txt","w"))==NULL) /*判断能否打开文件*/

{

printf("can not open the file");

exit(0); /*结束程序*/

}

head1=(struct good *)malloc(sizeof(struct good)); /*申请头结点空间*/

p1=head1;

p2=head1;

printf("*********************************************\n");

printf("请输入信息:编号,名称,类型,价格,单位,数目\n");

printf(" (以输入“-1”表示结束输入)\n");

printf("*********************************************\n");

printf("____________________\n");

scanf("%d %s %s %f %s %d",p1-num,p1-name,p1-kind,p1-price,p1-unit,p1-quantity); /*输入商品信息*/

printf("____________________\n");

p1-next=NULL;

fprintf(fp,"%d %s %s %f %s %d ",p1-num,p1-name,p1-kind,p1-price,p1-unit,p1-quantity); /*将商品信息写入文件*/

while(1)

{

p1=(struct good *)malloc(sizeof(struct good)); /*申请新空间*/

printf("*********************************************\n");

printf("请输入信息:编号,名称,类型,价格,单位,数目\n");

printf(" (以输入“-1”表示结束输入)\n");

printf("*********************************************\n");

printf("____________________\n");

scanf("%d",p1-num);

if(p1-num==-1) /*申请空间结束条件*/

{

printf("____________________\n\n");

fprintf(fp,"%d",-1);

fclose(fp);

return head1; /*返回头指针*/

}

scanf("%s %s %f %s %d",p1-name,p1-kind,p1-price,p1-unit,p1-quantity); /*输入商品信息*/

printf("________________\n");

fprintf(fp,"%d %s %s %f %s %d ",p1-num,p1-name,p1-kind,p1-price,p1-unit,p1-quantity); /*将商品信息写入文件*/

p1-next=NULL;

p2-next=p1;

p2=p1;

}

}

struct good *paixu(struct good*head2) /*链表排序函数*/

{

struct good *p6,*p7,*r,*s; /*定义结构体指针类型*/

for(i=0;i=3;i++) /*赋初值值*/

{

a[i]=0;

sum[i]=0;

aver[i]=0;

}

p6=(struct good *)malloc(sizeof(struct good)); /*申请新空间*/

p6-next=head2;

head2=p6;

while(p6-next!=NULL) /*判断循环结束条件*/

{

p7=p6-next;

r=p6;

while(p7-next!=NULL) /*判断循环结束条件*/

{

if((p7-next-price)(r-next-price)) /*判断是否调换*/

r=p7;

p7=p7-next;

}

if(p6!=r) /*判断循环结束条件*/

{

s=r-next; /*指针调换*/

r-next=s-next;

s-next=p6-next;

p6-next=s;

}

p6=p6-next;

}

p6=head2;

head2=head2-next;

free(p6); /*释放第一个无效空间*/

return head2;

}

void jisuan()

{

p1=head;

do

{

if(strcmp(p1-kind,c)==0) /*判断是否为电器类型*/

{

sum[0]=sum[0]+(p1-price)*(p1-quantity); /*求电器总价*/

a[0]=a[0]+p1-quantity; /*求电器总件数*/

}

if(strcmp(p1-kind,d)==0) /*判断是否为日用品类型*/

{

sum[1]=sum[1]+(p1-price)*(p1-quantity); /*求日用品总价*/

a[1]=a[1]+p1-quantity; /*求日用品总件数*/

}

if(strcmp(p1-kind,e)==0) /*判断是否为办公用品类型*/

{

sum[2]=sum[2]+(p1-price)*(p1-quantity); /*求办公用品总价*/

a[2]=a[2]+p1-quantity; /*求办公用品总件数*/

}

if(strcmp(p1-kind,f)==0) /*判断是否为食品类型*/

{

sum[3]=sum[3]+(p1-price)*(p1-quantity); /*求食品总价*/

a[3]=a[3]+p1-quantity; /*求食品总件数*/

}

p1=p1-next;

}while (p1!=NULL); /*遍历链表结束条件*/

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

aver[i]=sum[i]/a[i]; /*求每类商品平均价*/

printf("****************************************************\n");

printf("商品类型 \t 平均价\t 总库存量\n");

printf("****************************************************\n");

printf("____________________________________________________\n");

printf("电器总价值:%0.1f\t平均价:%0.1f\t总库存量:%d\n",sum[0],aver[0],a[0]);

printf("____________________________________________________\n");

printf("日用品总价值:%0.1f\t平均价:%0.1f\t总库存量:%d\n",sum[1],aver[1],a[1]);

printf("____________________________________________________\n");

printf("食品总价值:%0.1f\t平均价:%0.1f\t总库存量:%d\n",sum[2],aver[2],a[2]);

printf("____________________________________________________\n");

printf("办公用品总价值:%0.1f\t平均价:%0.1f\t总库存量:%d\n",sum[3],aver[3],a[3]);

printf("____________________________________________________\n");

}

void shuchu() /*输出商品信息函数*/

{

do

{

struct good *p3,*p4,*p5; /*定义结构体指针类型*/

int n=0,p=0,q=0,r=0;

printf("所有商品信息:\n");

printf("编号,名称,类型,价格,单位,数目\n");

printf("**********************************\n");

if((fp=fopen("goods message.txt","rb+"))==NULL) /*判断能否打开文件*/

{

printf("can not open the file");

exit(0); /*结束程序*/

}

head=(struct good *)malloc(sizeof(struct good)); /*申请头结点空间*/

p3=head;

fscanf(fp,"%d %s %s %f %s %d ",p3-num,p3-name,p3-kind,p3-price,p3-unit,p3-quantity); /*从文件中写到链表*/

while(1)

{

p4=(struct good *)malloc(sizeof(struct good)); /*申请头结点空间*/

fscanf(fp,"%d ",p4-num);

if(p4-num!=-1) /*判断循环结束条件*/

{

fscanf(fp,"%s %s %f %s %d ",p4-name,p4-kind,p4-price,p4-unit,p4-quantity); /*从文件中写到链表*/

p4-next=NULL;

p3-next=p4;

p3=p4;

}

else

{

p3-next=NULL;

break;

}

}

fclose(fp); /*关闭文件*/

p3=head;

while(p3!=NULL)

{

printf(" %d %s %s %0.1f %s %d\n\n",p3-num,p3-name,p3-kind,p3-price,p3-unit,p3-quantity);

printf("__________________________________\n");

p3=p3-next;

}

printf("**********************************\n");

printf("//////////////////////////////////\n");

while(n!=4)

{

p3=head;

printf("**********************************\n");

printf("1 添加商品信息\n");

printf("2 删除某商品信息\n");

printf("3 修改某商品信息\n");

printf("4 返回(当你完成了对某一商品的添加、删除或者修改后请按4返回)\n");

printf("**********************************\n");

scanf("%d",n);

if(n==1) /*添加商品信息*/

{

printf("请输入商品 编号 名称 类型 价格 单位 数目\n");

printf("**********************************\n");

p4=(struct good *)malloc(sizeof(struct good)); /*申请空间*/

scanf("%d %s %s %f %s %d",p4-num,p4-name,p4-kind,p4-price,p4-unit,p4-quantity); /*输入商品信息*/

p4-next=NULL;

while(p3-next!=NULL) /*判断循环结束条件*/

{

p3=p3-next;

}

p3-next=p4;

p3=head;

if((fp=fopen("goods message.txt","w"))==NULL) /*判断能否打开文件*/

{

printf("can not open the file");

exit(0); /*结束程序*/

}

while(p3!=NULL)

{

fprintf(fp,"%d %s %s %f %s %d ",p3-num,p3-name,p3-kind,p3-price,p3-unit,p3-quantity) /*将商品信息写入文件*/

p3=p3-next;

}

fprintf(fp,"%d",-1);

fclose(fp); /*关闭文件*/

printf("**********************************\n");

printf("__________________________________\n");

printf("------------请按4返回-------------\n");

printf("__________________________________\n");

printf("**********************************\n");

}

if(n==2) /*删除商品*/

{

printf("**********************************\n");

printf("请输入需要删除的商品编号\n");

printf("**********************************\n");

scanf("%d",p);

printf("**********\n");

printf("1 确认删除\n2 取消删除\n");

printf("**********\n");

scanf("%d",r);

if(r==1)

{

if((head-num)==p)

{

head=head-next;

free(p3); /*释放空间*/

}

else

{

p4=head;

p3=p4-next;

while(p3!=NULL) /*判断循环结束条件*/

{

if((p3-num)==p)

{

p5=p3-next;

free(p3); /*释放空间*/

p4-next=p5;

break;

}

p3=p3-next;

p4=p4-next;

}

}

if((fp=fopen("goods message.txt","w"))==NULL) /*判断能否打开文件*/

{

printf("can not open the file");

exit(0); /*结束程序*/

}

p3=head;

while(p3!=NULL) /*判断循环结束条件*/

{

fprintf(fp,"%d %s %s %f %s %d ",p3-num,p3-name,p3-kind,p3-price,p3-unit,p3-quantity); /*将商品信息写入文件*/

p3=p3-next;

}

fprintf(fp,"%d",-1);

fclose(fp); /*关闭文件*/

}

if(r==2)

continue; /*继续循环*/

printf("**********************************\n");

printf("__________________________________\n");

printf("------------请按4返回-------------\n");

printf("__________________________________\n");

printf("**********************************\n");

}

if(n==3) /*修改某商品信息*/

{

printf("请输入需要修改的商品编号\n");

scanf("%d",q);

while(p3!=NULL) /*判断循环结束条件*/

{

if((p3-num)==q) /*判断是否为所需要修改的商品*/

{

printf("请输入商品单价与库存量(如果单价不变请输入原来的单价)\n");

scanf("%f %d",p3-price,p3-quantity); /*输入商品价格与库存量*/

}

p3=p3-next;

}

if((fp=fopen("goods message.txt","w"))==NULL) /*判断能否打开文件*/

{

printf("can not open the file");

exit(0); /*结束程序*/

}

p3=head;

while(p3!=NULL) /*判断循环结束条件*/

{

fprintf(fp,"%d %s %s %f %s %d ",p3-num,p3-name,p3-kind,p3-price,p3-unit,p3-quantity); /*将商品信息写入文件*/

p3=p3-next;

}

fprintf(fp,"%d",-1);

fclose(fp); /*关闭文件*/

printf("**********************************\n");

printf("__________________________________\n");

printf("------------请按4返回-------------\n");

printf("__________________________________\n");

printf("**********************************\n");

}

if(n==4) /*退出*/

break;

}

printf("**********\n");

printf("1 继续修改\n---------\n2 返回\n");

printf("**********\n");

scanf("%d",p);

if(p==1)

continue; /*继续循环*/

if(p==2)

break; /*跳出循环*/

}while(n!=2);

fclose(fp); /*关闭文件*/

}

void printf0(struct good *p) /*遍历链表并打印电器类商品函数*/

{

struct good *p3; /*定义结构体指针类型*/

p3=p;

while (p3!=NULL) /*判断遍历链表循环结束条件*/

{

if(strcmp(p3-kind,c)==0) /*判断商品类型是否为电器类型*/

{

printf("%d\t%s\t%s\t%0.1f\t%s\t%d\n",p3-num,p3-name,p3-kind,p3-price,p3-unit,p3-quantity); /*输出电器类商品信息*/

printf("________________________________________________\n");

}

p3=p3-next;

}

return;

}

void printf1(struct good *p) /*遍历链表并打印日用品类商品函数*/

{

struct good *p3; /*定义结构体指针类型*/

p3=p;

while (p3!=NULL) /*判断遍历链表循环结束条件*/

{

if(strcmp(p3-kind,d)==0) /*判断商品类型是否为日用品类型*/

{

printf("%d\t%s\t%s\t%0.1f\t%s\t%d\n",p3-num,p3-name,p3-kind,p3-price,p3-unit,p3-quantity); /*输出日用品类商品信息*/

printf("________________________________________________\n");

}

p3=p3-next;

}

return;

}

void printf2(struct good *p) /*遍历链表并打印办公用品类商品函数*/

{

struct good *p3; /*定义结构体指针类型*/

p3=p;

while (p3!=NULL) /*判断遍历链表循环结束条件*/

{

if(strcmp(p3-kind,e)==0) /*判断商品类型是否为办公用品类型*/

{

printf("%d\t%s\t%s\t%0.1f\t%s\t%d\n",p3-num,p3-name,p3-kind,p3-price,p3-unit,p3-quantity); /*输出办公用品类商品信息*/

printf("________________________________________________\n");

}

p3=p3-next;

}

return;

}

void printf3(struct good *p) /*遍历链表并打印食品类商品函数*/

{

struct good *p3; /*定义结构体指针类型*/

p3=p;

while (p3!=NULL) /*判断遍历链表循环结束条件*/

{

if(strcmp(p3-kind,f)==0) /*判断商品类型是否为食品类型*/

{

printf("%d\t%s\t%s\t%0.1f\t%s\t%d\n",p3-num,p3-name,p3-kind,p3-price,p3-unit,p3-quantity); /*输出食品类商品信息*/

printf("________________________________________________\n");

}

p3=p3-next;

}

return;

}

void shunxudayin()

{

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

g[i]=aver[i]; /*将平均价赋给新数组*/

for(j=0;j3;j++) /*将新数组用冒泡排序法排序*/

for(i=j+1;i4;i++)

{

if(g[j]g[i])

{

h=g[j];

g[j]=g[i];

g[i]=h;

}

}

printf("\n****************************\n");

printf("商品平均价格排序表(从高到低)\n");

printf("****************************\n");

printf("________________________________________________\n");

printf("编号\t名称\t类别\t单价\t单位\t数量\n");

printf("________________________________________________\n");

for(j=0;j4;j++)

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

{

if (aver[i]==g[j]) /*判断每类商品平均价格的先后顺序*/

switch(i)

{

case 0:

printf0(head); /*调用遍历链表并打印电器类商品函数*/

break;

case 1:

printf1(head); /*调用遍历链表并打印日用品类商品函数*/

break;

case 2:

printf2(head);/*调用遍历链表并打印办公用品类商品函数*/

break;

case 3:

printf3(head); /*调用遍历链表并打印食品类商品函数*/

break;

}

}

}

void tongji1()

{

p1=head;

printf("\n************************\n");

printf("库存量低于100的货名及类别\n");

printf("************************\n");

printf("________________________\n");

printf("商品名称\t商品类型\n");

printf("________________________\n");

while(p1!=NULL) /*判断遍历链表循环结束条件*/

{

if(p1-quantity100) /*判断库存量是否小于100*/

{

printf("%s\t%s\n",p1-name,p1-kind); /*输出商品名称及类别*/

printf("________________________\n");

}

p1=p1-next;

}

}

void tongji2()

{

printf("\n**********************************************\n");

printf("商品库存量有2种以上(含2种)低于100的商品类别:\n");

printf("**********************************************\n");

printf("________\n");

if((a[0]100)(a[0]=2)) /*判断电器类库存量是否为2种以上(含2种)低于100*/

{

printf("电器\n");

printf("________\n");

}

if((a[1]100)(a[1]=2)) /*判断日用品类库存量是否为2种以上(含2种)低于100*/

{

printf("日用品\n");

printf("________\n");

}

if((a[2]100)(a[2]=2)) /*判断食品类库存量是否为2种以上(含2种)低于100*/

{

printf("食品\n");

printf("________\n");

}

if((a[3]100)(a[3]=2)) /*判断办公用品类库存量是否为2种以上(含2种)低于100*/

{

printf("办公用品\n");

printf("________\n");

}

}

int main(int argc, char* argv[])

{

struct good *p1,*p2; /*定义结构体指针类型*/

while(1)

{

printf("***********************************************\n");

printf("1 ----------输出查看或者修改已存信息-----------\n");

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

printf("2 -----重新输入新信息(并且删除原有信息)------\n");

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

printf("3 统计商品信息(如果您还没有查看过信息请先按1)\n");

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

printf("4 -------------------退出---------------------\n");

printf("***********************************************\n");

scanf("%d",m);

if(m==1)

shuchu(); /*调用输出信息函数*/

if(m==2)

{

system("cls");

head=createlist(); /*调用建立链表函数*/

}

if(m==3)

{

printf("统计结果如下\n");

head=paixu(head); /*调用链表排序函数*/

jisuan(); /*调用计算函数*/

shunxudayin(); /*调用顺序打印函数*/

tongji1(); /*调用统计1函数*/

tongji2(); /*调用统计2函数*/

}

if(m==4)

{

p1=head;

while(p1!=NULL) /*判断遍历链表结束条件*/

{

p2=p1-next;

free(p1); /*释放空间*/

p1=p2;

}

break;

}

}

return 0; /*结束程序*/

}

C语言的关于超市的代码

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

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;

}


推荐阅读
  • 本文介绍了一个题目的解法,通过二分答案来解决问题,但困难在于如何进行检查。文章提供了一种逃逸方式,通过移动最慢的宿管来锁门时跑到更居中的位置,从而使所有合格的寝室都居中。文章还提到可以分开判断两边的情况,并使用前缀和的方式来求出在任意时刻能够到达宿管即将锁门的寝室的人数。最后,文章提到可以改成O(n)的直接枚举来解决问题。 ... [详细]
  • 本文主要解析了Open judge C16H问题中涉及到的Magical Balls的快速幂和逆元算法,并给出了问题的解析和解决方法。详细介绍了问题的背景和规则,并给出了相应的算法解析和实现步骤。通过本文的解析,读者可以更好地理解和解决Open judge C16H问题中的Magical Balls部分。 ... [详细]
  • CF:3D City Model(小思维)问题解析和代码实现
    本文通过解析CF:3D City Model问题,介绍了问题的背景和要求,并给出了相应的代码实现。该问题涉及到在一个矩形的网格上建造城市的情景,每个网格单元可以作为建筑的基础,建筑由多个立方体叠加而成。文章详细讲解了问题的解决思路,并给出了相应的代码实现供读者参考。 ... [详细]
  • HDU 2372 El Dorado(DP)的最长上升子序列长度求解方法
    本文介绍了解决HDU 2372 El Dorado问题的一种动态规划方法,通过循环k的方式求解最长上升子序列的长度。具体实现过程包括初始化dp数组、读取数列、计算最长上升子序列长度等步骤。 ... [详细]
  • 本文介绍了九度OnlineJudge中的1002题目“Grading”的解决方法。该题目要求设计一个公平的评分过程,将每个考题分配给3个独立的专家,如果他们的评分不一致,则需要请一位裁判做出最终决定。文章详细描述了评分规则,并给出了解决该问题的程序。 ... [详细]
  • 本文介绍了C++中省略号类型和参数个数不确定函数参数的使用方法,并提供了一个范例。通过宏定义的方式,可以方便地处理不定参数的情况。文章中给出了具体的代码实现,并对代码进行了解释和说明。这对于需要处理不定参数的情况的程序员来说,是一个很有用的参考资料。 ... [详细]
  • 本文讨论了使用差分约束系统求解House Man跳跃问题的思路与方法。给定一组不同高度,要求从最低点跳跃到最高点,每次跳跃的距离不超过D,并且不能改变给定的顺序。通过建立差分约束系统,将问题转化为图的建立和查询距离的问题。文章详细介绍了建立约束条件的方法,并使用SPFA算法判环并输出结果。同时还讨论了建边方向和跳跃顺序的关系。 ... [详细]
  • 本文介绍了一种划分和计数油田地块的方法。根据给定的条件,通过遍历和DFS算法,将符合条件的地块标记为不符合条件的地块,并进行计数。同时,还介绍了如何判断点是否在给定范围内的方法。 ... [详细]
  • 本文介绍了P1651题目的描述和要求,以及计算能搭建的塔的最大高度的方法。通过动态规划和状压技术,将问题转化为求解差值的问题,并定义了相应的状态。最终得出了计算最大高度的解法。 ... [详细]
  • 本文介绍了解决二叉树层序创建问题的方法。通过使用队列结构体和二叉树结构体,实现了入队和出队操作,并提供了判断队列是否为空的函数。详细介绍了解决该问题的步骤和流程。 ... [详细]
  • 动态规划算法的基本步骤及最长递增子序列问题详解
    本文详细介绍了动态规划算法的基本步骤,包括划分阶段、选择状态、决策和状态转移方程,并以最长递增子序列问题为例进行了详细解析。动态规划算法的有效性依赖于问题本身所具有的最优子结构性质和子问题重叠性质。通过将子问题的解保存在一个表中,在以后尽可能多地利用这些子问题的解,从而提高算法的效率。 ... [详细]
  • 本文介绍了UVALive6575题目Odd and Even Zeroes的解法,使用了数位dp和找规律的方法。阶乘的定义和性质被介绍,并给出了一些例子。其中,部分阶乘的尾零个数为奇数,部分为偶数。 ... [详细]
  • Linux环境变量函数getenv、putenv、setenv和unsetenv详解
    本文详细解释了Linux中的环境变量函数getenv、putenv、setenv和unsetenv的用法和功能。通过使用这些函数,可以获取、设置和删除环境变量的值。同时给出了相应的函数原型、参数说明和返回值。通过示例代码演示了如何使用getenv函数获取环境变量的值,并打印出来。 ... [详细]
  • 本文介绍了PE文件结构中的导出表的解析方法,包括获取区段头表、遍历查找所在的区段等步骤。通过该方法可以准确地解析PE文件中的导出表信息。 ... [详细]
  • 前景:当UI一个查询条件为多项选择,或录入多个条件的时候,比如查询所有名称里面包含以下动态条件,需要模糊查询里面每一项时比如是这样一个数组条件:newstring[]{兴业银行, ... [详细]
author-avatar
拍友2502904975
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有