Explore BrainMass
Share

Explore BrainMass

    Struct Villian and copyVillian function

    This content was COPIED from BrainMass.com - View the original, and get the already-completed solution here!

    Suppose I have declared the following struct:

    struct Villian {
    int wit;
    int stealth;
    int slainCount;
    int slainCap;
    string* victimsSlain;
    };

    Also assume the existence of a function copyVillian (as declared below) that takes two Villian params, one called orig and the other called copycat, and makes copycat a deep copy of orig.

    void copyVillian (struct Villian * orig, struct Villian * copycat);

    Please explain and tutor for the below.

    1. Show how you would use the above copyVillian function to create a copy of sharpay called sharpaysMoreEvilTwin.

    2. Now create a new Villian value called badGuy that you declare dynamically. Then, set badGuy's values as follows:
    wit: 31 stealth: 25 slainCap: 4
    slainCount: 2
    victimsSlain[0]: Garko
    victimsSlain[1]: Sparko

    © BrainMass Inc. brainmass.com October 10, 2019, 4:27 am ad1c9bdddf
    https://brainmass.com/computer-science/arrays/struct-villian-copyvillian-function-461404

    Solution Preview

    1.

    // Declare the structure variable sharpaysMoreEvilTwin first.
    struct Villian sharpaysMoreEvilTwin;

    // Assuming that the structure variable sharpay is already declared and
    // properly initialised, here is how we can ...

    Solution Summary

    Detailed comments are provided to help the reader in understanding the code.

    $2.19