hw8_fncts.h

/*

Programmer: Jennifer Leopold

Date: March 23, 2018

File: hw8_functs.cpp

Purpose: This file contains the prototypes of the functions

for the program that plays telephone bingo.

*/

#ifndef H8_H

#define H8_H

#include <iostream>

#include <cctype>

#include <fstream>

#include <cstdlib>

#include <ctime>

#include <string.h>

#include <stdlib.h>

#include <iomanip>

using namespace std;

// ***********************************************************

// Constants and structs

// Max length of the name of a contestant (or Beatrice & BoJack)

const int MAX_NAME_LENGTH = 80;

// Names of the characters in the telephone conversation

const char BEATRICE[MAX_NAME_LENGTH] = "Beatrice";

const char BOJACK[MAX_NAME_LENGTH] = "BoJack";

// Max length of any data file name

const int MAX_LENGTH_FILENAME = 120;

// Delimiter between words in a csv data file

const char COMMA = ',';

// Max chars in a word or sentence

const int MAX_WORD_SIZE = 15;

const int MAX_SENTENCE_SIZE = 256;

// Max # exchanges in telephone conversation before quitting

const int MAX_NUM_EXCHANGES = 20;

// Which diagonal of the Bingo card was matched

const int NONE = 0;

const int UPPERLEFT_TO_LOWERRIGHT = 1;

const int LOWERLEFT_TO_UPPERRIGHT = 2;

// Dimensions (row and column)of the Bingo card, and

// names of the 2 files containing the Bingo card words

const int BINGO_CARD_DIM = 5;

const char BINGO_CARD_FILES[2][MAX_LENGTH_FILENAME] =

{"bingoCard1.dat", "bingoCard2.dat"};

// Names of the files that contain the sayings for the

// characters having the telephone conversation

const char BOJACK_FILE[MAX_LENGTH_FILENAME] =

"BojackSayings.dat";

const char BEATRICE_FILE[MAX_LENGTH_FILENAME] =

"BeatriceSayings.dat";

// Names of the files where the winning Bingo card contents

// will be output

const char WINNING_BINGO_CARD_FILES[2][MAX_LENGTH_FILENAME] =

{"winningBingoCard1.dat", "winningBingoCard2.dat"};

// Matches any word on a Bingo card

const char WILDCARD[MAX_WORD_SIZE] = "*";

// Each entry on a Bingo card will contain a word and

// an indication of whether or not it has been matched

struct BingoCardEntry

{

char word[MAX_WORD_SIZE];

bool matched;

};

// Each Bingo player has a name, a Bingo card, an indication

// of whether or not s/he has won

struct Player

{

char name[MAX_NAME_LENGTH];

BingoCardEntry bingoCard[BINGO_CARD_DIM][BINGO_CARD_DIM];

bool winner;

};

// Association of "bad" words and the "good" words we will

// substiture for them

struct Sanitization

{

char badWord[MAX_WORD_SIZE];

char goodWord[MAX_WORD_SIZE];

};

const int NUM_SUBSTITUTIONS = 5;

const Sanitization SUBSTITUTIONS[NUM_SUBSTITUTIONS] =

{{"bitch", "mean person"}, {"dammit", "darn it"},

{"shit", "poop"}, {"crap", "poopie"},

{"damn", "hoot"}};

// Name of the file containing prizes

const char PRIZE_FILE[MAX_LENGTH_FILENAME] = "WinnersPrize.dat";

const int MAX_PRIZE_DESCRIPTION_LENGTH = 100;

// ***********************************************************

// Function prototypes

// Display 'hello' messages from BoJack and Beatrice.

// Preconditions: None

// Postconditions: Messages have been output to the screen.

void sayHello();

// Display 'goodbye' messages from BoJack and Beatrice.

// Preconditions: None

// Postconditions: Messages have been output to the screen.

void sayGoodbye();

// Get names and bingo cards for 2 contestants.

// Preconditions: None

// Postconditions: players[0..1] contain

// (null-terminated char array) names and bingo cards,

// respectively.

void initializePlayers(Player players[]);

// Read in data for one Bingo card.

// Preconditions: The file named fileName should exist and

// contain data.

// Postconditions: Bingo card b contains words and its

// 'matched' entries have been set to false unless

// the word is the WILDCARD (in which case it has been

// set to true).

void readInBingoCard(BingoCardEntry b[][BINGO_CARD_DIM],

const char fileName[]);

// Randomly select a line (i.e., "sentence") from a file.

// Preconditions: fileName should be the name of an existing

// file.

