我的第一个完整的超长的C++程序

P228 4.12

Derive classes Fruit,Dairy and meat, appropriate for a grocery chain,from class Product of Programming 3.23 ,also derive classes from each of Fruit,Dairy and meat.

Include any reasonable data members and methods .Assume that evey product has supply and demand data memberswhose values are one of the qualitative values low,medium,high.Incluse a method  that computes a product‘s price change based on its values of supply and demand.

#include<iostream>
#include<string>

using namespace std;

class Product{
public:
    int supply,demand;
    double p;

    Product(){};
        Product(string na):name(na){
        };
        Product(string na,double pri):name(na),price( pri){
        };
        Product(string na,double pri,int da):name( na),price( pri),date(da){
        };
        void Input();
        void Output();
        void setSupply();
        void setDemand();
        void setPrice();

private:
        string name;
        double price;
        int date;
        string manuf;

};
class Fruit: public Product{

};
class Dairy:public Product{

};
class Meat:public Product{
};

class Cuke:public Fruit{
    public:

        void pricechange()
        {
                    if(supply>demand)
            {
            p=p*0.95;
                cout<<"output the changed price:"<<endl;
            cout << p<<endl;
            }
            if(supply=demand)
            {
                p=p*1.0;
                    cout<<"output the changed price:"<<endl;
                cout<< p<<endl;
            }

            if(supply<demand)
            {
                p=p*2.0;
                    cout<<"output the changed price:"<<endl;
                cout<<p<<endl;
            }
        };

};
class Butter:public Dairy{
    public:

        void pricechange()
        {
                if(supply>demand)
            {
            p=p*0.95;
                cout<<"output the changed price:"<<endl;
            cout << p<<endl;
            }
            if(supply=demand)
            {
                p=p*1.0;
                    cout<<"output the changed price:"<<endl;
                cout<< p<<endl;
            }

            if(supply<demand)
            {
                p=p*2.0;
                    cout<<"output the changed price:"<<endl;
                cout<<p<<endl;
            }
        };

};
class Milk:public Dairy{
    public:

        void pricechange()
        {
            if(supply>demand)
            {
            p=p*0.95;
                cout<<"output the changed price:"<<endl;
            cout << p<<endl;
            }
            if(supply=demand)
            {
                p=p*1.0;
                    cout<<"output the changed price:"<<endl;
                cout<< p<<endl;
            }

            if(supply<demand)
            {
                p=p*2.0;
                    cout<<"output the changed price:"<<endl;
                cout<<p<<endl;
            }
        };

};
class Beef:public Meat{
    public:

        void pricechange()
        {
            if(supply>demand)
            {
            p=p*0.95;
            cout<<"output the changed price:"<<endl;
            cout << p<<endl;
            }
            if(supply==demand)
            {
                p=p*1.0;
                    cout<<"output the changed price:"<<endl;
                cout<< p<<endl;
            }

            if(supply<demand)
            {
                p=p*2.0;
                    cout<<"output the changed price:"<<endl;
                cout<<p<<endl;
            }
        };

};
void Product :: Input()
{
    cout << "input name:"<< endl;

    getline(cin,name);

    cout << "input price:"<< endl;

    cin >> price;

    cout << "input date:" << endl;

    cin >>  date;

}
void Product :: Output()
{
    string st;
    cout<< "input the information you want:"<< endl;
    cout << "name,price,date "<<endl;
    cin >> st;
    if(st == "name" )

        cout << name <<endl;

    if(st =="price")

        cout << price << endl;

    if(st == "date")

        cout << date << endl;

}

void Product::setSupply()
        {

            cout<<"input the supply:"<<endl;
            cout<<"low=-1,medium=0,high=1"<<endl;
            cin >> supply;
        }
void Product::setDemand()
        {

            cout<<"input the demand:"<<endl;
            cout<<"low=-1,medium=0,high=1"<<endl;
            cin >> demand;
            }
void Product::setPrice()
{
    cout<<"input the price"<<endl;
//    double p;//p已经在基类定义了 此处再定义p 作用域只是在这个函数里面,输入的p不能代表基类的p 会使上面的p没有值出现#%#¥%@#%¥
    cin >> p;
}
int main()
{
    Product p1;
    p1.Input();
    p1.Output();
    Cuke p2;
    p2.setDemand();
    p2.setSupply();
    p2.setPrice();
    p2.pricechange();

    return 0;
}
时间: 2024-08-27 23:58:42

我的第一个完整的超长的C++程序的相关文章

记自己的第一个完整的java web项目

我是从asp.net平台转到java平台的.基于asp.net平台开发网站的快速便捷性,工作几年来大小网站多少也写了6.7个.但是转到java后,因为是在一家大公司,而且做的功能也比较单一,局限于此,一直未能使用java来写一个web站点.后来正好大学同学从事淘宝电商,让我帮他弄一个网站,所以我就想到了使用java来开发这个站点,正好练手一下java顺便也是使用一下bae,因为很早之前就接触到了BAE,但是问题在于无法部署asp.net的网站,所以只好作罢,这次正好是一个难得的机会.     考

