hw7_fncts.cpp

/* Programmer: Jennifer Leopold

Date: March 8, 2018

File: hw7_functs.cpp

Purpose: Function definitions used in program that simulatea a

main character (BoJack Horseman) randomly encounter-

ing various other characters and collecting cards of

different sizes.

*/

#include <iostream>

#include "hw7_functs.h"

using namespace std;

void greeting()

{

cout << "\nWelcome to Atlantis!\n\n";

return;

}

void signOff()

{

cout << "\nThanks for visiting Atlantis. "

<< "Now go back to Hollywood!\n";

return;

}

int myRand(const int low, const int high)

{

return((rand() % (high - low + 1)) + low);

}

void initCreaturesSeenSoFar(bool creaturesSeenSoFar[],

const int n)

{

for (int i = 0; i < n; i++)

creaturesSeenSoFar[i] = false;

return;

}

void recordDifferentCreaturesSeen(const int whichCreature,

bool creaturesSeenSoFar[],

const int n,

int &numCreaturesSeenSoFar)

{

creaturesSeenSoFar[whichCreature] = true;

numCreaturesSeenSoFar = 0;

for (int i = 0; i < n; i++)

if (creaturesSeenSoFar[i]) numCreaturesSeenSoFar++;

return;

}

void randomlyOutputCreatureGreeting(const int whichCreature)

{

cout << CREATURES[whichCreature].name << " says: "

<< CREATURE_SAYINGS[myRand(0, NUM_CREATURE_SAYINGS-1)]

<< endl;

return;

}

void addCreatureCardToCollection(const int whichCreature,

Creature cards[],

int &numCards)

{

if (numCards < MAX_NUM_CARDS_TO_COLLECT)

{

cards[numCards] = CREATURES[whichCreature];

numCards++;

}

return;

}

int numCardsStackable(Creature cards[], const int numCards)

{

int count = 1;

Creature previous;

previous = cards[0];

for (int i = 1; i < numCards; i++)

{

// Don't count (i.e., stack) cards that are same size

// or put a bigger card "on top of" a smaller card

if ((! (previous == cards[i])) && (previous <= cards[i]))

{

count++;

previous = cards[i];

}

}

return(count);

}

void printStackableCards(const Creature cards[],

const int numCards,

const int desiredStackSize)

{

int i, count = 1;

Creature previous;

cout << "\nOK, you've gotten enough stackable cards, "

<< "namely (stacking top to bottom):\n";

previous = cards[0];

cout << cards[0].card.length << " x "

<< cards[0].card.width

<< " (from " << cards[0].name << ")\n";

i = 1;

while ((i < numCards) && (count < desiredStackSize))

{

// Don't count (i.e., stack) cards that are same size

// or put a bigger card "on top of" a smaller card

if ((! (previous == cards[i])) && (previous <= cards[i]))

{

count++;

previous = cards[i];

cout << cards[i].card.length << " x "

<< cards[i].card.width

<< " (from " << cards[i].name << ")\n";

}

i++;

}

return;

}