#include<iostream>
#include<cstdlib>
#include<string.h>
using namespace std;
class Mammal
{
private:
float weight;
char name[30];
public:
// CONSTRUCTOR member function
Mammal()
{
weight=0;
strcpy(name,"null");
cout<<"Invoking Mammal default
constructor"<<endl;
}
Mammal(float w, char s[])
{
weight=w;
strcpy(name,s);
}
// DESTRUCTOR member function
~Mammal()
{
cout<<"Invoking Mammal destructor"<<endl;
}
// MUTATOR member functions
void setWeight(float w)
{
weight=w;
}
void setName(char s[])
{
strcpy(name,s);
}
// ACCESSOR member functions
float getWeight()
{
return weight;
}
string getName()
{
return name;
}
// PURE VIRTUAL function
virtual void speak()=0;
};
class Dog:public Mammal
{
public:
// CONSTRUCTOR member function
Dog()
{
cout<<"Invoking Dog default constructor"<<endl;
}
~Dog()
{
cout<<"Invoking Dog destructor"<<endl;
}
Dog(float w, char s[]):Mammal(w,s){}
void speak()
{
cout<<"Woof"<<endl;
}
};
class Cat:public Mammal
{
public:
// CONSTRUCTOR member function
Cat()
{
cout<<"Invoking Cat default constructor"<<endl;
}
~Cat()
{
cout<<"Invoking Cat destructor"<<endl;
}
Cat(float w, char s[]):Mammal(w,s){}
void speak()
{
cout<<"Meow"<<endl;
}
};
class Horse:public Mammal
{
public:
// CONSTRUCTOR member function
Horse()
{
cout<<"Invoking Horse default constructor"<<endl;
}
~Horse()
{
cout<<"Invoking Horse destructor"<<endl;
}
Horse(float w, char s[]):Mammal(w,s){}
void speak()
{
cout<<"I'm Mr. Ed"<<endl;
}
};
class Pig:public Mammal
{
public:
// CONSTRUCTOR member function
Pig()
{
cout<<"Invoking Pig default constructor"<<endl;
}
~Pig()
{
cout<<"Invoking Pig destructor"<<endl;
}
Pig(float w, char s[]):Mammal(w,s){}
void speak()
{
cout<<"Oink"<<endl;
}
};
int main()
{
char name[30];
srand(100);
int weight;
Mammal *m[5];
Dog *d;
Cat *c;
Horse *h;
Pig *p;
int i,j=0;
do{
cout<<"1.Dog"<<endl<<"2.Cat"<<endl<<"3.Horse"<<endl<<"4.Pig"<<endl<<endl;
cout<<"Select any animal from the above"<<endl;
cin>>i;
if(i<1 && i>4) continue;
cout<<"Enter the name for animal"<<endl;
cin>>name;
weight=rand()%151;
switch(i)
{
case 1:
{
d = new Dog(weight,name);
m[j++]=d;
}
break;
case 2:
{
c = new Cat(weight,name);
m[j++]=c;
}
break;
case 3:
{
h = new Horse(weight,name);
m[j++]=h;
}
break;
case 4:
{
p = new Pig(weight,name);
m[j++]=p;
}
break;
}
if(j==5) break;
}while(1);
cout<<endl;
for(i=0; i<5 ; i++)
{
cout<<"Speak of the animal is: ";
m[i]->speak();
cout<<"Name of the animal is:
"<<m[i]->getName();
cout<<endl;
cout<<"Weight of the animal is:
"<<m[i]->getWeight();
cout<<endl;
cout<<endl;
}
/* Deallocation of memory */
delete d;
delete c;
delete h;
delete p;
return 0;
}
C++ Programming Assignment S Mammal Lab This lab's goal is to give you some practice using inheritance, virtual functions, pointers, dynamic memory allocation, random numbers, and polym...
Please help me with the following question. This is for Java programming. In this assignment you are going to demonstrate the uses of inheritance and polymorphism. You will create an Animals class and a Zoo class that holds all the animals. You should create a general Animalclass where all other classes are derived from (except for the Zoo class). You should then create general classes such as Mammal, Reptile, and whatever else you choose based off of the Animalclass. For...
Please help me with the following question. This is for Java programming. In this assignment you are going to demonstrate the uses of inheritance and polymorphism. You will create an Animals class and a Zoo class that holds all the animals. You should create a general Animalclass where all other classes are derived from (except for the Zoo class). You should then create general classes such as Mammal, Reptile, and whatever else you choose based off of the Animalclass. For...
Lab Assignment : In this lab, you are going to implement QueueADT interface that defines a queue. Then you are going to use the queue to store animals. 1. Write a LinkedQueue class that implements the QueueADT.java interface using links. 2. Textbook implementation uses a count variable to keep track of the elements in the queue. Don't use variable count in your implementation (points will be deducted if you use instance variable count). You may use a local integer variable...
Program Purpose In this program you will demonstrate your knowledge in programming OOP concepts, such as classes, encapsulation, and procedural programming concepts such as lınked lists, dynamic memory allocation, pointers, recursion, and debugging Mandatory Instructions Develop a C++ object oriented solution to the Towers of Hanoi puzzle. Your solution will involve designing two classes one to represent individual Disk and another to represent the TowersOfHanoi game. TowersOfHanoi class will implement the game with three linked lists representing disks on each...
Purpose: Demonstrate the ability to create and manipulate classes, data members, and member functions. This assignment also aims at creating a C++ project to handle multiple files (one header file and two .cpp files) at the same time. Remember to follow documentation and variable name guidelines. Create a C++ project to implement a simplified banking system. Your bank is small, so it can have a maximum of 100 accounts. Use an array of pointers to objects for this. However, your...
This C++ Program consists of: operator overloading, as well as experience with managing dynamic memory allocation inside a class. Task One common limitation of programming languages is that the built-in types are limited to smaller finite ranges of storage. For instance, the built-in int type in C++ is 4 bytes in most systems today, allowing for about 4 billion different numbers. The regular int splits this range between positive and negative numbers, but even an unsigned int (assuming 4 bytes)...
Objective In this assignment, you will practice solving a problem using object-oriented programming and specifically, you will use the concept of object aggregation (i.e., has-a relationship between objects). You will implement a Java application, called MovieApplication that could be used in the movie industry. You are asked to implement three classes: Movie, Distributor, and MovieDriver. Each of these classes is described below. Problem Description The Movie class represents a movie and has the following attributes: name (of type String), directorName...
Need some help with this C++ code. Please screenshot the code if possible. Purpose: Demonstrate the ability to create and manipulate classes, data members, and member functions. This assignment also aims at creating a C++ project to handle multiple files (one header file and two .cpp files) at the same time. Remember to follow documentation and variable name guidelines. Create a C++ project to implement a simplified banking system. Your bank is small, so it can have a maximum of...
Overview This assignment will give you experience on the use of classes. Understand the Application Every internet user–perhaps better thought of as an Internet connection–has certain data associated with him/her/it. We will oversimplify this by symbolizing such data with only two fields: a name ("Aristotle") and a globally accessible IP address ("139.12.85.191"). We could enhance these by adding other—sometimes optional, sometimes needed—data (such as a MAC address, port, local IP address, gateway, etc), but we keep things simple and use...
This java assignment will give you practice with classes, methods, and arrays. Part 1: Player Class Write a class named Player that stores a player’s name and the player’s high score. A player is described by: player’s name player’s high score In your class, include: instance data variables two constructors getters and setters include appropriate value checks when applicable a toString method Part 2: PlayersList Class Write a class that manages a list...