// Postconditions: message is now a null-terminated char array

// containing a line randomly selected from file named

// fileName.

void getRandomMessage(const char fileName[], char message[]);

// Construct a sentence that has all "bad" words replaced

// with "good" words.

// Preconditions: message should be a null-terminated char array.

// Postconditions: newMessageis a null-terminated char array

// that is has all "bad" words replaced with "good" words.

void sanitizeMessage(const char message[], char newMessage[]);

// If word is considered "bad", translate it to a "good" word.

// Preconditions: word should be a null-terminated char array.

// Postconditions: newWord is a null-terminated char array

// that is either another ("good" alternative) or is the

// same (original) word.

void sanitizeWord(const char word[], char newWord[]);

// Create a copy of a null-terminated char array with all

// lowercase letters.

// Preconditions: word should be a null-terminated char array.

// Postconditions: lcWord is a copy of a null-terminated char

// array word, but with all lowercase letters.

void convertToLowercase(const char word[], char lcWord[]);

// Look for words in a msg that match words on a Bingo card.

// Preconditions: msg should be a null-terminated char array,

// b should be a Bingo card that contains words.

// Postconditions: Bingo card b has been updated to have

// 'matched' set to true for entries with any word occurring

// in msg.

void matchWordsOnBingoCard(BingoCardEntry b[][BINGO_CARD_DIM],

const char msg[]);

// Look for a word on a Bingo card.

// Preconditions: word should be a null-terminated char array,

// b should be a Bingo card that contains words.

// Postconditions: Bingo card b has been updated to have

// 'matched' set to true if the specified word is on the card.

void matchWordOnBingoCard(const char word[],

BingoCardEntry b[][BINGO_CARD_DIM]);

// Check to see if a Bingo card has met winning criteria.

// Preconditions: Bingo card b should contain data.

// Postconditions: Returns true if the Bingo card meets winning

// criteria; otherwise, returns false.

bool checkForBingo(const BingoCardEntry b[][BINGO_CARD_DIM]);

// Check to see if a Bingo card has matches in an entire row.

// Preconditions: Bingo card b should contain data.

// Postconditions: Returns true if the Bingo card has matches in

// an entire row; otherwise, returns false. Pass-by-reference

// parameter winningRow will contain the row number where the

// match occurred (or -1 if there was no match).

bool checkForBingoInRows

(const BingoCardEntry b[][BINGO_CARD_DIM], int &winningRow);

// Check to see if a Bingo card has matches in an entire column.

// Preconditions: Bingo card b should contain data.

// Postconditions: Returns true if the Bingo card has matches in

// an entire column; otherwise, returns false. Pass-by-reference

// parameter winningCol will contain the column number where the

// match occurred (or -1 if there was no match).

bool checkForBingoInColumns

(const BingoCardEntry b[][BINGO_CARD_DIM], int &winningCol);

// Check to see if a Bingo card has matches in a diagonal.

// Preconditions: Bingo card b should contain data.

// Postconditions: Returns true if the Bingo card has matches in

// a diagonal; otherwise, returns false. Pass-by-reference

// parameter winningDiag will contain UPPERLEFT_TO_LOWERRIGHT or

// LOWERLEFT_TO_UPPERRIGHT to indicate which diagonal was

// matched (or NONE if there was no match).

bool checkForBingoInDiagonals

(const BingoCardEntry b[][BINGO_CARD_DIM], int &winningDiag);

// Write the words of a Bingo card to an output stream.

// Preconditions: Bingo card b should contain data,

// fout should be cout or an open file stream,

// checkForWin should be true if []'s are to be output around

// the words in the row, column, or diagonal that resulted in

// the Bingo win (otherwise, checkForWin should be false).

// Postconditions: The file stream has been modified to contain

// the words of the Bingo cards. Words that resulted in the

// Bingo winning conditions have []'s around them.

void outputBingoCard(const BingoCardEntry b[][BINGO_CARD_DIM],

ostream &fout, bool checkForWin = true);

// Output results of the Bingo card in terms of which contestant

// won and the contents of their Bingo card.

// Preconditions: players[0..1] should contain data for names,

// bingoCard, and winner.

// Postconditions: A message about who won the Bingo game will

// be output to the screen. The contents of the winner(s)'

// Bingo card will have been written to a file.

void outputResults(const Player players[]);

// Output a randomly selected prize from the PRIZE_FILE file.

// Preconditions: The file with name PRIZE_FILE should contain

// contain data.

// Postconditions: A message describing a prize has been output

// to the screen.

void outputRandomPrize();

#endif