欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

设计Dog类 代码参考

程序员文章站 2022-06-15 13:17:35
1 #include 2 #include 3 4 using namespace std; 5 6 class Dog 7 { 8 private: 9 string name; 10 int age; 11 char sex; 12 double weig ......
 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 }

 

上一篇: PHP webshell

下一篇: php命名空间