热门标签 | 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;

}


推荐阅读
  • 向QTextEdit拖放文件的方法及实现步骤
    本文介绍了在使用QTextEdit时如何实现拖放文件的功能,包括相关的方法和实现步骤。通过重写dragEnterEvent和dropEvent函数,并结合QMimeData和QUrl等类,可以轻松实现向QTextEdit拖放文件的功能。详细的代码实现和说明可以参考本文提供的示例代码。 ... [详细]
  • 开发笔记:实验7的文件读写操作
    本文介绍了使用C++的ofstream和ifstream类进行文件读写操作的方法,包括创建文件、写入文件和读取文件的过程。同时还介绍了如何判断文件是否成功打开和关闭文件的方法。通过本文的学习,读者可以了解如何在C++中进行文件读写操作。 ... [详细]
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • 本文讨论了一个关于cuowu类的问题,作者在使用cuowu类时遇到了错误提示和使用AdjustmentListener的问题。文章提供了16个解决方案,并给出了两个可能导致错误的原因。 ... [详细]
  • 本文详细介绍了在ASP.NET中获取插入记录的ID的几种方法,包括使用SCOPE_IDENTITY()和IDENT_CURRENT()函数,以及通过ExecuteReader方法执行SQL语句获取ID的步骤。同时,还提供了使用这些方法的示例代码和注意事项。对于需要获取表中最后一个插入操作所产生的ID或马上使用刚插入的新记录ID的开发者来说,本文提供了一些有用的技巧和建议。 ... [详细]
  • 本文详细介绍了Spring的JdbcTemplate的使用方法,包括执行存储过程、存储函数的call()方法,执行任何SQL语句的execute()方法,单个更新和批量更新的update()和batchUpdate()方法,以及单查和列表查询的query()和queryForXXX()方法。提供了经过测试的API供使用。 ... [详细]
  • C++字符字符串处理及字符集编码方案
    本文介绍了C++中字符字符串处理的问题,并详细解释了字符集编码方案,包括UNICODE、Windows apps采用的UTF-16编码、ASCII、SBCS和DBCS编码方案。同时说明了ANSI C标准和Windows中的字符/字符串数据类型实现。文章还提到了在编译时需要定义UNICODE宏以支持unicode编码,否则将使用windows code page编译。最后,给出了相关的头文件和数据类型定义。 ... [详细]
  • 本文介绍了iOS数据库Sqlite的SQL语句分类和常见约束关键字。SQL语句分为DDL、DML和DQL三种类型,其中DDL语句用于定义、删除和修改数据表,关键字包括create、drop和alter。常见约束关键字包括if not exists、if exists、primary key、autoincrement、not null和default。此外,还介绍了常见的数据库数据类型,包括integer、text和real。 ... [详细]
  • MyBatis多表查询与动态SQL使用
    本文介绍了MyBatis多表查询与动态SQL的使用方法,包括一对一查询和一对多查询。同时还介绍了动态SQL的使用,包括if标签、trim标签、where标签、set标签和foreach标签的用法。文章还提供了相关的配置信息和示例代码。 ... [详细]
  • 本文介绍了在Windows系统上使用C语言命令行参数启动程序并传递参数的方法,包括接收参数程序的代码和bat文件的编写方法,同时给出了程序运行的结果。 ... [详细]
  • 纠正网上的错误:自定义一个类叫java.lang.System/String的方法
    本文纠正了网上关于自定义一个类叫java.lang.System/String的错误答案,并详细解释了为什么这种方法是错误的。作者指出,虽然双亲委托机制确实可以阻止自定义的System类被加载,但通过自定义一个特殊的类加载器,可以绕过双亲委托机制,达到自定义System类的目的。作者呼吁读者对网上的内容持怀疑态度,并带着问题来阅读文章。 ... [详细]
  • 基于Socket的多个客户端之间的聊天功能实现方法
    本文介绍了基于Socket的多个客户端之间实现聊天功能的方法,包括服务器端的实现和客户端的实现。服务器端通过每个用户的输出流向特定用户发送消息,而客户端通过输入流接收消息。同时,还介绍了相关的实体类和Socket的基本概念。 ... [详细]
  • 本文介绍了使用哈夫曼树实现文件压缩和解压的方法。首先对数据结构课程设计中的代码进行了分析,包括使用时间调用、常量定义和统计文件中各个字符时相关的结构体。然后讨论了哈夫曼树的实现原理和算法。最后介绍了文件压缩和解压的具体步骤,包括字符统计、构建哈夫曼树、生成编码表、编码和解码过程。通过实例演示了文件压缩和解压的效果。本文的内容对于理解哈夫曼树的实现原理和应用具有一定的参考价值。 ... [详细]
  • 本文介绍了Android中的assets目录和raw目录的共同点和区别,包括获取资源的方法、目录结构的限制以及列出资源的能力。同时,还解释了raw目录中资源文件生成的ID,并说明了这些目录的使用方法。 ... [详细]
  • 本文介绍了在使用Laravel和sqlsrv连接到SQL Server 2016时,如何在插入查询中使用输出子句,并返回所需的值。同时讨论了使用CreatedOn字段返回最近创建的行的解决方法以及使用Eloquent模型创建后,值正确插入数据库但没有返回uniqueidentifier字段的问题。最后给出了一个示例代码。 ... [详细]
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社区 版权所有