pxxfxxxxx

导航

复习题1

#include<iostream>
 
using namespace std;
 
class Cup
{
private:
    int volume;
public:
    Cup(int v=0):volume(v)
    {
        cout<<"A cup of "<<volume<<" ml is created."<<endl;
    }
    Cup(const Cup& c):volume(c.volume)
    {
        cout<<"A cup of "<<volume<<" ml is copied."<<endl;
    }
    ~Cup()
    {
        cout<<"A cup of "<<volume<<" ml is erased."<<endl;
    }
    void setVolume(int v)
    {
        volume=v;
    }
};
int main()
{
    Cup c1;
    int i, j;
    cin>>i>>j;
    Cup c2(i), c3(c2);
    c3.setVolume(j);
    return 0;
}

 

posted on 2019-07-05 11:55  pxxfxxxxx  阅读(120)  评论(0编辑  收藏  举报