CSCI 261 - Programming Concepts - Spring 2021

Lab 8B - Classes Part II: Godzilla vs Mechagodzilla

This lab is due by Tuesday, May 04, 2021, 11:59 PM.
As with all labs you may, and are encouraged, to pair program a solution to this lab. If you choose to pair program a solution, be sure that you individually understand how to generate the correct solution.


Concepts


Focus on expanding the Godzilla class from Lab7C.


Suggestion: Use NotePad or WordPad


Consider using NotePad or WordPad on your computer to write your code for this lab. Once you feel good about what you've written, then copy the code into your project. Doing this will help you see where you might make mistakes on the exam!

You should write a main.cpp that tests each feature of your class works as expected. You will need to submit your class declaration file, your class definition file, and your main.cpp file for this lab.


Even More Expanded Godzilla Class


It's now time for godzilla and nechagodzilla to go to battle. Add an attack function as described below:

Now in main, have godzilla attack mechagodzilla once. Then, have mechagodzilla attack godzilla until godzilla has been vanquished. Your program should end at that point.

An example output is below:

Enter the health of Godzilla: 80
Enter the power of Godzilla: 20

Enter the name of the second creature: Metalzilla
Enter the health of the second creature: 95
Enter the power of the second creature: 30

The two creatures are:
Godzilla (P: 20) - H: 80
Metalzilla (P: 30) - H: 95

Godzilla attacks Metalzilla.
Metalzilla attacks Godzilla.
Metalzilla attacks Godzilla.
Metalzilla attacks Godzilla.
Godzilla has been vanquished.

Now add the following function to your class:

Finally, in main before the two Godzillas do battle, have godzilla greet mechagodzilla. As in, the code would look like

godzilla.greet( mechaGodzilla );

In order for this to work, you will need to make sure that you have marked ALL of your functions as const or not appropriately. Which functions should be constant functions? Which parameters should be constant parameters? Do this for every function - denote it as a const function when it is not modifying andy of the callee's data members. Likewise, mark any parameters in every function as const that are not modified within the function body.

An example output is below:

Enter the health of Godzilla: 80
Enter the power of Godzilla: 20

Enter the name of the second creature: Metalzilla
Enter the health of the second creature: 95
Enter the power of the second creature: 30

The two creatures are:
Godzilla (P: 20) - H: 80
Metalzilla (P: 30) - H: 95

Metalzilla bows to Godzilla.
Godzilla bows to Metalzilla.

Godzilla attacks Metalzilla.
Metalzilla attacks Godzilla.
Metalzilla attacks Godzilla.
Metalzilla attacks Godzilla.
Godzilla has been vanquished.

Lab Submission



You will submit your solution to this lab with the rest of Set8. Detailed instructions for doing this are posted in Assignment 8.


This lab is due by Tuesday, May 04, 2021, 11:59 PM.
As with all labs you may, and are encouraged, to pair program a solution to this lab. If you choose to pair program a solution, be sure that you individually understand how to generate the correct solution.