online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
''' Demonstration file for classes in python 11/16/2021 -Dr. G ''' ''' This is a character class for a simple battle game Attributes: name, hitPoints, strength, alive Methods: print, fight, take_damage, attack ''' ''' Weapon class. Provides an attack value, but decreases durablity each use Attributes: name, strength, durability Methods: attack ''' def main (): print ("Woot") main() ''' Part 1 : Creating a simple object ''' #1. What is OO programing? #How have you already been using objects? #2. Create a class object Character with a name, hitPoints, and strength. #(I've left the class definition above.) #3. Create an instance of a character and set each of the values. #Where does the character class have to be declared? Why? #How do you set default values? #SEPERATE INTO BREAKOUT ROOMS #4. Print the character, print each values, print the type of the character. #Explain the print character output #5. Add a print method. #6. Add a __str__ (self) method that returns what you would want to print and observe #how print changes. #This was part of the module. I hope you watched. #Why is the __str__ method needed? #How do you access invidual elements? #What is "self" and why is it needed? #COME BACK TOGETHER #When you create an object, what's going on in memory? #What's the difference in a class and an object? ''' Part 2 : Constructors/Initializers ''' #In part 1 you were using a class as more of a grouping of objects. This isn't #really what classes are for. Let's dig deeper. #1. Create a constructor/initializer with only a self argument. #2. Create a self + argument constructor/initializer. #3. Create an all argument constructor/initializer (except for alive) #4. Add default values to the constructor/initializer #SEPERATE INTO BREAKOUT ROOMS #5. Create 4 different characters using a variety of the constructor/initializers #6. Create a list of Characters, for fun. How is this useful? #7. Print all of your characters to confirm your results #What is the constructor/initialzer for? #Why did we avoid "alive" in the constructors? #Why could you not create a constructor/initialzer that sets strength, but not hitPoints? #COME BACK TOGETHER ''' Part 2 Part 2 Test what you've got so far ''' #Create a Character test class "class CharacterTest(unittest.TestCase):" #Test what you've done so far #You can swap between having your program run the main function and the test by #swapping out main() and unittest.main() at the bottom of your file ''' Part 3 : Using objects ''' #10. Discuss and then add a take damage method that accepts a damage amount and #reduces hitPoints. #11. Discuss and then add an attack method that accepts a character and then #calls that characters take_damage. #What's going on in memory. #12. Use main to test your understanding of these methods. #13. Create a fight method that sets up an epic battle between self and sent character. #14. Slow the output down to add suspense. #How would you add a test to see if your alive works as intended? #SEPERATE INTO BREAKOUT ROOMS #15. Test this out on some different characters. #16. Seperate out your code into a character file and a driver file.(If you are #using gdb, this is easy enough to do with the new file button.) #What's the advantage of having these classes in different files? #COME BACK TOGETHER ''' Part 4 : The next level (Project starts here)''' #SEPERATE INTO BREAKOUT ROOMS #17. Create a weapon class that has a name, strength, and durability. #18. Give the class an appropriate constructor with default values built in. #19. Give this class an attack method that deducts from durability and returns #an attack value from 1 to strength. #COME BACK TOGETHER #20. Add a weapon to the character class and the ability for a character to #have a weapon. #21. If the user has a weapon, add that attack to the character's attack. #SEPERATE INTO BREAKOUT ROOMS #22. Run and test. #23. Seperate into its own file. #COME BACK TOGETHER

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text



Program is not being debugged. Click "Debug" button to start program in debug mode.