每日一个C++小程序(四)--DOG类

来源:互联网 发布:燃气灶烤箱一体机 知乎 编辑:程序博客网 时间:2024/06/08 10:53
#include<iostream>using namespace std;class Dog{   public:   Dog(int Bage=0,int Bweight=5);//构造函数   ~Dog();//析构函数   int GetAge() { return Hage; }   void SetAge(int age) { Hage=age; }   int GetWeight() { return Hweight; }   void SetWeight(int weight) { Hweight=weight; }      private:   int Hage,Hweight;};Dog::Dog(int Bage,int Bweight){   Hage=Bage;   Hweight=Bweight;}Dog::~Dog() {}//析构函数,不做任何工作int main(){   Dog Tom,Jack(2,10);   cout<<"when Tom born,it is "<<Tom.GetAge()<<" years old and he is "<<Tom.GetWeight()<<" pounds weight."<<endl;   cout<<"Jack is a dog who is "<<Jack.GetAge()<<" years old and he is "<<Jack.GetWeight()<<" pounds weight."<<endl;      Jack.SetAge(7);   Jack.SetWeight(20);   cout<<"Now Jack is "<<Jack.GetAge()<<" years old and "<<Jack.GetWeight()<<" pounds weight."<<endl;   return(0);}

—————————————————————————————————

本文原创自Sliencecsdn技术博客。

本博客所有原创文章请以链接形式注明出处。

欢迎关注本技术博客,本博客的文章会不定期更新。


大多数人想要改造这个世界,但却罕有人想改造自己。

世上没有绝望的处境,只有对处境绝望的人。

                                              ————By slience

—————————————————————————————————


0 0
原创粉丝点击