Lab 9
Lab assignment: Structs for the storage and retrieval of data - Dictionary Version
This week in lab we'll be using structs and arrays of structs again, to be sure you understand them.
We've given you the code to read in a dictionary, and it should look pretty familiar.
You do not need to modify any of the code to read in the dictionary, your code should be before main (for the struct) and after the dictionary is fully read in.
A sample run of the program will look like the following. (User input is shown in bold, though in your program it will not be bold.)
1 point
Enter a letter: g
g 89334 97902
2 points
a 0 15472
b 15473 29035
c 29036 52783
...
3 points
a 0 15472 0.0587137
b 15473 29035 0.051466
c 29036 52783 0.090114
...
Stage 1 (1 point):
Declare a struct containing 3 fields, a char, an int, and another int. The first field should contain a letter. The second field should store the index of the first word in the dictionary at which the letter stored in the struct is the first character. The third field should contain the index of the last word in the dictionary for which the stored letter is the first character.
Then, in main, ask the user to input a letter. Instantiate a structure containing the information for that letter. Then output the letter, starting index, and ending index, separated by tabs.
Note that you only need to do this once, you do not need to keep asking the user for letters.
C or C++ is fine, but be sure to be consistent with how you use structs.
Stage 2 (1 point):
Create an array of length 26 of your structs. Populate this array with one object per letter, storing the starting index and ending index for each letter.
Then print out the line of code for every object in the array.
Stage 3 (Extra Credit) (1 point):
When you output, print out one additional piece of data: the probability of a random word from the dictionary starting from that letter. You can either modify your struct to add one more value, a double, to store this probability, or store the total length of the dictionary in main (it already is in wordRow) and calculate it on the spot.
Notes:
Keep in mind that this is a team effort so you should agree with your partner on what you are going to do before you start typing. The partner who is typing is the "driver" and the partner watching is the "navigator." Be sure to switch roles every 10 to 15 minutes, to foster a deep understanding of the code for both partners. The navigator should be watching for syntax errors and verifying the correctness of the code you're writing.
It will speed things up for you if you keep a window open for editing and have a separate window open for compiling and running your program. Remember that windows are resizeable!
Submission:
1. You should work with a partner for this (and all the remaining) lab(s). Only one of you need to submit the program to Blackboard, though you should be certain that both of your names be present in a comment at the top of the .c or .cpp source file.
1.5 If you work alone, include just your name in a comment at the top so that I know you worked alone, and not have to guess.
2. You should turn in to Blackboard by the END OF THE LAB (8:50 for the 8-9 lab session, 9:50 for the 9-10 lab session). I know it's tempting to keep working on it, but other classes come in, and it's not fair to the students who are limited to that particular time span if you go over. Which isn't to say that you can't work on it later, to check your solution against the one I post for your own understanding. But what you submit for a grade should be before the next hour begins.
3. If you wish, you may submit your lab by 11 am on Thursday for a 1 point penalty. If you can't finish up the second point by the end of lab, you can still earn the score by completing all three steps and submitting your code by the day after.