| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 767 人关注过本帖
标题:关于用链表方式实现对超市定价管理
取消只看楼主 加入收藏
丘汤媚
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2013-12-12
结帖率:25%
收藏
 问题点数:0 回复次数:3 
关于用链表方式实现对超市定价管理
#include<iostream>
#include<string>
using namespace std;
struct supermarket
{int num;string name;double price_trade;int pre_days;double price_retail;int count;supermarket *next;};
supermarket *creat(void);
void sum(supermarket *,int);
int n;
int main()
{
    char c;
    int number;
    bool prime=true;
    supermarket *head,*q;
    cout<<"calculate retail price(y).exit program(n)."<<endl;
    cin>>c;
    if(c=='y'|| c=='Y')
        head=creat();      
    else return 0;
    while(prime)
    {
        cin>>number;
        sum(head,number);
        cout<<"continue or not?"<<endl;
        cin>>c;
        if(c=='y'|| c=='Y')
            prime=true;
        else prime=false;
    }
    q=head;
    cout<<"商品的销售情况:"<<endl;
    while(head!=0&&q!=0)
    {
        cout<<q->num<<' '<<q->name<<' '<<q->price_retail<<q->count;
        q=q->next;
    }
    return 0;
}

   
supermarket *creat(void)
{
    supermarket *head,*p1,*p2;
    n=0;
    p1=p2=new supermarket;
    cout<<"请输入各个商品的编号,名称,批发价,预售天数:"<<endl;
    cin>>p1->num>>p1->name>>p1->price_trade>>p1->pre_days;
    p1->price_retail=p1->price_trade+p1->pre_days/4;
    head=NULL;
    while(p1->num!=0)
    {
        n=n+1;
        if(n==1)
            head=p1;
        else p2->next=p1;
        p2=p1;
        p1=new supermarket;
        p1->price_retail=p1->price_trade+p1->pre_days/4;
    }
    p2->next=NULL;
    return head;
}

void sum(supermarket *head,int n)
{
    supermarket *p;  
    p=head;
    p->count=0;
    if(head!=NULL)
        while(p!=NULL)
        {
            if(p->num==n)
            {p->count=p->count+1;break;}
             p=p->next;
        }
}
编译没问题,但是运行不出结果,求指教!
搜索更多相关主题的帖子: include double number return price 
2014-04-13 21:32
丘汤媚
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2013-12-12
收藏
得分:0 
我改了一下,可是还不行啊
  while(p1->num!=0)
     {
         n=n+1;
         if(n==1)
             head=p1;
         else p2->next=p1;
         p2=p1;
         p1->price_retail=p1->price_trade+p1->pre_days/4;
         p1=new supermarket;
         cin>>p1->num>>p1->name>>p1->price_trade>>p1->pre_days;
     }
2014-04-14 12:34
丘汤媚
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2013-12-12
收藏
得分:0 
谁能帮我改一下吗?
2014-04-14 12:39
丘汤媚
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2013-12-12
收藏
得分:0 
可是我是输入了p1->num的值,才进行判断的
2014-04-14 21:57
快速回复:关于用链表方式实现对超市定价管理
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024536 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved