#include<iostream>
using namespace std;
class Bottle{
private:
int type;
int now;
public:
Bottle(int a,int b)
{
type=a;
now=b;
}
void Pour(Bottle bottle)
{
if(type>bottle.type)
{
bottle.now=bottle.type;
now=now-bottle.type;
}
else
{
bottle.now=now;
now=0;
}
cout<<endl<<bottle.now; //这里显示的还是 3
}
void print()
{
cout<<"当前液体体积为"<<type<<"的瓶子的状况为 : (有多少升液体)"<<now<<endl;
cout<<endl;
cout<<endl;
cout<<endl;
}
};
int main()
{
Bottle a(10,10);
Bottle b(7,0);
Bottle c(3,0);
a.print();
c.print();
a.Pour(c);
a.print();
c.print(); //这里显示的 3L的瓶子当前液体的体积就是0了?????
return 0;
}
运行之后程序明明应该三升的瓶子满了的,看了好长时间没看出名堂
using namespace std;
class Bottle{
private:
int type;
int now;
public:
Bottle(int a,int b)
{
type=a;
now=b;
}
void Pour(Bottle bottle)
{
if(type>bottle.type)
{
bottle.now=bottle.type;
now=now-bottle.type;
}
else
{
bottle.now=now;
now=0;
}
cout<<endl<<bottle.now; //这里显示的还是 3
}
void print()
{
cout<<"当前液体体积为"<<type<<"的瓶子的状况为 : (有多少升液体)"<<now<<endl;
cout<<endl;
cout<<endl;
cout<<endl;
}
};
int main()
{
Bottle a(10,10);
Bottle b(7,0);
Bottle c(3,0);
a.print();
c.print();
a.Pour(c);
a.print();
c.print(); //这里显示的 3L的瓶子当前液体的体积就是0了?????
return 0;
}
运行之后程序明明应该三升的瓶子满了的,看了好长时间没看出名堂