Cs304 Assignment 1 Solution Nov 2015 Cancer

Problem Statement

In this assignment you will write code about animal hierarchy classes. There should be base class Animal which is abstract class by declaring pure virtual function.

From Animal Class, two classes will be inherited. One is Duck and other is Horse class. Duck and Horse classes are concreteclasses.

Animal Class has the following members:

  • virtual char * GetColor() = 0;            //Pure Virtual Function
  • virtual float calDistanceCovered();

Here, GetColor() function returns color which will be passed while instantiating objects in main function and CalDistanceCoverered() function will calculate distance covered by any animal according to the following formula and return distance.

                     Distance=speed * time;

Speed and time will also be passed as parameter while instantiating objects of classes.

Speed, time and color should be set in constructors of the classes.

Duck class will have the following members:

private:

    char* color;

    float speed, time,distance;

public:

           Duck(char*,float,float );

           virtual float calDistanceCovered();

           char* GetColor();

Horse class will have the following members:

private:

            char *color;

            float speed, time,distance;

  public:

             Horse(char*, float , float)

             float calDistanceCovered();

             virtual char * GetColor();

In main function, create an array of 5 pointers to Animal Class as:

               Animal *obj[5];

Then assign different objects of derived classes as:

obj[0]=new Duck("White",2,2.5);

            obj[1]=new Horse("Red",10,6);

           …….

           …….

Here the first parameter is color, 2nd is speed in Km/h and 3rd is for time in hours.

Now call the function as below by passing array pointer and size;

Фонтейн кивнул. Иерархия допуска в банк данных была тщательно регламентирована; лица с допуском могли войти через Интернет. В зависимости от уровня допуска они попадали в те отсеки банка данных, которые соответствовали сфере их деятельности.

0 Thoughts to “Cs304 Assignment 1 Solution Nov 2015 Cancer

Leave a comment

L'indirizzo email non verrà pubblicato. I campi obbligatori sono contrassegnati *