Homework 3 Spec

Homework 3 Spec - Spring 2009 CS 32 Homework 3 Time due...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Spring 2009 CS 32 Homework 3 Time due: 9:00 PM Sunday, May 3 To coincide with the release of the sixth movie in the series, your company is developing computer games based on the adventures of Hairy Otter, a teen enrolled at the Pigboils Academy of the Magical Arts. Your group is working on a game for younger children. (Since the themes in the later books/movies are too dark for that age group, this game is based on the earlier ones.) Hairy, with his friends Rod Weaselly and Anemone Stranger, will encounter many kinds of magical creatures around the grounds of Pigboils. All creatures have a name. All creatures have a distinctive way of moving (e.g. trotting or flying). Most creatures are mortal, but some are immortal. a Declare and implement the classes named in the sample program below in such a way that the program compiles, executes, and produces the output shown. (The real game will have all sorts of snazzy graphics and audio, but for now we'll stick to simple text output.) Do not change the implementations of animate or main . . #include <iostream> #include <string> using namespace std; Your declarations and implementations would go here void animate(const Creature* c) { cout << c->name() << ", who is "; if (c->mortal()) cout << "mortal"; else cout << "immortal"; cout << ", will now " << c->move() << ".\n"; } int main()
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Creature* creatures[4]; creatures[0] = new Phoenix("Squawkes"); // Giants have a name and a weight in tons. Giants under 20 tons // walk by tromping; giants weighing at least 20 tons lumber. creatures[1] = new Giant("Frawp", 17); creatures[2] = new Giant("Gridwulfa", 22); creatures[3] = new Centaur("Florence"); cout << "Here are the creatures." << endl; for (int k = 0; k < 4; k++) animate(creatures[k]); // Clean up the creatures before exiting cout << "Cleaning up." << endl; for (int k = 0; k < 4; k++) delete creatures[k]; } Output produced: O Here are the creatures. Squawkes, who is immortal, will now fly. Frawp, who is mortal, will now tromp. Gridwulfa, who is mortal, will now lumber. Florence, who is mortal, will now trot. Cleaning up. Destroying Squawkes the phoenix. Destroying Frawp the giant. Destroying Gridwulfa the giant. Destroying Florence the centaur. D Decide which function(s) should be pure virtual, which should be non- pure virtual, and which could be non-virtual. Experiment to see what output is produced if you mistakenly make a function non- virtual when it should be virtual instead. v To force you to explore the issues we want you to, we'll put some constraints on your solution: The Creature class must not have a default constructor. The only constructor you may declare for Creature must have one useful parameter. Although the expression
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 9

Homework 3 Spec - Spring 2009 CS 32 Homework 3 Time due...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online