谁给我一个编程一个C++程序?

来源:百度知道 编辑:UC知道 时间:2024/06/28 07:50:59
要求:
定义一个cat类,包括数据成员age,weight,成员函数包括构造函数,setage(),setweight(),getage(),getweight(),定义一个对象A进行测试!

#include<iostream.h>
class Cat
{
int age; //定义成员变量
double weight; //定义成员变量
public:
Cat() //构造函数
{

}
void setage(int a) //设置年龄
{
age=a;
}
void setweight(double a) //设置宽度
{
weight=a;
}
int getage() //返回年龄
{
return age;
}
double getweight() //返回宽度
{
return weight;
}

};
void main()
{
Cat A;
A.setage(4);
A.setweight(5.5);
cout<<A.getage()<<endl; //输出
cout<<A.getweight()<<endl; //输出
}

#include<iostream.h>
class cat
{
public:
cat(int a,double b)
{age=a;weight=b;}
void setage(int a)
{age=a;}
void setweight(double a)
{weight=a;}
int getage()
{return this->age;}
double getweight()
{return this->weight;}
private:
int age;
double weight;

};

void