+ 1
Define a class Bird which contains following properties of a bird:
Define a class Bird which contains following properties of a bird: color of the feathers, color of the beak, size of the bird(small/medium/large), size of eggs(small,medium,large) and sound made by the bird(sing/tweet/shriek/hoot/click). Define appropriate constructor to initialise the data members. Next, define a function Lifetime() that will determine how long a bird will live (small birds - 3 years, medium - 10 years,big birds -20 years). Write a driver C++ program that instantiates three birds House Sparrow, Bald Eagle and King Vulture. The driver program should be able to tell which bird will survive the longest and also display all the characteristic features of that bird.
10 Respostas
+ 2
This can't work as Lifetime is declared the same way a constructor would. You can't have a constructor with another name as the class' one. You also can't have two constructors defined that can be called with the same parameters, it would be ambiguous
You should add parameters to bird's constructor so that you set attributes' values
Lifetime should return one of the three values you set in it, you should chose one then in it depending on its attributes' values
You should add a return type to your method, it is mandatory apart from some exceptions (such as constructor and destructors, but they are others)
+ 1
Is that an assignment ? Did you tried doing it yourself ? Did you succeed ? Do you need help ?
+ 1
What did you manage to do ? What did you tried ? I can try to help find what you did wrong if you want
+ 1
No sorry, firstly because I do not have enough free time, and secondly because I am not doing videos and do not want to ^^ I can correct the things I said though, and let you finish the program if you want !
+ 1
I would make my constructor take many parameters:
Bird(string name, char size, char eggSize, char songType)
I'm using chars because that seems to be what you want to use. Here is how I'd use it:
Bird houseSparrow("house sparrow", 's', 's', 'h');
But this is probably a style choice. I would also call Lifetime in the constructor:
lifeSpan = Lifetime();
0
This question was asked in my mid semester exam, but I couldn't answer it, I need help.
0
https://code.sololearn.com/cSMEadCJvN97/#cpp
i tried this
0
Could you please make a video tutorial on this program?
0
Welcome to C++