十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
我帮你改了一下,你可以试一试,可能有的地方不合你的题目(建议你把题目描述贴出来,我再改改)。可能你的编译器和我的不一样,要是有编译错误的话你可以自己改一下(或者把错误贴出来,我再改改),至少我的代码符合C99标准。
创新互联建站专注于企业成都营销网站建设、网站重做改版、固始网站定制设计、自适应品牌网站建设、H5开发、商城建设、集团公司官网建设、外贸网站制作、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为固始等各大城市提供网站开发制作服务。
ps:LZ挺勤奋的,不想某些伸手党直接贴题目,LZ还写了很长的代码,赞一下!
#includestdio.h
#includestdlib.h
typedef struct //我定义了一个商品结构体
{int num; //我定义了一个商品号
char name[20]; //我定义了一个商品名称
double jia; //我定义了一个商品价格
} Shop;
struct hui //会员结构体
{ int number;
char name[40];
float fen;
int mima;
}h1[5]=,,,,};
void zero()/*指针函数*/
{int i;
FILE *fp;
fp=fopen("c: \\file1.txt","wb");
if(fp==NULL)
for(i=0;i=4;i++)
fclose(fp);}
void Shop1() //函数购物
,,,,};
system("cls");
printf("\t\t\t 商品清单\n\n");
printf("**********************************************************************\n");
printf("编号\t\t\t 名称\t\t\t\t价格\n\n");
int g;
for(g=0;g=4;g++)
printf("**********************************************************************\n");
}//上面是个输出商品清单
//我定义了一个主函数main
void main ()
{int a,b,c=1000,d=123456789,z=2;
FILE *fp;
L1:printf("**************欢迎来到超市!**************\n");
printf("**************下面进入管理员登陆界面**************\n");
printf("\t请输入登陆账号:\t"); scanf("%d",a);
printf("\t请输入登陆密码:\t"); scanf("%d",b);
if(a==cb==d)
{ printf("登陆成功\n");
}
else
for(z=2;z=0;z--)
{
printf("账号或密码错误,请重新输入,您还有%d次机会!\n",z);
printf("\t请输入登陆账号:\t"); scanf("%d",a);
printf("\t请输入登陆密码:\t"); scanf("%d",b);
if(a==cb==d)
{
printf("登陆成功\n");
break;
}
}
//-----------------------------------------------
int m,k,i,x,o,q;
printf("**************下面进入会员登陆界面**************");
printf("\t\t\t1.会员登陆");
printf("\t\t\t2.非会员登陆");
printf("\t\t\t0.退出");
scanf("%d",m);
if(m==0)
else if(m==1)
{
printf("**************请输入会员编号**************");
scanf("%d",k);
printf("**************请输入会员密码**************");
scanf("%d",x);
int i;
for(i=0; i=4;++i)
{
if(h1[i].number==kh1[i].mima==x)
break;
}
if (i==5)
{
for (q=0;q2;q++)
{
printf("编号或密码错误,请重新输入,您还有%d次机会!\n",2-q);
printf("\t请输入登陆编号:\t"); scanf("%d",k);
printf("\t请输入登陆密码:\t"); scanf("%d",x);
for(i=0; i=4;++i)
{
if(h1[i].number==kh1[i].mima==x)
break;
}
if (i!=5)
break;
}
}
switch(k)
{
case 1:printf("您好尊敬的会员1");break;
case 2:printf("您好尊敬的会员2");break;
case 3:printf("您好尊敬的会员3");break;
case 4:printf("您好尊敬的会员4");break;
case 5:printf("您好尊敬的会员5");break;
}
fp=fopen("c: \\file1.txt","r");
if(fp==NULL)
{
printf("读写文件打开失败!\n");
exit(0);
}
fread(h1,sizeof(struct hui),5,fp);
printf("\t\t%s\t积分%4.2f:\t",h1[i].name ,h1[i].fen );
fclose(fp);
fp=fopen("c: \\file1.txt","w");Shop1();
float u;
float sum=0;
int n;
int h;
float w;
Shop str1[5]=,,,,};
for(int j=0;j=1000;j++)
{
printf("请输入您所选择的商品编号(输入886结束): ");
scanf("%d",h);
for(int g1=0;g1=4;g1++)
{
if(h==str1[g1].num)
{ (w=str1[g1].jia);
printf("名称: %s\t价格:$%.2f \n",str1[g1].name ,str1[g1].jia );
printf("请输入所选择商品的数量: ");
scanf("%d",n);
sum=sum+(w*n);}}
if(h==886)
{
L2: printf("总价格:$%4.2f\n",sum);
printf("收银 :$",u);
scanf("%f",u);
if(u==sum)
{ h1[i].fen=h1[i].fen+sum;
fwrite(h1,sizeof(struct hui),5,fp);
printf("购物完的积分:%.2f\t",h1[i].fen);
fclose(fp);
printf(" 谢谢您的光临\n");break;
}
else
{
sum=u-sum;
printf("请找零:$%4.2f\n",sum);
goto L2;
}
}
}
}
else if (m==2)//非会员购买
{
Shop1();
float u;
float sum=0;
int n;
int h;
float w;
Shop str1[5]=,,,,};
for(int j=0;j=1000;j++)
{
printf("请输入您所选择的商品编号(输入886结束): ");
scanf("%d",h);
for(int g1=0;g1=4;g1++)
{
if(h==str1[g1].num)
{
(w=str1[g1].jia);
printf("名称: %s\t价格:$%.2f \n",str1[g1].name ,str1[g1].jia );
printf("请输入所选择商品的数量: ");
scanf("%d",n);
sum=sum+(w*n);
}
}
if(h==886)
{
L3: printf("总价格:$%4.2f\n",sum);
printf("收银 :$",u);
scanf("%f",u);
if(u==sum)
{printf(" 谢谢您的光临\n");
break;
}
else
{ sum=u-sum;
printf("请找零:$%4.2f\n",sum);
goto L3;
}
}
}
}
}
#includestdio.h
int main()
{
int i,max,a,min,sum=0;
printf("请输入数字:\n");
scanf("%d",a);
max=a;
min=a;
for(i=2;i=5;i++)
{scanf("%d",a);
if(amin) min=a;
if(amax) max=a;}
sum=sum+i;
printf("\nmax=%d\nmin=%d\n",max,min);
}
#includestdio.h
int main()
{
struct Cargo
{
char Name[10];
double price;
int ID;
};
int i,ch0;
char ch;
struct Cargo Com[5];
for(i=0;i5;i++)
{
printf("Input Name:\n");
scanf("%s",Com[i].Name);
ch=getchar();
printf("Input the Price:\n");
scanf("%lf",Com[i].price);
ch=getchar();
printf("Input the No:\n");
scanf("%d",Com[i].ID);
ch=getchar();
}
printf("Input the ID to search:\n");
scanf("%d",ch0);
for(i=0;i5;i++)
if(Com[i].ID==ch0)
{
printf("Name:%s\n",Com[i].Name);
printf("Price:%lf",Com[i].price);
printf("ID:%d",Com[i].ID);
}
ch=getchar();
}
我自己设计了一个,你试试!操作结束后按Ctrl+z显示清单。使用方面有什么不懂可以问我!
#include "stdio.h"
typedef struct{
char node[100]; /*商品编号*/
char name[100];/*商品名称*/
float price;/*商品价格*/
} datatype;
typedef struct node{
datatype food[100];
int len;/*存放商品总数*/
}SPku;
datatype Input(void)
{datatype x;br/ scanf("%s %s %f",x.node,x.name,x.price);br/ printf("输入完毕!");br/return x;br/}
void create(SPku *r)
{ int i;
printf("\n输入商品总数:");
scanf("%d",r-len);
for(i=0;ir-len;i++)
{printf("\n输入商品编号 名称 价格:"); br/ r-food[i]=Input();br/ }
}
int strlen(char s[])
{int i;br/ for(i=0;is[i];i++);br/ return i;br/ }
int compare(char y[],char s[])
{int i;br/if(strlen(y)!=strlen(s))br/ return 0;br/elsebr/ for(i=0;istrlen(y);i++)br/ if(y[i]!=s[i])br/ return 0;br/ return 1;br/}
void Output(datatype f)
{
printf("\n%s %s %f",f.node,f.name,f.price);
}
int judge(SPku *r,char nd[])
{ int i;
for(i=0;ir-len;i++)
if(compare(r-food[i].node,nd))
{ Output(r-food[i]) ;
return i;
}
return 1000;
}
main()
{SPku r,n;br/ char nd[100];br/ int k,j,i,y=0;br/ printf("\n开始创建数据库...");br/ create(r);br/ printf("\n*********商品总单*********");br/ for(i=0;ir.len;i++)br/ Output(r.food[i]);br/ printf("\n**************************");br/while((j=getchar())!=EOF)br/ {br/ printf("\n扫描输入商品的编号:");br/ gets(nd);br/ printf("输入成功!");br/ k=judge(r,nd);br/ if(k==1000) br/ printf("\n无此商品...");br/ elsebr/ n.food[y++]=r.food[k];br/ }
printf("\n*********商品清单*********");
n.len=y;
for(i=0;in.len;i++)
Output(n.food[i]);
}
#include stdio.h
int main()
{
float totalprice=0,level=0; //总的消费额,打折等级标志
scanf("%d",totalprice);
if(totalprice=1000) level=1; //一共分为五等,不同等级,对应不同的优惠策略。
else if(totalprice1000 totalprice=2000) level=2;
else if(totalprice2000 totalprice=3000) level=3;
else if(totalprice3000 totalprice=5000) level=4;
else level=5;
switch(level) //一共分为五等,不同等级,对应不同的优惠策略。
{
case 1: printf("%f",totalprice);break;
case 2: printf("%f",totalprice*0.95);break;
case 3: printf("%f",totalprice*0.90);break;
case 4: printf("%f",totalprice*0.85);break;
default: printf("%f",totalprice*0.80);break;
}
return 0;
}
#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()
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()
void Add(ItemPurchaseInfo 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;
}
另外,站长团上有产品团购,便宜有保证