Beispiel #1
0
int main() {

	Animal fred;

	fred.setHeight(33);
	fred.setName("fred");
	fred.toString();

	Animal tom(36, 15, "tom");
	tom.toString();

	Dog balou(44, 23, "balou", "wufff");
	balou.toString();
	balou.Animal::toString();

	Animal* fp = &fred;
	cout << "Compare To: " << balou.compareTo(fred) << endl;
	cout << "Compare To: " << balou.compareTo(fp) << endl;
	balou.setWeight(10);
	fred.setWeight(10);
	cout << "Compare To: " << balou.compareTo(fred) << endl;

	cout << Animal::getNumOfAnimals() << endl;
    // everything went successful
    return 0;
}
int main()
{
    Shelter aq;
    Cat c1("Cat1");
    Cat c2("Cat2");
    Cat c3("Cat3");
    Dog d1("Dog1");
    Dog d2("Dog2");
    Dog d3("Dog3");

    aq.enqueue(d1);
    aq.enqueue(c1);
    aq.enqueue(c2);
    aq.enqueue(c3);
    aq.enqueue(d2);
    aq.enqueue(d3);

    Animal a = aq.dequeueAny();
    cout << "Get your pet: " << a.getName() << endl;
    Cat c = aq.dequeueCat();
    cout << "Get your cat: " << c.getName() << endl;
    Dog d = aq.dequeueDog();
    cout << "Get your dog: " << d.getName() << endl;
    return 0;
}
int main ( int argc, char *argv[] ) {
	//freopen("destinationWord.cppin","r",stdin);
	Tiger tiger;
	Animal *animal = &tiger;
	animal->render();
	return EXIT_SUCCESS;
}				/* ----------  end of function main  ---------- */
TEST( VirtualInheritance, test )
{
    Animal *p = new Pegasus( );
    p->trot( );
    p->fly( );
    delete p;
}
Beispiel #5
0
int main(int argc, char const *argv[])
{
	Animal* cat = new Cat("Kitty");
	cat->shout();
	MachineCat* machineCat = new MachineCat("Little Bell",10);
	machineCat->ChangeThing("Anywhere Door");
	return 0;
}
Beispiel #6
0
// Compare two Animals for equality; used in Recipe 14.9
// (for completeness, you should also define operator!=)
inline bool operator==(const Animal& lhs, const Animal& rhs)
{
    return lhs.name( ) == rhs.name( ) && 
           lhs.species( ) == rhs.species( ) && 
           lhs.dateOfBirth( ) == rhs.dateOfBirth( ) && 
           lhs.veterinarian( ) == rhs.veterinarian( ) && 
           lhs.trainer( ) == rhs.trainer( );
}
Beispiel #7
0
int main(void)
{
    Cat b;
    Animal *a = &b;
    a->eat();

    return 0;
}
Beispiel #8
0
Animal* combattre(Animal* animal1, Animal* animal2, bool verbose){
    Animal* vainqueur;

    string attaque1 = animal1->attaquer();
    string attaque2 = animal2->attaquer();

    if (verbose) {
        cout << endl << animal1->nom() << " avec "<< attaque1 << " contre " << animal2->nom()<<" avec "<< attaque2 << endl;
    }

    if (attaque1=="FEUILLE"){
        if (attaque2=="PIERRE") {
            vainqueur = animal1;
            delete animal2;
        }
        else if (attaque2=="FEUILLE") {
            vainqueur = ( rand()%2 ? animal1 : animal2 );
            ( vainqueur == animal1 ? delete animal2 : delete animal1 );
        }
        else if (attaque2=="CISEAU"){
            delete animal1;
            vainqueur = animal2;
        }
    }
    else if (attaque1=="PIERRE"){
        if (attaque2=="PIERRE") {
            vainqueur = ( rand()%2 ? animal1 : animal2 );
            ( vainqueur == animal1 ? delete animal2 : delete animal1 );
        }
        else if (attaque2=="FEUILLE") {
            delete animal1;
            vainqueur = animal2;
        }
        else if (attaque2=="CISEAU"){
            delete animal2;
            vainqueur = animal1;
        }
    }
    else if (attaque1=="CISEAU"){
        if (attaque2=="PIERRE") {
            delete animal1;
            vainqueur = animal2;
        }
        else if (attaque2=="FEUILLE") {
            delete animal2;
            vainqueur = animal1;
        }
        else if (attaque2=="CISEAU"){
            vainqueur = ( rand()%2 ? animal1 : animal2 );
            ( vainqueur == animal1 ? delete animal2 : delete animal1 );
        }
    }

    if (verbose) {
        cout << "  Vainqueur round: "<< vainqueur->nom() << endl;
    }
    return vainqueur;
}
 int main()
 {
	 {
     Animal *pCat = new Cat;
     pCat->Speak();
	 }
	//delete pCat;
     return 0;
 }
