//===================================
//ex0802.cpp
//使用 Cat类
//===================================
#include<iostream>
//-----------------------------------
class  Cat{
  int  itsAge;
public:
int  getAge();
void setAge(int age);
void meow();                      //喵喵叫
};//---------------------------------
int Cat::getAge(){  return itsAge;  }
void Cat::setAge(int age) {  itsAge=age;   } 
void Cat::meow() { std: :cout<<”Meow.\n”;  }
//-----------------------------------
int main(){ 
  Cat  frisky;
  frisky.setAge(5) ;
  frisky.meow();
  std::cout<<”frisky is  a cat who is  ”<<frisky.getAge()<<”  years  old.\n";
  frisky.meow();
}//==================================
     
//=================================== //ex0802.cpp using Cat class //=================================== #include"cat.h" #include<iostream> //----------------------------------- int main(){ Cat frisky; frisky.setAge(5) ; frisky.meow(); std::cout<<”frisky is a cat who is ”<<frisky.getAge()<<” years old.\n"; frisky.meow(); }//==================================类定义部分://=================================== //Cat.cpp //=================================== #include"cat.h" #include<iostream> //----------------------------------- int Cat::getAge(){ return itsAge; } void Cat::setAge(int age) { itsAge=age; } void Cat::meow() { std: :cout<<”Meow.\n”; } //-----------------------------------//=================================== //Cat.h //=================================== class Cat{ int itsAge; public: int getAge(); void setAge(int age); void meow(); //喵喵叫 };//---------------------------------