#include #include using namespace std; struct cat { string name, colour; int legs, weight, value; }; void set(cat & c, string n, string co, int l, int w, int v) { c.name = n; c.colour = co; c.legs = l; c.weight = w; c.value = v; } void print(cat c) { cout << c.name << ", " << c.colour << ", " << c.legs << " legs, weight = " << c.weight << ", $" << c.value << "\n"; } struct member { string name, address; cat c1, c2, c3; }; void set(member & m, string n, string a, cat x, cat y, cat z) { m.name = n; m.address = a; m.c1 = x; m.c2 = y; m.c3 = z; } void print(member m) { cout << m.name << " of " << m.address << "\n"; cout << " "; print(m.c1); cout << " "; print(m.c2); cout << " "; print(m.c3); } int fight(cat a, cat b) { if (a.legs == 4 && b.legs != 4) return 1; if (b.legs == 4 && a.legs != 4) return 2; if (a.weight > b.weight) return 1; if (b.weight > a.weight) return 2; if (a.value < b.value) return 1; if (b.value < a.value) return 2; return random() % 2 + 1; } void fight(member & a, member & b) { int awins = 0; if (fight(a.c1, b.c1) == 1) awins += 1; if (fight(a.c2, b.c2) == 1) awins += 1; if (fight(a.c3, b.c3) == 1) awins += 1; if (awins >= 2) b.name = "Mr. Loser"; else a.name = "Mr. Loser"; } // The question did not ask for a main, this is just to show how things would fit together: int main() { cat timmy; set(timmy, "Timmy", "tabby", 4, 7, 500); print(timmy); cat pinky; set(pinky, "Pinky", "pink", 4, 7, 500); cat joe; set(joe, "Joe", "black", 4, 7, 500); member jane; set(jane, "Jane Smith", "123 first St.", timmy, pinky, joe); print(jane); if (fight(timmy, pinky) == 1) cout << "timmy would beat pinky\n"; else cout << "pinky would beat timmy\n"; member fred; ... fight(jane, fred); print(jane); print(fred); }