/*
Programmer: Jennifer Leopold
Date: October 31, 2016
File: hw8_functs.cpp
Purpose: This file contains the prototypes of the functions
for the program that generates answers for candidates
during a debate.
*/
#ifndef H8_H
#define H8_H
#include <iostream>
#include <cctype>
#include <fstream>
#include <cstdlib>
#include <ctime>
#include <string.h>
#include <stdlib.h>
using namespace std;
// ***********************************************************
// Constants
// If true, output info about how candidate's answer is formed
const bool DEBUG = false;
// # of candidates in the debate
const int NUM_CANDIDATES = 2;
// # of questions that will be asked, alternated between
// candidates
const int NUM_QUESTIONS = 4;
// Max length for various cstrings declared in the program
const int PARTIAL_ANSWER_LENGTH = 250;
const int ANSWER_LENGTH = 1000;
const int MAX_QUESTION_LENGTH= 1000;
// When generating answer to question, percent chance of
// adding various constructs
const int CHANCE_OF_APPENDING_PREFIX = 50;
const int CHANCE_OF_INSERTING_INTERJECTION = 25;
const int CHANCE_FOR_PERIOD = 60;
const int CHANCE_FOR_NONPERIOD = 50;
// When scoring an answer, percent chance of increasing the
// value of particular letters or words
const int DOUBLE_LETTER_CHANCE = 2;
const int TRIPLE_LETTER_CHANCE = 3;
const int DOUBLE_LETTER_MULTIPLIER = 2;
const int TRIPLE_LETTER_MULTIPLIER = 3;
const int DOUBLE_WORD_CHANCE = 5;
const int TRIPLE_WORD_CHANCE = 2;
const int DOUBLE_WORD_MULTIPLIER = 2;
const int TRIPLE_WORD_MULTIPLIER = 3;
// Maximum length of a file name (when specified as cstring)
const short MAX_LENGTH_FILENAME = 20;
// Names of files that contain possible answers to questions
const string SENTENCE_FILENAMES[NUM_CANDIDATES]
= {"candidate1_sentences.dat", "candidate2_sentences.dat"};
// Names of files that contain possible interjections to insert
// into candidates' answers
const string INTERJECTION_FILENAMES[NUM_CANDIDATES]
= {"candidate1_interjections.dat",
"candidate2_interjections.dat"};
// Names of files that contain possible remarks to append at
// the beginning of candidates' answers
const string PREFIX_FILENAME = "prefix_expressions.dat";
// Min and max # sentences in a candidate's answer
const int MIN_NUM_SENTENCES = 2;
const int MAX_NUM_SENTENCES = 4;
// ***********************************************************
// Function prototypes
// Construct a candidate's answer to a question.
// Preconditions: candidateNum should be 0..NUM_CANDIDATES-1
// (Note: candidateNum should be 0 for "candidate 1" and
// candidateNum should be 1 for "candidate 2").
// Postconditions: answer is now a null-terminated char array
// containing a randomly constructly answer, in part made up
// of passages from the sentences and interjections from
// the specified candidateNum's files.
void constructAnswer(char answer[ANSWER_LENGTH],
const int candidateNum);
// Randomly select a "prefix" remark that subsequently can be
// appended to a candidate's answer.
// Preconditions: File named PREFIX_FILENAME should exist.
// Postconditions: prefix is now a null-terminated char array
// containing a remark randomly selected from file named
// PREFIX_FILENAME.
void getPrefixFromFile(char prefix[PARTIAL_ANSWER_LENGTH]);
// Randomly select a line (i.e., "sentence") from a file.
// Preconditions: candidateNum should be 0..NUM_CANDIDATES-1,
// and file named SENTENCE_FILENAMES[candidateNum] should exist.
// Postconditions: sentence is now a null-terminated char array
// containing a line randomly selected from file named
// SENTENCE_FILENAMES[candidateNum].
void getSentenceFromFile(char sentence[PARTIAL_ANSWER_LENGTH],
const int candidateNum);
// Randomly select a line (i.e., "interjection") from a file.
// Preconditions: candidateNum should be 0..NUM_CANDIDATES-1,
// and file named INTERJECTION_FILENAMES[candidateNum] should
// exist.
// Postconditions: interjection is now a null-terminated char
// array containing a line randomly selected from file named
// INTERJECTION_FILENAMES[candidateNum].
void getInterjectionFromFile
(char interjection[PARTIAL_ANSWER_LENGTH],
const int candidateNum);
// Randomly generate a punctuation char for ending a sentence.
// Preconditions: None.
// Postconditions: A period, question mark, or exclamation mark
// is returned.
char chooseEndingPunctuationChar();
// Treat the specified sentence as numPortions many equal
// portions (based on whitespace chars), and extract the
// desiredPortion.
// Preconditions: sentence should be a null-terminated char
// array, numPortions should be >= 1, desiredPortion should be
// >= 1 and <= numPortions.
// Postconditions: extractedPortion is now a null-terminated char
// array containing the desiredPortion of sentence as determined
// by treating sentence as numPortion many equal portions.
void extractPortionFromSentence
(char sentence[PARTIAL_ANSWER_LENGTH],
const int numPortions, const int desiredPortion,
char extractedPortion[PARTIAL_ANSWER_LENGTH]);
// Generate a random number within a specified range.
// Preconditions: Parameter low is <= parameter high.
// Postconditions: A value >= low and <= high is returned.
int myRand(const int low, const int high);
// Determine the score that should be associated with an
// alphabetic character.
// Preconditions: ch should be an alphabetic character
// (i.e., 'a'..'z', 'A'..'Z').
// Postconditions: A score for ch is returned.
int scoreAlphaChar(const char ch);
// Determine the score that should be associated with an
// answer.
// Preconditions: answer is a null-terminated char array.
// Postconditions: A score for answer is returned, possibly
// (randomly) having multiplied the value for individual chars
// and/or words when determing the total score.
int scoreAnswer(const char answer[ANSWER_LENGTH]);
// Display the results of the debate.
// Preconditions: scores[0..NUM_CANDIDATES-1] should contain
// the total scores for the respective candidates' answers.
// Postconditions: A message has been displayed on the screen
// showing each candidate's total score, and the winner of the
// debate (i.e., the candidate with the lowest total score).
void outputResults(const int scores[NUM_CANDIDATES]);
#endif