Beispiel #10
0
int main()
{
	Lion x;
	Animal *y;
	y = &x;
	y->setTail(4);
	cout << y->getTail() << endl;
	return 0;
}
Beispiel #11
0
void Lista:: Guardar()
{
    for(Animal * temp = inicio; temp!=NULL; temp = temp->sig)
    {
        temp->guardarDatos();

    }

}
Beispiel #12
0
int main(void)
{
	Animal zh;	
	Dog dg;
	zh.sleep1();
	dg.sleep();
//	dg.sleep1(); 				//////不可直接访问。
	return 0;
}
Beispiel #13
0
int main(void)
{
    Animal an;
    Person p;
    an.eat();
    p.eat();
    
    return 0;
}
Beispiel #14
0
int main(int argc, char* argv[]) {
  // Initialize and parse command line values
  // before any code that uses pvals is called:
  pvals.parse(argc, argv, usage);
  pvals.print();
  Animal a;
  cout << "Animal a values:" << endl;
  a.print();
} ///:~
Beispiel #15
0
int main(int argc, char **argv) {
	cout << "Hello Class!" << endl;
	Animal *fred = new Animal();
	Animal bob("Bob","Yellow","Caf");
	
	fred->description();
	bob.description();
	
	delete fred;
}
int main() {
	Animal a;
	cout << sizeof(a) << endl;
	
	Dog d;
	cout << sizeof(d) << endl;

	Animal* p = &d;
	p->foo();			// *p[0](p) 라는 기계어 코드 생성.
}
int main(){
   Animal A = "Buffy";
 //  Animal A("Buffy");
   int i(5);
   A.act();
  A.move();
  A.sound();
  cout << "------------End of main" << endl;
  return 0;
}
Beispiel #18
0
int main()
{
    Fish* fish = Fish_new();    // 创建鱼对象
    Dog* dog = Dog_new();       // 创建狗对象
    Car* car = Car_new();       // 创建车子对象

    Animal* animals[2] = { 0 };     // 初始化动物容器(这里是Animal指针数组)
    IMoveable* moveObjs[3] = { 0 }; // 初始化可移动物体容器(这里是IMoveable指针数组)

    int i = 0;                  // i和j是循环变量
    int j = 0;

    // 初始化鱼对象的昵称为:小鲤鱼,年龄为:1岁
    fish->init(fish, "Small carp", 1);

    // 将fish指针转型为Animal类型指针,并赋值给animals数组的第一个成员
    animals[0] = SUPER_PTR(fish, Animal);

    // 初始化狗对象的昵称为:牧羊犬,年龄为:2岁
    dog->init(dog, "sheepdog", 2);

    // 将dog指针转型为Animal类型指针,并赋值给animals数组的第二个成员
    animals[1] = SUPER_PTR(dog, Animal);

    // 将fish指针转型为IMoveable接口类型指针,并赋值给moveOjbs数组的第一个成员
    moveObjs[0] = SUPER_PTR(fish, IMoveable);

    // 将dog指针转型为IMoveable接口类型指针,并赋值给moveOjbs数组的第二个成员
    moveObjs[1] = SUPER_PTR(dog, IMoveable);

    // 将car指针转型为IMoveable接口类型指针,并赋值给moveOjbs数组的第三个成员
    moveObjs[2] = SUPER_PTR(car, IMoveable);

    // 循环打印动物容器内的动物信息
    for(i=0; i<2; i++)
    {
        Animal* animal = animals[i];
        animal->eat(animal);
        animal->breathe(animal);
        animal->sayHello(animal);
    }

    // 循环打印可移动物体容器内的可移动物体移动方式的信息
    for(j=0; j<3; j++)
    {
        IMoveable* moveObj = moveObjs[j];
        moveObj->move(moveObj);
    }

    lw_oopc_delete(fish);
    lw_oopc_delete(dog);
    lw_oopc_delete(car);

    return 0;
}
// http://d.pr/n/16sMV
int main()
{
	Animal a; Dog d;
	cout << sizeof(a) << endl;
	cout << sizeof(d) << endl;


	Animal* p = &d;
	p->cry();       // 이 순간의 정확한 원리를 생각해 봅시다.
	// (*p)[0](p);
}
Beispiel #20
0
int main(void) {

//    Animal *a = new terrier("pepper");
    Animal tt("xxx");
    Animal *a;
    //a = &tt;
    a = createDog();
    Animal *b = new cat("tesla");
    a->shout();
    return 0;
}
Beispiel #21
0
int main()
{
	Animal *p = new Bird;
	Animal *p1 = new Dog;
	p->name();
	p->does();
	p1->name();
	p1->does();

	system("pause");
}
Beispiel #22
0
 void enqueue(Animal ani){
    order++;
   ani.setOrder(order);
   if (ani.getType()=="Cat"){
     cats.push_back(*(Cat*) &ani);
   }
   if (ani.getType()=="Dog"){   
     dogs.push_back(*(Dog*) &ani);
   }
   cout << "Enqueue: " << ani.getName() << " on time: " << ani.getOrder() << endl;
 }
