| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 461 人关注过本帖
标题:帮改哈,一个C++程序。
只看楼主 加入收藏
ggx7061131
Rank: 2
等 级:论坛游民
威 望:1
帖 子:21
专家分:12
注 册:2012-7-5
结帖率:100%
收藏
已结贴  问题点数:10 回复次数:2 
帮改哈,一个C++程序。
Food类(食品)
属性    商品名称,商品编号,进价,售价,库存数,入库时间,保质期
功能     录入食品信息,检查食品是否过期,显示食品信息
Dress类(衣服)
属性    商品名称,商品编号,进价,售价,库存数,入库时间,适合时令
功能     录入衣服信息,检查衣服是否适合当前季节,显示衣服信息
Appliance类(电器)
属性    商品名称,商品编号,进价,售价,库存数,入库时间,当前状况
功能     录入电器信息,显示电器信息


帮改哈,感谢
/*Commodity.h-----commodity(商品)的类声明头文件 ;
Commodity.cpp----包含commodity类的实现代码;
Food.h-----Food(食品)的类声明头文件;
Food.cpp----包含Food类的实现代码;
Dress.h-----Dress(衣服)的类的声明头文件;
Dress.cpp---包含Dress类的实现代码;
Appliance.h-----Appliance(电器)的类声明头文件;
commodity.h*/
#ifndef H_COMMODITY
#define H_COMMODITY
#include<time.h>
class commodity
{
    private:
        int number;
        char name[100];
        int buyPrice;
        int account;
    protected:
        tm dateIn;
    public:
        commodity();
        void showBaseInfor();
        int RecordBaseInfor(char*pInBuffer);
    public:
        virtual void showInfer()=0;
        virtual void RecordInfor(char*pInBuffer)=0;
        virtual void Check()=0;
};
#endif
#include<iostream.h>
#include<commodity.h>
#include<stdio.h>
#include<time.h>
commodity::commodity()
{cout<<endl;
cout<<"请输入商品名称:";
cin>>name;
cout<<"请输入商品编号(1000-9999):";
cin>>number;
while(number<1000||number>9999)
{
    cout<<"商品编号应为四位数,请重新输入:";
        cin>>number;
}
cout<<"请输入商品的进价:";
cin>>buyPrice;
cout<<"请输入商品的售价:";
cin>>salePrice;
cout<<"请输入商品的库存数:";
cin>>account;
cout<<"请输入商品入库的年份:";
cin>>dateIn.tm_year;
cout<<"请输入商品入库的月份:";
cin>>dateIn_.tm_mon;
cout<<"请输入商品入库为当月第几天:";
cin>>dateIn.tm_mday;
dateIn.tm_hour=0;
dateIn.tm_min=0;
dateIn.tm_sec=0;
while(dateIn.tm_year<1990||dateIn.tm_year>2050||dateIn.tm_mon<1||dateIn.tm_mon>12||dateIn.tm_mday>31)
{
cout<<"输入商品的入库时间错误,请重新输入:"<<endl;
cout<<"请输入商品入库的年份:";
cin>>dateIn.tm_year;
cout<<"请输入商品入库的月份:";
cin>>dateIn.tm_mon;
cout<<"请输入商品入库为当月的那一天:";
cin>>dateIn.tm_mday;
}
};
void commodity::showBaseInfor()
{
    cout<<endl;
    cout<<"商品名称:"<<name<<endl;
    cout<<"商品编号:"<<number<<endl;
    cout<<"进价:"<<buyPrice<<endl;
    cout<<"售价:"<<salePrice<<endl;
    cout<<"库存数:"<<accout<<endl;
    cout<<"入库时间:";
    cout<<dateIn.tm_year<<"年";
        cout<<dateIn.tm_mon<<"月";
        cout<<datein.tm_mday<<"日"<<endl;
};
int commodity::RecordBaseInfor(char*pInbuffer)
{ int j;
j=sprintf(pInBuffer,"商品名称:%s\r\n",name);
j+=sprintf(pInBuffer+j,"商品编号:%d\r\n",number);
j+=sprintf(pInbuffer+j,"进价:%f\r\n",buyPrice);
j+=sprintf(pInBuffer+j,"售价:%f\r\n",salePrice);
j+=sprintf(pInBuffer+j,"库存数:%d\r\n",account);
j+=sprintf(pInBuffer+j,"入库时间:%d年%d月%d日\r\n",dateIn.tm_year,
           dateIn.tm_mon,dateIn.tm_mday);
return j;
}
food.h
#ifndef H_FOOD
#define H_food
#include<Commodity.h>
class Food:public commodity
{
    private:
        tm   deadline;
        bool   isCheak;
        long    remainDays;
    public:
        Food();
        void ShowInfor();
        void RecordInfor(char*pInBuffer);
        void Check();
};
#endlif
Food.cpp
#include<Food.h>
#include<iostream.h>
#include<stdio.h>
Food::Food()
{   isCheck=false;
remainDay=0;
cout<<"请输入该食品的保质期:"<<endl;
cout<<"保质年数:";
cin>>deadline.tm_year;
cout<<"保质月份:";
cin>>deadline.tm_mon;
cout<<"保质天数:";
cin>>deadline.tm_mday;
deadline.tm_hour=0;
deadline.tm_min=0;
deadline.tm_sec=0;
}
void Food::showInfor()
{  ShowBaseInfor();
cout<<"商品类型:食物"<<endl;
cout<<"保质期:";
cout<<deadline.tm_year<<"年";
cout<<deadline.tm_mon<<"月";
cout<<deadline.tm_mday<<"日"<<endl;
if(isCheck)
{if(remainDay>0)
cout<<"注意:该食品还有"<<remainDays<<"天到期!"<<endl;
else
cout<<"注意:该食品已经到期了,必须尽快处理!"<<endl;
}
else
cout<<"注意:该食品还没有经过检查!"<<endl;
}
void Food::RecordInfor(char*pInfBuffer)
{
    int  j;
    j=RecordBaseInfor(pInfBuffer);
    j+=sprintf(pInfBuffer+j,"商品类型:食品\r\n");
    j+=sprintf(pInfBuffer+j,"保质期"%d年%d月%d日\r\n",deadline.tm_year,deadline.tm_mon,deadline.tm_mday);
        j+=sprintf(pInfBuffer+j,"检查结果:");
    if(isCheck)
    {if(remainDays>0)
    j+=sprintf(pInfBuffer+j,"该食品还有%d天到期!\r\n",remainDays);
    else
        j+=sprintf(pInfBuffer+j,"该食品已经到期,必须尽快处理!\r\n");
    }
    else
        j+=sprintf(pInfBuffer+j,"该食品还没有经过检查!\r\n");
    j+=sprintf(pInfBuffer+j,"\r\n");
    void Food::Check()
    {
        time_t   start,today;
        tm   TempTm;
        double   diff;
        int    days;
        time(&today);
        TempTm=dateIn;
        TempTm.tm_year-=1900;
        TempTm.tm_mon-=1;
        start=mktime(&TempTm);
        diff=difftime(today,start);
        days=(int)(diff/(3600*24));
        remainDays=deadline.tm_year*365+deadline.tm_mon*30+deadline.tm_mday-days;
        isCheck=true;
    }
    Dress.h
#ifndef H_DRESS
#define H_DRESS
#include<Commodity.h>
        class Dress:public commodity
    {
    private:
        int   seasonStyle;
        int   checkResult;
    public:
        Dress();
        void showInfor();
        void RecordInfor(char*pInBuffer);
        void Check();
    };
#endif
    Dress.cpp
#include<Dress.h>
#include<iostream.h>
#include<stdio.h>
        Dress::Dress()
    {
        checkResult=0;
        cout<<"请输入该衣服的时令(1.春装;2.夏装;3.秋装;4.冬装):";
        cin>>seasonStyle;
    }
    void Dress::showInfor()
    {
        showBaseInfor();
        cout<<"商品类型:衣服"<<endl;
cout<<"时令:";
switch(seasonStyle){
    case 1:
        cout<<"春装"<<endl;
        break;
case 2:
        cout<<"夏装"<<endl;
        break;
case 3:
        cout<<"秋装"<<endl;
        break;
case 4:
    cout<<"冬装"<<endl;
    break;
}
switch(checkResult){
case -1:
    cout<<"注意:该衣服应进行销价处理!"<<endl;
    break;
case 0:
    cout<<"注意:该衣服还没有经过检查!"<<endl;
    break;
case 1:
    cout<<"注意:该衣服适合当前季节,可以进行出售"<<endl;
    break;
}
    }
void Dress::RecordInfor(char*pInBuffer)
{  int j;
j=RecordBaseInfor(pInfBuffer);
j+=sprintf(pInfBuffer+j,"商品类型:衣服\r\n");
switch(seasonStyle){
case 1:
j+=sprintf(pInfBuffer+j,"时令:春装\r\n");
break;
case 2:
    j+=sprintf(pInfBuffer+j,"时令:夏装\r\n");
    break;
case 3:
    j+=sprintf(pInfBuffer+j,"时令:秋装\r\n");
    break;
case 4:
    j+=sprintf(pInfBuffer+j,"时令:冬装\r\n");
    break;}
j+=sprintf(pInfBuffer+j,"检查结果:");
switch(checkResult){
case-1:
cout<<"注意:该衣服应进行销价处理!"<<endl;
    break;
case 0:
    cout<<"注意:该衣服还没有经过检查!"<<endl;
    break;
case 1:
    cout<<"注意:该衣服适合当前季节,可以进行出售"<<endl;
    break;}
j+=sprintf(pInfBuffer+j,"\r\n");
void Dress::Check()
time_t ltime;
tm * today;
time(&ltime);
today=localtime(&time);
today->tm_mon+=1;
if(today->tm_mon=3&&today->tm_mon<=5)
{
    if(seasonStyle==1)
        checkResult=1;
    else checkResult=-1;
}
if(today->tm_mon=6&&today->tm_mon<=8)
{
    if(seasonStyle==1)
        checkResult=1;
    else checkResult=-1;
}
if(today->tm_mon=9&&today->tm_mon<=11)
{
    if(seasonStyle==1)
        checkResult=1;
    else checkResult=-1;
}if(today->tm_mon=12&&today->tm_mon<=2)
{
    if(seasonStyle==1)
        checkResult=1;
    else checkResult=-1;
}
}
Appliance.h
#ifndef H_APPLICANCE
#define H_APPLICANCE
#include<Commodity.h>
class Appliance:public commodity
{
    private:
        int nowState;
    public:
        Appliance();
        void ShowInfor();
        void RecordInfor(char*pInBuffer);
        void Check();
};
#endif
Appliance.cpp
#include<Appliance.h>
#include<iostream.h>
#include<stdio.h>
Appliance::Appliance()
{ cout<<"请输入该电器的检测情况(1:良好;0:损坏):";
cin>>nowState;
}
void Appliance::showInfor()
{
    ShowBaseInfor();
    cout<<"商品类型:电器"<<endl;
    cout<<"检查结果:";
    switch(nowState){
    case 1:
        cout<<"良好"<<endl;
        break;
            case 0:
        cout<<"损坏"<<endl;
        break;}
}
void Appliance::RecoedInfor(char*pInfBuffer)
{ int j;
j=RecordBaseInfor(pInfBuffer);
j+=sprintf(pInfBuffer+j,"商品类型:电器\r\n");
switch(seasonStyle){
case 1:
j+=sprintf(pInfBuffer+j,"时令:春装\r\n");
break;
case 2:
    j+=sprintf(pInfBuffer+j,"时令:夏装\r\n");
    break;
case 3:
    j+=sprintf(pInfBuffer+j,"时令:秋装\r\n");
    break;
case 4:
    j+=sprintf(pInfBuffer+j,"时令:冬装\r\n");
    break;}
j+=sprintf(pInfBuffer+j,"检查结果:");
搜索更多相关主题的帖子: 保质期 信息 商品 
2013-01-16 10:49
peach5460
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:武汉
等 级:贵宾
威 望:30
帖 子:2780
专家分:6060
注 册:2008-1-28
收藏
得分:5 
超过20行的脑残代码,我一般只帮顶

我总觉得授人以鱼不如授人以渔...
可是总有些SB叫嚣着:要么给代码给答案,要么滚蛋...
虽然我知道不要跟SB一般见识,但是我真的没修炼到宠辱不惊...
2013-01-16 11:48
浅水无殇
Rank: 2
等 级:论坛游民
帖 子:123
专家分:75
注 册:2012-11-23
收藏
得分:5 
啧啧。。算了,下午还有高数考试,留点精神。。。

wula wual
2013-01-16 12:04
快速回复:帮改哈,一个C++程序。
数据加载中...
 
   



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

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