+ 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.

3rd Nov 2018, 5:20 AM
Suresh Thiyam
Suresh Thiyam - avatar
10 odpowiedzi
+ 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)
3rd Nov 2018, 1:18 PM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
3rd Nov 2018, 2:24 PM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
+ 1
Is that an assignment ? Did you tried doing it yourself ? Did you succeed ? Do you need help ?
3rd Nov 2018, 7:30 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
+ 1
What did you manage to do ? What did you tried ? I can try to help find what you did wrong if you want
3rd Nov 2018, 9:05 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
+ 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 !
3rd Nov 2018, 2:18 PM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
+ 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();
3rd Nov 2018, 3:28 PM
Zeke Williams
Zeke Williams - avatar
0
This question was asked in my mid semester exam, but I couldn't answer it, I need help.
3rd Nov 2018, 7:39 AM
Suresh Thiyam
Suresh Thiyam - avatar
3rd Nov 2018, 9:29 AM
Suresh Thiyam
Suresh Thiyam - avatar
0
Could you please make a video tutorial on this program?
3rd Nov 2018, 1:23 PM
Suresh Thiyam
Suresh Thiyam - avatar
0
Welcome to C++
15th Mar 2024, 4:49 PM
Prasenjit Datta
Prasenjit Datta - avatar