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.
There are two main algorithms at work here: calculating match_positions, and printing
the mesostic with the right number of leading spaces on each line to get the letters of the vertical word to line up correctly.
These algorithms are not complicated, and you should try to figure them out on your own first. However, I will
be providing additional ideas later if you get stuck.
And here are the additional ideas.
Program details and algorithms
You should use a struct in your program to hold the mesostic. The declaration of the struct should be the following:
The struct contains the following information about a mesostic:
struct mesostic
{
string vert_word;
vector<string> poem_lines;
vector<int> match_positions;
};
Let us illustrate these pieces with a short example. Say your input file contains the four lines:
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 numbers in the match_positions vector.
After your program calculates this information, it should be able to print the poem as:
cat
this cuddly
animal
bites me
Notice how the word "cat" is found vertically in the output.
this cuddly
animal
bites me
How the program should work
The user should be asked to type in the name of a text file that contains a mesostic. The user will not
type in the vertical word and the lines of the poem manually; that information will be read from the text file.
Your program should then calculate the pertinent information and display the mesostic arranged
so the vertical word can be seen in the lines. Obviously, some of the lines of the poem will need to
be moved to the right on the screen; this can be done by printing a certain number of blank spaces before each line of the poem.
The mesostic
should always be left-justified; that is, there should be at least one line of the poem that is printed without
any leading spaces. This line is not necessarily the first line of the poem.
Coding style
Testing your program
You should test your program thoroughly to make sure it works correctly. Here are some sample mesostic files to try:
meso0.txt
meso1.txt
meso2.txt
meso3.txt
meso4.txt
Sample input and output
The program's output is in normal text; what the user types is in bold. Each test
of the program is shown separately; the SAMPLE RUN parts are not part of the output.
-----------------------------------------------------
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.
Hints
What to turn in
Through Moodle, turn in your code as a file called mesostic_yourLastName_yourFirstName.cpp.
You do not need to turn in anything other than the .cpp file; I do not need all the other
files that Visual Studio creates.
Challenge Problem
Print the mesostic using uppercase letters for the vertical word to make it easier
to find quickly. For example, the output
for meso4.txt would change to
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 static_cast the return
value of toupper to a char to get it to print correctly.