这道题还是挺水的
我朋友的
#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;
}