Explore BrainMass
Share

# Struct Villian

This content was STOLEN 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;
};

1. Declare a new Villian called sharpay who has a wit of 24, a stealth of 16, and who has currently claimed three victims: Chad, Troy, and Gabriella. Give sharpay an initial capacity to vanquish 10 victims.

2. Write a function called copyVillian that takes two Villian parameters, one called orig and the other called copycat, and makes copycat a deep copy of orig. Hint: a "deep copy" is one that would allow copy to exist completely separately from orig. In other words, they will not share any memory locations.

https://brainmass.com/computer-science/arrays/function-called-copyvillian-takes-two-villian-parameters-461232

#### Solution Preview

As nothing specifically is mentioned about the sharpay variable declaration and the type of copyVillian function parameters, this solution declares sharpay as an initialized variable and copyVillian function parameters are considered as pointer types.

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

1.

string sharpayVictims[] = {"Chad", "Troy", "Gabriella"};

// Following statement declares a new Villian called sharpay who has a wit of
// 24, a stealth of 16, ...

#### Solution Summary

As nothing specifically is mentioned about the sharpay variable declaration and the type of copyVillian function parameters, this solution declares sharpay as an initialized variable and copyVillian function parameters are considered as pointer types. Detailed comments are provided to help the reader in understanding the code.

\$2.19
Similar Posting

## Struct Villian and copyVillian function

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

View Full Posting Details