Question: Please fix my Hero.cpp and Hero.h file to fix the data leaks error. There are also Power.cpp, Power.h, and main.cpp, but you can only modify
Please fix my Hero.cpp and Hero.h file to fix the data leaks error.
There are also Power.cpp, Power.h, and main.cpp, but you can only modify Hero module.
My code can output the same thing with Instruction's sample output, but I can't submit it because there are data leaks in my Hero module code.
Please see the error Info to know where you have to fix, and instruction to fix Hero module.
YOU CAN'T MODIFY Power module and main.cpp!!!!!! ONLY Hero module CAN MODIFY!!!!!
Data leaks Info:



-=52404== =52404-= HEAP SUMMARY: =52404== in use at exit: 616 bytes in 4 blocks 52404== total heap usage: 14 allocs, 10 frees, 75, 168 bytes allocated -52404== 52404== 112 bytes in 1 blocks are definitely lost in loss record 1 of 4 =52404== at 0x4C2AC38: operator new (unsigned long) (vg_replace_malloc.c: 43 3) -52404== by 0x400AE1: adds: : Hero: : Hero (char const*, adds: : Power*, int) (Hero cpp : 23) -52404== by 0x40183C: main (main_prof . cpp: 52) =52404== -52404== 112 bytes in 1 blocks are definitely lost in loss record 2 of 4 =52404== at 0x4C2AC38: operator new (unsigned long) (vg_replace_malloc. c: 43 3) ==52404== by 0x400AE1: sdds: : Hero: : Hero (char const*, adds: : Power*, int) (Hero . cpp : 23) =52404== by 0x401BA5: main (main_prof . cpp: 52) 52404== -52404== 168 bytes in 1 blocks are definitely lost in loss record 3 of 4 52404== at 0x4C2AC38: operator new (unsigned long) (vg_replace_malloc. c: 43 3) -52404== by 0x400AE1: sdds : : Hero: : Hero (char const*, adds: : Power*, int) (Hero . cpp : 23) 52404== by 0x401860: main (main_prof . cpp: 52) =52404= -52404-= 224 bytes in 1 blocks are definitely lost in loss record 4 of 4 =52404== at 0x4C2AC38: operator new (unsigned long) (vg_replace_malloc.c: 43 3) ==52404== by 0x400AE1: sdds : : Hero: : Hero (char const*, adds: : Power*, int) (Hero . cpp : 23) -=52404== by 0x401817: main (main_prof . cpp: 52) 52404== -52404== LEAK SUMMARY : =52404- definitely lost: 616 bytes in 4 blocks =52404== indirectly lost: 0 bytes in 0 blocks =52404=- possibly lost: 0 bytes in 0 blocks =52404== still reachable: 0 bytes in 0 blocks =52404== suppressed: 0 bytes in 0 blocks -52404-= -52404-= ERROR SUMMARY: 4 errors from 4 contexts (suppressed: 0 from 0) Script done, file is student_output . txtHero Data Members Declare four private data members: 1. Declare an array to hold the name ofa hero, not exceeding MAX_NAME_LEN characters. 2. Declare a Pointer of type Power that will hold a dynamic set of powers a hero may have. 3. Declare an integer variable for the number of powers a hero may have. 4. Declare a integer variable for the power level ofa hero. This will be a calculated value. Every time you need to calculate/update this variable it will be done as follows: Sum of rarity of all the heroes' powers multiplied by the total count of powers. Store your class denition in a header le named Hem.h and your member function definitions in an implementation le named Hero.cpp . Constructors 0 Default constructor to set a hero to a safe empty state. 0 Overloaded constructor with 3 parameters to set the name, list of powers and the count of powers a hero have. This constructor will also set/update the powerlevel of a hero. Display Function 0 A display function that will send the information about a hero to ostream in the following format and then returns the reference of ostrea m,- Name: WCENDL) List of available powers: powers listed here... powers listed here... powers listed here... powers listed here... Power Level: XXXX
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
