Dog类c++(练习题)

#include <iostream>
#include<cmath>
using namespace std;
class Dog{
        public:
        Dog();
        Dog(int a,double w):age(a),weight(w)
    {cout<<"Consyructor called"<<endl;}
        void setDog(int a,double w){
        age=a;
        weight=w;
        }
        int geta(){return age;}        
        double getw(){return weight;}                
        ~Dog()
        {cout<<"Destructor called."<<endl;}
        void display()
        {cout<<age<<endl<<weight<<endl;}
        private:
        int age;double weight;
        };
    Dog::Dog()
        {age=0;weight=0;}                
        int main()
        {
    Dog r(10,18.9);
        r.display();
        r.setDog(11,20);
        cout<<r.geta()<<endl<<r.getw()<<endl;
    return 0;
}


版权声明:本文为kt1776133839原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。