Your program will work by opening and reading the lines of a text file. The first line of the file will contain a single word without spaces. The subsequent lines will contain the lines of a poem; these lines may include spaces. Your program will print out the lines of the poem spaced so that the single word from the beginning of the file can be read vertically in the output.
It is guaranteed that all the files I use to test your program will consist of poems for which mesostics can be found. You should also note that this concept only works in computational form because typical computer programs produce their output in a monospace (a font where each letter, number, or punctuation symbol takes up the same amount of horizontal space), as opposed to a proportional font (a font where the amount of horizontal space used for a character is proportional to the normal amount of horizonal space the character actually would take up).
Examples: This is a monospace font. This is a proportional font.
struct mesostic
{
string vert_word;
vector<string> poem_lines;
vector<int> match_positions;
};
The struct contains the following information about a mesostic:
cat
this cuddly
animal
bites me
When your program reads this file, it would create a mesostic struct with vert_word as "cat" and
poem_lines consisting of the strings "this cuddly", "animal", and "bites me" in a vector.
match_positions would contain a vector of 5, 0, and 2, because the 5th position (counting from zero)
in the string "this cuddly" is 'c', the 0th position in "animal" is 'a', and the 2nd position in
"bites me" is 't'.
Naturally, you will need to write code to calculate the integer values in the match_positions vector.
It is also worth pointing out that poem_lines contains three strings and match_positions contains three integers.
After your program calculates this information, it should be able to print the poem (using cout and some blank spaces) as:
Notice how the word "cat" is found vertically in the output.
this cuddly
animal
bites me
Here are some suggested prototypes:
mesostic read_file(string filename) --- This function will read the file specified by the filename, read the vertical word,
the lines of the poem, calculate the match positions, and return the mesostic struct.
void find_match_positions(mesostic & m) --- This function handles calculating the match positions and updates the mesostic struct; I called this from read_file.
void print_mesostic(const mesostic & m) --- This function prints the mesostic with spaces in the right places on each line to make the vertical word appear.
mesostic meso;
string s;
getline(infile, meso.vert_word); // read the vertical word directly
while (getline(infile, s))
{
meso.poem_lines.push_back(s);
}
Things will get wonky if you try to use while (!infile.eof()) here.
Work out some examples (e.g., from the text files) on graph paper to figure out this algorithm. The graph paper is useful because you can put one character in each square on the paper and easily see how things are supposed to line up. See if you can figure out what the connection is between match_positions and how many leading spaces are added to each line of the poem.
-----------------------------------------------------
SAMPLE RUN 1
-----------------------------------------------------
Mesostic input file: meso0.txt
this cuddly
animal
bites me
-----------------------------------------------------
SAMPLE RUN 2
-----------------------------------------------------
Mesostic input file: meso1.txt
let us make
of this
modest
place
a room holding
tons of love
(&, naturally, much good food, too)
-----------------------------------------------------
SAMPLE RUN 3
-----------------------------------------------------
Mesostic input file: meso2.txt
life is a
companion
treat it with
generosity
sincerity
patience and
love
-----------------------------------------------------
SAMPLE RUN 4
-----------------------------------------------------
Mesostic input file: meso3.txt
music
indeterminacy
words
collaboration
speech
invention
silence
cage
-----------------------------------------------------
SAMPLE RUN 5
-----------------------------------------------------
Mesostic input file: meso4.txt
it's just
great theater. there's
an ordinary guy, balding,
unknown,
leaves sunny stratford
penniless, a few plays
and poems in a bag, ends up on
the globe stage a master,
unrivalled
bard, 100%
literary genius.
mesostic.cpp.
Please do not upload anything other than the .cpp file.
it'S just
great tHeater. there's
An ordinary guy, balding,
unKnown,
lEaves sunny stratford
pennileSs, a few plays
and Poems in a bag, ends up on
thE globe stage a master,
unrivAlled
baRd, 100%
litErary genius.
For historical reasons, the toupper function returns an int, not a char. If you use
toupper to convert from lowercase to uppercase, you will need to cast the return
value of toupper to a char to get it to print correctly.