Difficulty with an exercise


Hello guys,

I can't understand what does the question want, to write appropriate code for it. Would you please read it to find out what it exactly wants?

Modify the Link class from 17.10.1 to hold a value of a class God. Class God should have members of type string: name, mythology, vehicle, weapon. For example God("Zeus", "Greek", "", "lightning") and God("Odin","Norse", "Eight-tagged flying horse called Sleipner",""). Write a print_all() function that lists gods with their attributes one per line. Add a member function add_ordered() that places its new element in its current lexicographical position. Using the Links with the values of type God, make a list of god from three lexicographically ordered lists - one per each mythology.

The 17.10.1 is here:
http://books.google.com/books?id=We21AwAAQBAJ&lpg=PP1&dq=programming%20principle%20and%20practice&pg=PA620#v=onepage&q&f=true

Problems are these:
What is "gods"? Of which class is it?
" Add a member function add_ordered() ..." to what class?
What is that meant by "a value of a class God"? An object?

Can you understand the question completely?
Could you please explain it step-by-step for me?:)
Last edited on
hi,

This is only my interpretation, I would recommend get clarification from your teacher.

Modify the Link class from 17.10.1 to hold a value of a class God


So the Link class needs to have a member variable added, which is of type class God.

That implies you have to create your own God class with these as member variables:

Class God should have members of type string: name, mythology, vehicle, weapon.



Write a print_all() function that lists gods with their attributes one per line. Add a member function add_ordered() that places its new element in its current lexicographical position. Using the Links with the values of type God, make a list of god from three lexicographically ordered lists - one per each mythology.


So a Link is one item in a linked list - the goal is to make an actual linked list container object?

This class will have the functions print_all() and add_ordered() . The print_all() function implies that the God class should have it's own PrintDetails() function.

Now make 3 objects of this container class, 1 for each mythology.

Make yet another list object which represents all the gods, use the 3 lists (of each mythology) to populate it.

That last part is a bit confusing, I would naturally have a list of all the gods first, then split that up into the 3 mythology types.

Good Luck !! :+)

Thank you very much. I appreciate you for the answer.
I don't know why the author should embed such a not-complete context as a question.
I don't have a teacher :( I'm self-learning.
Hi,

Well at least your book is on the list of really good books :+) And it is from the inventor of C++.

I am not sure I interpreted the problem correctly - one needs to read the pages in the book carefully (the ones in the link url you posted)

So a Link is one item in a linked list - the goal is to make an actual linked list container object?


A Link is actually a linked list.

There is a non member function called print_all (p621) which traverses from a Link to the next link. The difference is you have to print the details of each god now, not just the name. I would use God::PrintDetails to help with that.

The member function add_ordered() goes into the Link class.

Also there are 3 different lists with the different mythologies. There is still a need to have 1 list of all the gods.

Hope that improved things :+)
Hi,

Thank you very much for your guidance. I appreciate you for it :)
Topic archived. No new replies allowed.