山科oj2307 Problem C: Cherry

在这里插入图片描述这道题还是挺水的
我朋友的

#include <bits/stdc++.h>
using namespace std;
class Cherry
{
public:
    Cherry(double a = 0, double b = 0):w(a), am(b)
    {
        w = w*am;
    }
    double weight()
    {
        return w;
    }
    double weight(double m)
    {
        w = m;
    }
    double sold_weight(double m)
    {
        w -= m;
    }
private:
    double w, am;
};

int main()
{
    double weight, amount;
    cin >> weight >> amount;

    Cherry cherry(weight, amount);
    Cherry sold_cherry[100];

    int cases;
    cin >> cases;
    for(int i = 0; i < cases; i++)
    {
        double w;
        cin >> w;
        sold_cherry[i].weight(w);
        cherry.sold_weight(w);
    }
    cout << cherry.weight() << endl;
}

我的
我菜炸了

#include<iostream>
using namespace std;
class Cherry
{
private:
    double weigt,amount,total;
public:
    Cherry()
    {
        weigt=0;
    }
    Cherry(double ww,double aa)
    {
        total=ww*aa;
        weigt=total;
    }
    double weight()
    {
        return weigt;
    }
    void weight(double a)
    {
        weigt=weigt+a;
    }
    void sold_weight(double a)
    {
        weigt=weigt-a;
    }
};

int main()
{
    double weight, amount;
    cin >> weight >> amount;

    Cherry cherry(weight, amount);
    Cherry sold_cherry[100];

    int cases;
    cin >> cases;
    for(int i = 0; i < cases; i++)
    {
        double w;
        cin >> w;
        sold_cherry[i].weight(w);
        cherry.sold_weight(w);
    }
    cout << cherry.weight() << endl;
}

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值