CS 160 - Programming Concepts and Applications

Summer II 2018 - Lab 7A - Godzilla vs Mechagodzilla

Quick Links: Canvas | John Cabot | Piazza | zyBooks

|   Home |  Contact |  Syllabus |  Assignments |  Schedule |  Resources   |

This lab is due by Friday, August 3, 2018, 11:59 PM.


Concepts



Focus on defining a Godzilla class from scratch.


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.


Godzilla Class



We are going to declare a class called Godzilla that will allow us to simulate a battle between Godzilla & Mechagodzilla. Create a new class called Godzilla that contains data members for storing the name (as a string), the health and power (as doubles) of a Godzilla creature. Also, use a private helper function wherever one makes sense. Functions you should include in your class:
  • A default constructor that sets the name to "Godzilla", the health to a random value between [50, 100], and the power to a random value between [10, 25].
  • A parameterized constructor that allows a user to enter a new Godzilla object specifying the name, health, and power. Ensure that the provided health and power are both greater than zero. If either are not, then reassign it to the random default values.
  • Appropriate getter and setter functions. The power setter should ensure that the power is greater than zero. If not, then reassign it to the random default value.
  • An attack function that accepts another Godzilla object as a parameter. The function should modify the target's health by subtracting the callee's power. It should also print out a message in the form of "Callee's Name attacks Target's Name." If the target's health falls below zero, print out a second message stating "Target's Name has been vanquished."
Now in main, create two Godzilla objects - one named Godzilla and the other named Mechagodzilla. Godzilla should be created using the default constructor and prompt the user to provide the health and power of Mechagodzilla so the parameterized constructor can be used. Then have Godzilla attack Mechagodzilla once. Lastly, have Mechagodzilla attack Godzilla until Godzilla has been vanquished. Your program should end at that point.


Lab Submission



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


This lab is due by Friday, August 3, 2018, 11:59 PM.

Last Updated: 06/13/18 21:51


Valid HTML 4.01 Strict Valid CSS! Level Triple-A conformance, W3C WAI Web Content Accessibility Guidelines 2.0