Beispiel #23
0
int main () {
	cout << "Hello World" << endl;

	Animal a;
	a.speak();

    Cat cat;
    cat.speak();
    cat.jump();
	return 0;
}
Beispiel #24
0
int main(int argc, const char * argv[])
{
    //Animal a;//抽象类不能实例化
    
    Dog d;
    d.show();
    
    //抽象类虽然不能实例化,但可以用指针指向子类的对象
    Animal* a = new Dog();
    a->show();
}
int main(){
  Cat C("TOM");
  Animal* ap = new Cat("Fluffy");
  cout << "------------Using Animal pointer: " << endl;
  ap->act();
  ap->move();
  ap->sound();
  cout << "------------End of main" << endl;
  delete ap;
  act(C);
  return 0;
}
int main()
{
    Dog* d = new Dog();
    Animal* a = d;       // refer to Dog instance with Animal pointer

    using namespace std;

    cout << d->Says();   // always Woof
    cout << a->Says();   // Woof or ?, depends on virtual

    return 0;
}
Beispiel #27
0
Animal* Animal::CreateWithSpeceis(std::string specesName, float size)
{
    Animal* animal = new(std::nothrow) Animal();
    Species* species = new Species(specesName);
    if (animal && animal->initWithSpeceis(species, size))
    {
        animal->autorelease();
        return animal;
    }

    CC_SAFE_DELETE(animal);
    return nullptr;
}
Beispiel #28
0
int main (){
    Animal *animal = new Animal;
    Cat *cat = new Cat;
    
    animal->eat(); // outputs: "I'm eating generic food."
    cat->eat();    // outputs: "I'm eating a rat."
    
    cout << endl;
    
    func(animal); // outputs: "I'm eating generic food."
    func(cat);    // outputs: 
    
}
Beispiel #29
0
Animal* Animal::CreateWithSpeceis(Species* species)
{
    Animal* animal = new(std::nothrow) Animal();
    float mm = species->getRandomHeight().getMmLength();
    if (animal && animal->initWithSpeceis(species, mm))
    {
        animal->autorelease();
        return animal;
    }

    CC_SAFE_DELETE(animal);
    return nullptr;
}
int main(){

	Animal a;	
	a.move();
	a.climb();
	return 0;
}