#include
#include
using namespace std;
class animal
{
private:
string animal_type;
int age;
char sex;
char max_age;
char state;
public:
animal(string);
~animal();
int get_age(void);
char get_sex(void);
char get_max_age(void);
char get_state(void);
void set_age(int);
void set_sex(char);
void set_max_age(char);
void set_state(char);
virtual void tell_name(void);
// operator
void operator +(animal&);
void operator -(animal&);
void operator =(animal&);
};
animal::animal(string name)
{
animal_type=name;
cout<<"new anniaml "<
}
animal::~animal()
{
cout<<"animal "<}
void animal::tell_name(void)
{
cout<<" in class top \n";
}
int animal::get_age(void)
{
return age;
}
char animal::get_sex(void)
{
return sex;
}
char animal::get_max_age(void)
{
return max_age;
}
char animal::get_state(void)
{
return state;
}
////////////////////////////////////
void animal::set_age(int i)
{
age=i;
}
void animal::set_sex(char i)
{
sex=i;
}
void animal::set_max_age(char i)
{
max_age=i;
}
void animal::set_state(char i)
{
state=i;
}
/*
const animal operator+( const animal& a, const animal& b)
{
// a.age=a.age+b.age;
int i;
i=a.get_age()+b.get_age();
a.set_age(i);
return a;
} */
void animal::operator +(animal& tmp)
{
age=age+tmp.get_age();
}
void animal::operator -(animal& tmp)
{
age=age-tmp.get_age();
}
void animal::operator =(animal& tmp)
{
age=tmp.get_age();
sex=tmp.get_sex();
max_age=tmp.get_max_age();
state=tmp.get_state();
}
int main(void)
{
//class//
animal cat("cat"),dog("dog");
cat.set_age(10);
dog.set_age(20);
cout<<"cat age is "< cat+dog;
cout<<"cat age is "<
dog=cat;
cout<<"cat age is "< dog-cat;
cout<<"cat age is "<
return 1;
}
阅读(1400) | 评论(0) | 转发(0) |