您现在的位置: 汕头自考网 >> 串讲笔记 >> 理学类 >> 正文
  • 北大“面向对象程序设计”上机试题(含答案)
  • 发布日期时间:2007-3-6  来源:不详   点击数:  作者:佚名
gt;>(std::istream & is,Cat &cat);

  void deleteme();

  ~Cat();

  private:

  static int Catnum;

  };

  class Dog:public Animal

  {

  public:

  Dog();

  void showme();

  static int number();

  friend std::istream & operator>>(std::istream & is,Dog &dog);

  void deleteme();

  ~Dog();

  private:

  static int Dognum;

  };

  class Snake:public Animal

  {

  public:

  Snake();

  void showme();

  static int number();

  friend std::istream & operator>>(std::istream & is ,Snake &snake);

  void deleteme();

  ~Snake();

  private:

  static int Snakenum;

  };

  class Shelves

  {

  public:

  Shelves();

  int add(int n,Animal *animal);

  void Delete(int n);

  void query(int n);

  void stat();

  private:

  Animal * shelves[12];

  };

  #endif

  Animal.cpp

  #include<iostream>

  #include“animal.h”

  using std::cout;

  using std::cin;

  using std::endl;

  int Cat::Catnum=0;

  Cat::Cat()

  {

  type=0;

  weight=0;

  name=new char[20];

  color =new char [20];

  food=new char [20];

  Catnum++;

  }

  void Cat::showme()

  {

  cout<<“I am a Cat.”<<endl;

  cout<<“ My name is ”<<name<<endl;

  cout<<“ My color is ”<<color<<endl;

  cout<<“My weight is ”<<weight<<endl;

  cout <<“ My favorite foood is ”<<food <<endl;

  return ;

  }

  int Cat::number()

  {

  return Catnum;

  }

  std::istream & operator>>(std::istream & is ,Cat &cat)

  {

  cout<<“ the cat's name is :”;

  is>>cat.name;

  cout<<endl<<“the cat's color is:”;

  is>>cat.color;

  cout<<endl<<“ the cat's weight is :”;

  is>>cat.weight;

  cout<<endl<<“the cat's fovarite food is :”;

  cin>>cat.food;

  return is;

  }

  void Cat::deleteme()

  {

  Catnum——;

  }

  Cat::~Cat()

  {

  }

  int Dog::Dognum=0;

  Dog::Dog()

  {

  type=1;

  name=new char [20];

  color =new char [20];

  food=new char [20];

  weight=0;

  Dognum++;

  }

  void Dog::showme()

  {

  cout<<endl<<“I am a Dog”<<endl;

  cout<<“My name is ”<<name<<endl;

  cout<<“ My color is ”<<color&l

上一页  [1] [2] [3] [4] [5] [6] [7] [8] [9] 下一页

文章转载请注明来源于:汕头自考网