Hi,

Ive been given an assignment in college to implement a dog class and to include functionality such as eating,sleeping,barking etc..im not really familiar with writing code to describe living things so just wondering could anyone give me a few suggestions as to how to go about doing this? I know its a strange kinda question but im not looking for code as such, rather suggestions on how to describe the animals behaviour / general design etc.. Any suggestions appreciated

Thanks

Recommended Answers

All 4 Replies

Didn't you teacher tell you exactly what to implement, or did he expect you to design the class by yourself?

Describe the attributes of livig things just like you would the attributes of non-living things. You are human (I assume :) ) and have probably observed many times how dogs behave. It doesn't matter what kind of dog it is they all behave the same way. All (or most) dogs bark, so give the dog class a speak() method and make it bark

class dog
{
public:
   void speak() { cout << "Bark!\n"; }
}

You can do similar with other attributes, such as eat

chass dog
{
public:
   void eat() {cout << "Chomp, chomp!\n";}
};

For your purpose it doesn't matter if it's silly or not as long as you make the class do what dogs normally do.

thanks for reply Ancient Dragon,

we werent given explicit implementations.. It was more the purpose of demonstrating knowledge of various topics in C++ (such as funtion overriding, operator overloading, dynamic binding etc)..i was finding it hard to come up of ways of demonstrating these topics through an animal class and finding it hard.. he said we cud pick our own class instead of the examples he gave us so im trying to think of a better class to implement instead (ps we are not allowed to use bank accounts/cars/college personnel classes either as these are in notes)do you have any suggestions of other classes? as there doesnt seem to be much i can demonstrate through the actions of an animal?! Thanks again

There are lots of exaples all over the net -- for example this one. Google for "c++ polymorph" and you will get more examples.

thanks for that..will have a look :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.