分享

设计Dog类 代码参考

 行者花雕 2020-06-06
 1 #include <iostream>
 2 #include <string>
 3 
 4 using namespace std;
 5 
 6 class Dog
 7 {
 8     private:
 9         string name;
10         int age;
11         char sex;
12         double weight;
13     public:
14         void GetName(){cin>>name;return;}
15         void GetAge(){cin>>age;return;}
16         void GetSex(){cin>>sex;return;}
17         void GetWeight(){cin>>weight;return;}
18         void ShowMyDog(){
19             cout<<"It is my dog."<<endl;
20             cout<<"Its name is "<<name<<'.'<<endl;
21             cout<<"It is "<<age<<" years old."<<endl;
22             if(sex=='m')    cout<<"It is male."<<endl;
23             else    cout<<"It is female."<<endl;
24             cout<<"It is "<<weight<<" kg."<<endl;
25             return;
26         }
27 };
28 
29 int main()
30 {
31     Dog one;
32     one.GetName();
33     one.GetAge();
34     one.GetSex();
35     one.GetWeight();
36     one.ShowMyDog();
37     return 0;
38 }

 

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多