/*定义一个Dog类,包含age,weight等属性,以及对这些属性操作的方法
实现并测试这个类*/
#include <iostream>
#include <string.h>
#define N 10
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
class Dog{
public:
void Age(int a);
void Weight(int b);
void Haircolor(char s[N]);
private:
int x,y;
char c[N];
};
void Dog::Age(int a){
x=a;
cout<<"age="<<x<<endl;
}
void Dog::Weight(int b){
y=b;
cout<<"weight="<<y<<endl;
}
void Dog::Haircolor(char s[N]){
int i=0,n=0;
strcat(c,s);
n=strlen(c);
cout<<"Haircolor=";
while((i++)<n){
cout<<c[i];
}
}
int main(int argc, char** argv) {
Dog mydog; //定义对象mydog
int x=0,y=0;
char c[N];
cin>>x>>y;
cin>>c[N];
mydog.Age(x);
mydog.Weight(y);
mydog.Haircolor(c);
return 0;
}
```![图片说明](https://img-ask.csdn.net/upload/202003/20/1584669498_184479.png)