首页 > 其他 > 详细

设计Dog类 代码参考

时间:2020-03-28 18:35:35      阅读:54      评论:0      收藏:0      [点我收藏+]
 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 }

 

设计Dog类 代码参考

原文:https://www.cnblogs.com/Conan-jine/p/12588179.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!