运用c语言程序写一个超市收银情况

运用c语言程序写一个超市收银情况,第1张

#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=0i<list->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)

}

设计思路有问题,要么你的羡兆程序得重新写。

void M::display()

{float temp

temp=average(M *p,int b)//这里的参数从何而来?

cout<<sum<<endl

cout<<temp<<endl}

改为display(M *p,int b)

{float temp

temp=average(p, b)//这里的参数

cout<<sum<<endl

cout<<temp<<endl

}

主函数内改为 display(m,3)

float M::average(M *p,int b)

{for(int i=0i<bi++)

n+=(*(p+i)).quantity

return (sum/n)}

这个也有潜兄手租在问题,比如说 sum/n 是整数 ,应改为((double)sum)/n

另外,虚机团上薯亮产品团购,超级便宜

#include<stdio.h>

#include<槐数conio.h>

#include<stdlib,h>

#include<math.h>

void main()

{

char a,b,c

double i,m,n,r,l,p

printf("j为简易型,k为科学型,x为退出")

scanf("%c",&a)

if (a=='j')

{

scanf("%f%c%f",&m,&b,&n)

if(b=='a')

i=m+n

else if(b=='s')

i=m-n

else if(b=='d')

i=m/n

else if(b=='r')

return

else if(b=='x')

exit(0)

printf("%f",i)

}

else if(a=='k'){

scanf("%c%f",&c,&r)

if(c=='i')

p=sin(r)

else if(c=='c')

p=cos(r)

else if(c=='t')

p=tan(r)

else if(c=='m'铅困首)

{scanf("%f",&l)

p=1

for(r=1r<=lr++)

p=p*r

}

else if(c=='e')

p=log(r)

else if(c=='s')

p=log10(r)

else if(c=='j')

{

p=1

for(i=1i<=ri++)

p=p*i

}

else if(c=='尺友d')

p=1/r

else if(c=='u')

p=r*r*r

else if(c=='p')

p=r*r

else if(c=='r')

return

else if(c=='x')

exit(0)

printf("%f",p)

}

system("cls")

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12437153.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-25
下一篇 2023-05-25

发表评论

登录后才能评论

评论列表(0条)

保存