使用完整读写函数的网络应用程序

使用完整读写函数的网络应用程序 Linux的设计原则是将硬件设备抽象成文件,用户可以像操作文件一样操作设备,前边已经说过,我们可以使用文件操作函数操作套接字. 使用read函数读取套接字另一端发送过来的内容,使用write函数也可以向套接字另一端发送内容.但是,在网络环境中有一个很大的问题就是延时的问题,对于本地文件夹来说,字节流在本地传输的延时可以忽略不计,但是网络环境中传输延时可能会很长造成I/O阻塞.其次,网络应用程序要能够处理因为中断或者网络连接等问题造成的读写操作异常返回. 对于第一个

NSIS制作了一个完整的演示产品安装程序

NSIS制作了一个完整的演示产品安装程序,实现功能概要如下:1.安装路径的选择2.浏览器的选择3.桌面数据库的自动安装及启动 4.数据库实例及演示数据的自动恢复 5.应用服务器的自动安装 6.JDK的安装及环境变量的设置 7.应用程序的自动安装 8.数据库实例端口的设置(要考虑用户机器上可能存在别的sqlserver数据库实例) 9.windows服务中的自动启动项的安装 10.启动应用 11.readme的打开 12.用浏览器打开应用的登录界面 13.在安装过程中切换公司或应用的介绍信息: 1

第一个完整的iOS小demo:引导

断断续续地熟悉了一些常用的控件的动态创建方式,也就是用纯代码创建,不用Interface Builder来拖放控件,也动手一一去实现了.基础的东西熟悉之后还是觉得很迷惘,不知道可以做些啥,领导建议让我直接查看公司现有的App源码,让我把那个引导功能给仿出来~ 有了目标,接下来就要分析怎么去实现了,不用第三方库,最简单的大概就是用UIScrollView来实现了,主要有这么几点: 4个页 每页上面都有一张大图 每页上面都有显示当前页的标识(页码) 最后一页应该有个跳过的按钮 先放上成品图,然后再放

第一个完整一点的项目记录下自己的坎坷之路

这是一个管理系统  今天实现了注册和登陆的功能以及过滤器判断是否登录访问 这是一个注册和登录的界面 用到了前端页面中自带的一点H5的标签和属性---巩固下 邮箱格式 :type="email"  不能为空:  required="required" js 添加提示语句 : document.getElementById("agree").setCustomValidity("需同意协议"); 这是一个判断是否有重复用户的js

写了人生中第一个完整模块的用例

我好激动,因为这次机会终于争取来了 以前都是做项目测试,单个网站的测试,1个小时以内结束 经过不断的努力争取,领导终于分给我了一个完整的功能模块 其实我自己完全可以利用业余时间写用例,但是没人反馈,没有与开发和策划的互动 这样的努力是低效的 我更喜欢在工作中进行更多的交流与学习,因为有反馈 咳咳,回到正题 这次我和同事的任务是通测xx小程序,我先写"捐赠"模块的用例,同事评估后再说后续工作 经过几经折腾,终于写出了有正确前置条件的"捐赠"模块的用例,共计115条,减

“洋垃圾”复活记:夏普shl25刷机救砖实战指南(也许是网上第一篇完整的SHL25的刷机教程)

废话: 两个月前在网上发现一篇二手手机购买使用评测,手机外观漂亮,机器参数牛逼,价格白菜价. 很久没折腾了,瞬间手痒想买来做备用机,立马某宝下单.快递很快,第二天就到了.开箱很新, 不仔细看看不出是二手机,九成新的,赚大了,接下来就看人品能用多久了. 声明:这不是广告,某宝没卖下架啦o(∩_∩)o 哈哈,教程仅供参考,刷机有风险的哟 日媒解析: AQUOS SERIE SHL25拥有最先进的CPU.高画质的照相机.低耗能的IGZO液晶屏,同时具有防水.防尘.full segment等功能,最大传

第一个完整的cppunit单元测试程序

在极限编程中,测试程序本应该在编写主程序之前就要写好,然后将写好的类程序放在测试程序中进行测试,但考虑到项目中需求文档等并未将接口定义好,我无从开始,而且,自己对单元测试也是刚刚熟悉,需要一边写测试程序一边解决遇到的问题,时间周期较长.在本次编程中,我是直接把github上小组的程序下载下来,看有哪些接口,再来编写的测试程序. 测试对象:robot类中的solver类(https://github.com/TeamWork-Robot/Team1/tree/master/Robot):选择sol

2016-1-5第一个完整APP 私人通讯录的实现 4:编辑联系人

一:建立编辑联系人的controller,并使其拥有模型contact,且有协议.代码如下 #import <UIKit/UIKit.h> #import "contact.h" @class EditContactViewController ; @protocol EditContactViewControllerDelegate<NSObject> - (void) editContactViewController:(EditContactViewCon