1、C+商场收银系统#include #include#include#include /*问题已解决*/#define NULL 0#define SIZE 20#define LEN sizeof(struct goods) void log() /*登录函数*/ char str120; int s,i; struct casher char name20;long int num;casher1=“yulongyue“,6334;for(i=1;inum,p1-name,head=NULL;while(p1-num!=0) n=n+1;if(n=1)head=p1;else p2-next
2、=p1;p2=p1;p1=(struct goods*)malloc(LEN);scanf(“%d%s%f“,p2-next=NULL;return(head);void print1(struct goods *head) struct goods *p;printf(“nNow,These %d records are:n“,n);p=head;if(head!=NULL)doprintf(“%dt%st%5.1fn“,p-num,p-name,p-price);p=p-next;while(p!=NULL);struct goods *insert(struct goods *head,
3、 struct goods *good) struct goods *p0,*p1,*p2;p1=head;p0=good;if(head=NULL) head=p0; p0-next=NULL;else while(p0-nump1-num) p1=p1-next;if(p0-numnum) if(head=p1) head=p0;else p2-next=p0;p0-next=p1;else p1-next=p0;p0-next=NULL;n=n+1;return(head);struct goods *del(struct goods *head,long num)struct good
4、s *p1,*p2;if (head=NULL)printf(“nlist null!n“);goto end;p1=head;while(num!=p1-num p1=p1-next;if(num=p1-num)if(p1=head)head=p1-next;else p2-next=p1-next;printf(“delete:%ldn“,num);n=n-1;else printf(“%d not been found!n“,num); end:return(head);void menu1()clrscr();gotoxy(25,10);printf(“1.creatn“);gotox
5、y(25,11);printf(“2.deleten“);gotoxy(25,12);printf(“3.insertn“);gotoxy(25,13);printf(“4.printn“);gotoxy(25,14);printf(“5.exitnn“);gotoxy(25,16);printf(“Please select:“);void automoatic() struct goods *head,*stu;long del_num;int x;lp: menu1();scanf(“%d“,switch(x)case 1: clrscr();printf(“input records:
6、n“);head=creat(); break;case 2: clrscr();printf(“ninput the deleted number:n“);scanf(“%ld,%s,%f“,head=del(head,del_num); break;case 3: clrscr();printf(“ninput the inserted record:n“);stu=(struct goods *)malloc(LEN);scanf(“%ld,%s,%f“,head=insert(head,stu); break;case 4: clrscr();print1(head);getch();
7、break;case 5: exit(0);goto lp; /*链表建立等*/int n,i;float pay,paid,balance,sum; /*定义全局变量*/ struct goodddsssint number;char name20;float price ;int counts;float amount; merSIZE;void cash(struct goods *head) /*收银函数 */ int count,l;struct goods *p;float m; sum=0;n=0;doprintf(“Number:t“);scanf(“%d“,if(l=0)br
8、eak;for(p=head;p!=NULL;p=p-next) if(l=p-num) break;printf(“Name:%sn“,p-name);printf(“Price:%fn“,p-price);printf(“Count:“);/*输入商品数量*/scanf(“%d“,m=p-price*count; sum=sum+m; mern.number=l;strcpy(mern.name,p-name); mern.price=p-price;mern.counts=count; mern.amount=m;n+;while(1); /*收银函数 */ void print() /
9、*打印回单函数及保存回单*/ struct goodddsss *p; FILE *fp; fp=fopen(“save.text“,“w+“);printf(“tCORNER SMILEnn“); for(i=0;inumber,p-name,p-price,p-counts,p-amount);fprintf(fp,“ %dt%st%.2ft%dt%.2fn“,p-number,p-name,p-price,p-counts,p-amount);for(i=0;i50;i+) printf(“-“); printf(“n“);printf(“Pay :%fnn“,sum); printf(
10、“paid:%fnn“,paid); printf(“Bala:%fnn“,balance); printf(“tWelcome next time !nn“);for(i=0;i50;i+) printf(“*“); printf(“n“); printf(“Pay:%fn“,sum); printf(“paid :“); scanf(“%f“, balance=paid-sum;printf(“Balance:%fn“,balance);for(i=0;i50;i+) fprintf(fp,“-“); fprintf(fp,“n“);fprintf(fp,“Pay :%fnn“,sum);
11、 fprintf(fp,“paid:%fnn“,paid); fprintf(fp,“Bala:%fnn“,balance); fprintf(fp,“tWelcome next time !nn“);for(i=0;i50;i+) fprintf(fp,“*“); fprintf(fp,“n“);fclose(fp); /*打印回单函数及保存回单*/void menu() /*菜单函数*/int j;clrscr();for(i=0;j57;i+) if(j=27)printf(“WELCOME THE LOG ON TO THE SYSTRM“);else printf(“*“); pri
12、ntf(“nn“);for(j=0;i5;j+) printf(“ “);printf(“Welcome shops of 08 Information management class four corner smile!“);gotoxy(25,10);printf(“1.please log on to the system;n“);gotoxy(25,12);printf(“2.Cashier operation;n“);gotoxy(25,14);printf(“3.Print holder;n“);gotoxy(25,16);printf(“4.Save holder;n“);go
13、toxy(25,18);printf(“5.Automoatic updates;n“);gotoxy(25,20);printf(“6.Exit system;n“);gotoxy(25,24);printf(“Please input your options:“); /*菜单函数*/void main() /*主函数*/ char ch;struct goods *head;op: menu();ch=getch();switch(ch) case 1:clrscr(); log();break;case 2:clrscr();automoatic() ;break;case 3:clrscr(); cash(head);break;case 4:clrscr();print();break; case5:clrscr(); exit(0);break;goto op;void bsnhk(float a) /*主函数*/float *p;p=