PA 6.3: Speed reader I
- Due Apr 6, 2021 by 11:59pm
- Points 10
- Submitting a file upload
- File Types cpp
- Available after Mar 23, 2021 at 2pm
When completing this programming assignment, you may work with up to one other person. No groups of more than two are permitted.
One of the things that makes it difficult to read quickly is the movement of our eyes: as we scan a line of text, our eyes dart back and forth. Software can help with this by moving the text so your eyes don't have to, usually by presenting individual words or short phrases in the center of the screen for a split second before moving on to the next word or phrase. This way, the reader can focus on a single point in space, thus limiting the need for their eyes to dart around.
In this programming assignment, you will develop a program that reads in a multi-lined blurb of text from the user using a sentinel (STOP) to indicate when they are finished entering text. The program must also ask for the desired speed (in words per minute). The program will then iterate through the words in the input, printing each to the screen for the number of seconds indicated by the user, then "deleting" the printed characters using the backspace `\b` character so the screen is ready for the next word.
We will need a few extra things for this, including some code that will allow our program to "sleep" between displaying words (this will control the rate) and an example of how to delete program output on the console. Here are two helpful examples:
Define sleep functions (put this at the top of your PA below `using namespace std;`
// Source: https://stackoverflow.com/a/1658429 #ifdef _WIN32 #include <windows.h> void snooze(unsigned milliseconds) { Sleep(milliseconds); } #else #include <unistd.h> void snooze(unsigned milliseconds) { usleep(milliseconds * 1000); // takes microseconds } #endif
Delete console output:
cout << "Hello"; cout.flush(); // Delete the o, l, l, e, and H // by outputting "\b \b" (backspace, space, backspace)
// for each character we originally printed: cout << "\b \b\b \b\b \b\b \b\b \b";
Note that the snooze functions require the number of milliseconds to sleep for. You'll need to convert words per minute (which is what the user provides) to milliseconds per word. There are 1000 milliseconds in a second, and 60 seconds in a minute. For example, 200 words per minute (the average reading speed) is 60/200 = 0.3 seconds per word, which is 1000*60/200 = 300 milliseconds per word.
Here's a program Download Here's a program that demonstrate how to use these two to display the numbers 0–9 over the course of 10 seconds (1 second each).
Here is an example of how the completed program may look:
Here are the specs:
// Name:
// Date:
// Partner:
//
// Specifications checklist for PA 6.3: Speed reader I
//
// General specs:
// [ ] the header includes your name and anyone you worked with
// [ ] the header includes this specifications checklist with all completed
// specifications checked off: [x]
// [ ] the code is indented properly (inside of every block, code is indented
// one more tab)
// [ ] each chunk of code that "hangs together" (works toward a higher level goal):
// [ ] includes a brief, useful comment above it
// [ ] is separated from the next chunk by a blank line
// [ ] there are no really long lines of code or comments (if you have long
// lines, split them across multiple shorter lines)
// [ ] identifiers are well named
// [ ] the program compiles
// [ ] the program runs without crashing or hanging
// [ ] all output and prompts look clean (correct spelling, capitalization,
// nothing squished)
// [ ] all prompts make it clear what data the user is expected to enter and in
// what format and work as expected
//
// Specific specs:
// [ ] a passage of words is read in from the user until the sentinel STOP is reached
// [ ] the sentinel is not included as part of the passage
// [ ] the desired words per minute is read in from the user
// [ ] this is accurately converted to milliseconds per word
// [ ] each word from the text passage is displayed
// [ ] the word is displayed for the correct amount of time
// [ ] the word is then entirely deleted from the screen
// [ ] the next word shows up at the same spot where the previous word was
If you are working with a partner, both of you must submit individually.