/* Programmer: Jennifer Leopold Date: November 1, 2015
File: hw8_functs.h
Purpose: Function prototypes used for encrypting a text
file.
*/
#ifndef HW8_FUNCTS_H
#define HW8_FUNCTS_H
#include <iostream>
#include <fstream>
#include <cmath>
#include <string.h>
#include <cstdlib>
#include <cctype>
using namespace std;
// ******************************************************
// Constants
const short
NUM_CHARS_TO_IGNORE_UNTIL_NEWLINE = 500; // for getline.ignore
const char PERIOD = '.'; // denotes end of
// a sentence
const char SPACE = ' '; // delimits words
const short MAX_WORD_LENGTH = 25; // max length of
// a word
const short MAX_WORDS = 100; // max # words in
// a sentence
const short NUM_HOMERISMS = 8;
const char HOMERISMS[NUM_HOMERISMS][MAX_WORD_LENGTH] =
{"shut up Flanders", "D'OH!", "woo hoo!",
"why, you little...", "mmmmmm, doughnutttt",
"stupid Flanders", "BART!", "borrrring"};
const short NUM_VOWELS = 3;
const char VOWELS[NUM_VOWELS] = {'a','i','o'}; // vowels
const short PERCENT_CHANCE_APPEND_PHRASE_AT_END = 50;
// Certain % of time
// append phrase to
// end of sentence;
// otherwise, insert
// a phrase at
// beginning
const char BEGINNING_PHRASE[MAX_WORD_LENGTH] =
"I mean";
const char ENDING_PHRASE[MAX_WORD_LENGTH] =
", n'stuff";
const char OUTPUT_FILENAME[] = "homerfried.dat";
const bool DEBUGGING = false; // extra output to screen
// when true
// ******************************************************
// Type declarations
struct SentenceInfo
{
char words[MAX_WORDS][MAX_WORD_LENGTH];
int numWords;
};
// ******************************************************
// Function prototypes
// Determine whether a specified character is a vowel.
// Preconditions: Parameter 'ch' is an ASCII character.
// Postconditions: Returns true if parameter 'ch' is in
// VOWELS; otherwise, returns false.
bool isVowel(const char ch);
// Determine whether a specified word ends in a particular
// alphanumeric character. Note: If the word has a punctuation
// character on the end, that character preceding that will
// be checked for the particular alphanumeric character.
// Preconditions: Parameter 'ch' is an alphanumeric char
// and parameter 'word' is a ntca. If 'word' contains
// a punctuation char at the very end, then the length of the
// word must be >= 2 (i.e., there is at least one other char
// in the word besides the punctuation char that is at the
// very end).
// Postconditions: Returns true if parameter 'word' ends in
// parameter 'ch'; otherwise, returns false.
bool wordEndsInChar(const char word[], const char ch);
// Create a string that is the reverse of a specified string.
// Preconditions: Parameter 'c2' is ntca.
// Postconditions: Parameter 'c1' is a ntca containing the
// characters of parameter 'c2' in reverse order.
void strReverse(char c1[], const char c2[]);
// Transform a word according to the rules listed below in
// the postconditions.
// Preconditions: Parameter 'word' is a ntca.
// Postconditions: Parameter 'word' has been modified
// as follows:
// (1) if the word ends in 'y' or 'u', it has been changed
// to "",
// (2) if the word ends in a character in VOWELS, "st" has
// been appended to the word,
// (3) if the word is "the", it has been changed to "da", and
// (4) wherever the word contains "ion", that has been changed
// to "or".
void transformWord(char word[]);
// Read a sentence from the specified input stream.
// Preconditions: Parameter 'fin' is an open input stream
// (or cin).
// Postconditions: Parameter 's' contains an array of words
// (and the number of words) read from updated input stream
// parameter 'fin'.
void getSentence(SentenceInfo &s, istream &fin);
// Insert a specified word into a sentence at a designated
// position.
// Preconditions: Parameter 's' is a struct representing a
// sentence with number of words >= 0, parameter 'position'
// is >= 0 and <= number of words in the sentence 's', and
// parameter 'word' is a ntca.
// Postconditions: Each word that was in s.words[i],
// i = position..numWords-1, is now in s.words[i+1].
// s.word[position] contains the specified 'word', and
// s.numWords has been incremented by 1.
void insertWord(SentenceInfo &s, const int position,
const char word[]);
// Transform the words in a sentence as specified by the rules
// listed below.
// Preconditions: Parameter 's' is a struct representing a
// sentence with number of words >= 0.
// Postconditions: The words in parameter 's' have been modified
// as follows:
// (1) the operations of transformWord() have been performed on
// every word,
// (2) the characters in every other word have been reversed,
// (3) a Homerisms has been inserted at a random position, and
// (4) a phrase has been inserted at the beginning or at the
// end of the sentence.
// Because of these modifications, the number of words in 's'
// has increased.
void transformSentence(SentenceInfo &s);
// Allow user to input the name of a file or specify
// that input will be from the keyboard. In the case of the
// former, open that file.
// Preconditions: None.
// Postconditions: Parameter 'fin' contains an ifstream
// associated with an input data file (if user does not want
// to input from keyboard). Parameter 'inputFromKeyboard'
// is true if user has chosen to input data from keyboard;
// otherwise, it is false.
void openInputFile(ifstream &fin, bool &inputFromKeyboard);
// Definition of the insertion operator for sentence
// information.
// Preconditions: Parameter 'out' is associated with an
// open output stream and parameter 's' has number of words
// >= 0.
// Postconditions: Parameter 'out' has been modified to contain
// formatted data about all words in sentence 's'.
ostream& operator << (ostream &out, const SentenceInfo &s);
#endif