October 7th, 2009, 9:30p.m.
In this project, you will create a typing tutor program. This simple typing tutor program basically displays a sentence on the screen and then waits for the user to type what is displayed. When the user has finished typing, the program displays the number of errors made by the user.
Download the list of practice text from the following link. Save the file to your working directory.
text.h
Take a look at the contents of the above file. There are three variables--TEXTCOUNT, TEXTLENGTH and text. The value of TEXTCOUNT gives the number of sentences in array text. The variable text is a pointer to an array of strings containing the sentences.
To use this file, include it in your .c file by putting #include "text.h" at the top of your .c file.
Write a program that displays sentences on the screen and prompts the user to enter the exact text displayed. Follow the steps below to complete this project.
First, print a welcome message and the instruction.
CS240 Project 2: Typing Tutor
-----------------------------
Instruction: Please type each sentence as displayed, or QUIT to exit.
Second, display a sentence from the array of sentences text, starting from the first sentence. For example, the first sentence is
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue massa.
For each character typed, check if the character is correct or not. Keep track of the number of wrong characters typed. After the user presses enter, tell the user how many characters are wrong ([x]), and its percentage ([y]). The percentage is calculated by # of wrong characters / # characters in the sentence. The percentage value should be rounded to two decimal places.
You typed [x] wrong characters ([y] %).
Here are three examples of how to count the number of wrong characters.
|
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. Lorem ipsam dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. |
| The above has 1 wrong character. |
|
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. Lorem ipsaum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. |
| The above has 80 wrong characters. |
|
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. Lorem |
| The above has 85 wrong characters. |
Repeat the previous step with the next sentence until the user type QUIT. If all the sentences have been used, start from the first sentence again. When the user type QUIT, print out the total number of wrong characters typed and the percentage value of # of wrong characters in all sentences / # characters in the all sentences. The percentage value should be rounded to two decimal places.
In total, you have typed [x] wrong characters ([y] %).
lore 30 % ./p2.out
CS240 Project 2: Typing Tutor
-----------------------------
Instruction: Please type each sentence as displayed, or QUIT to exit.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue massa.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue massa.
You typed 0 wrong characters (0.00 %).
Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna. Nunc viverra imperdiet enim.
Fusce posuere, magna sed pl
You typed 117 wrong characters (81.82 %).
Fusce est. Vivamus a tellus.
Fusce est. Vivamus
You typed 10 wrong characters (35.71 %).
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Proin pharetra nonummy pede.
Pellentesque habitant morbi tristique sens
You typed 81 wrong characters (66.39 %).
Mauris et orci. Aenean nec lorem.
Mauris et orci. Aenean nec lorem.
You typed 0 wrong characters (0.00 %).
In porttitor. Donec laoreet nonummy augue.
In porttitor. Donec laoreet nonummy augue..
You typed 1 wrong characters (2.38 %).
Suspendisse dui purus, scelerisque at, vulputate vitae, pretium mattis, nunc. Mauris eget neque at sem venenatis eleifend.
Suspendisse dui purus, scelerisque at, vulputate vitae, pretium mattis, nunc. Mauris eget neque at sem venenatis eleifend.
You typed 0 wrong characters (0.00 %).
...
Nunc lacus metus, posuere eget, lacinia eu, varius quis, libero. Aliquam nonummy adipiscing augue.
Nunc lacus metus, posuere eget, lacinia eu, varius quis, libero. Aliquam nonummy adipiscing augue.
You typed 0 wrong characters (0.00 %).
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue massa.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue massa.
You typed 0 wrong characters (0.00 %).
Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna. Nunc viverra imperdiet enim.
QUIT
In total, you have typed 6598 wrong characters (94.68 %).
lore 31 %
You can use any standard library functions except scanf().
Any cheating behavior (copy code from Internet or from other students) will be severely dealt with according to departmental and University policy, with a report to the Dean of Students. All of your codes will be analyzed automatically to find potential cheating.
When you are satisfied that your program works correctly (or you run out of time), please do the following.
Goto the parent directory of project2 and type the following command into the terminal:
turnin -c cs240=XXXX -p project2 project2
where XXXX represents your lab section number.
The turnin section is as follows:
| Section | Time | TA |
| 0201 | Thursday 15:30-17:20 | Dan Zhang |
| 0301 | Friday 09:30-11:20 | Suli Xi |
| 0401 | Friday 13:30-15:20 | Youhan Fang |
| 0501 | Thursday 09:30-11:20 | J. C. Chin |
Make sure turnin reports that your project was submitted for grading. You can check the files you have submitted by running the following command:
turnin -c cs240=XXXX -v -p project2
Your project will be graded against a set of test cases. Points are awarded by passing each test case.
| Makefile | 5 |
| Welcome message and instruction are printed correctly. | 2 |
| The practice text is printed correctly. | 3 |
| Statistic is correctly printed after each sentence. | 5 |
| Statistic is correctly printed when program exit. | 5 |
| The first sentence is used again after all the sentences have been used. | 10 |
| 10 Test cases | 70 (7 for each) |