练习4

    xiaoxiao2021-03-25  53

    #include <iostream> #include <string> using namespace std; class Dog{ public:     void setAttribute(string name,float age,string sex,float weight);     void showAttribute(); private:     string N;float A;string S;float W; }; void Dog::setAttribute(string name,float age,string sex,float weight){     N=name;     A=age;     S=sex;     W=weight; } inline void Dog::showAttribute(){     cout<<"The dog is named as "<<N<<endl;     cout<<"The dog is "<<A<<" years old"<<endl;     cout<<"The dog is "<<S<<endl;     cout<<"The dog is "<<W<<" pounds"<<endl; } int main(){     Dog myDog;     string name,sex;     float age,weight;     cout<<"Please input the dog's attribute:"<<endl;     cin>>name>>age>>sex>>weight;     myDog.setAttribute(name,age,sex,weight);     myDog.showAttribute();     return 0; }
    转载请注明原文地址: https://ju.6miu.com/read-36065.html

    最新回复(0)