Before starting, review the subversion submission instructions, and ensure you have access to subversion. If you encounter any issues, please alert your lab TA.
Part 1: You will create a program that performs text justification by formatting a string so that each line contains exactly 90 characters. You will first add spaces after punctuation marks, and if necessary, randomly insert additional spaces between words to reach the required line length.
Part 2: You will also implement a basic file I/O component. Your program should read the input string from a file and write the justified text to an output file. The input and output file paths should be specified by the user. Use the following files as examples.
justified example Note that this is not justified to 90 but 75 characters
change the text from normal english to pig latin. Where each word is altered, usually by adding a fabricated suffix or by moving the onset or initial consonant or consonant cluster of a word to the end of the word and adding a vocalic syllable (usually -ay or /e/) to create such a suffix.For example, Wikipedia would become Ikipediaway (taking the 'W' and 'ay' to create a suffix).
Lab7_LineJustify.Part 1 Example:
Input string: Contrary to popular belief, Lorem Ipsum is not simply random text. Output string: Contrary to popular belief, Lorem Ipsum is not simply random text.
Part 2 Example:
Input file: unjustified.txt Output file: justified.txt
Use the getline() function to read the user's input. For reference, see
this example on how to use getline(). You can locate spaces and punctuation characters
using the find() function, as shown in
this code. Additionally,
this example demonstrates how to find multiple occurrences of the same symbol.
To modify strings, see this example.
To randomly insert spaces, consider the following approach:
while the string is not 90 characters:
randomly pick a position between 0 and the size of the string
locate the first whitespace following this position
(make sure it is not the end of the string)
insert a space there
Use srand() and rand() to generate random numbers. Here is an example:
#include <ctime>
#include <iostream>
using namespace std;
int main() {
srand(time(nullptr));
// Generate random numbers
for (int i = 0; i < 10; i++) {
cout << rand() << endl;
}
// Random numbers between 0-9
for (int i = 0; i < 10; i++) {
cout << rand() % 10 << endl;
}
// Random numbers between 1-10
for (int i = 0; i < 10; i++) {
cout << (rand() % 10) + 1 << endl;
}
}
For the first part of the assignment, focus on inserting spaces after punctuation marks.
Ensure your program adheres to proper programming style. Submit your projects to the subversion repository, and don’t forget to verify your submission on the web.