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 dog(string,int,char,double); 15 void getname(){cin>>name;return;} 16 void getage(){cin>>age;return;} 17 void getsex(){cin>>sex;return;} 18 void getweigth(){cin>>weight;return;} 19 void speak(){cout<<"arf!arf!"<<endl;return;} 20 void show() 21 { 22 cout<<name<<endl; 23 cout<<age<<endl; 24 cout<<sex<<endl; 25 cout<<weight<<endl; 26 return; 27 } 28 }; 29 30 dog::dog(string name, int age, char sex, double weight) 31 { 32 this->name=name; 33 this->age=age; 34 this->sex=sex; 35 this->weight=weight; 36 } 37 38 int main() 39 { 40 string name; 41 int age; 42 char sex; 43 double weight; 44 cin>>name>>age>>sex>>weight; 45 dog one(name,age,sex,weight); 46 one.show(); 47 one.speak(); 48 return 0; 49 }
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/c-cdevelopment/600009.html