L548: Final Exam

Notes:
a) Send the exam to upriss@indiana.edu by Monday, April 30, 12.00 pm (Noon).
Send 3 scripts as attachments to an email message. The 3 files should be labeled yourname1, yourname2, yourname3.
b) You will get a better grade if you produce a program that runs without errors but does not have all required features than if you work on all the features but your program cannot be executed.
c) The scripts must be completely written in Perl. System calls to Unix utilities or other programming languages are not allowed.
d) Team work is not allowed. If you have questions, send them to upriss@indiana.edu. If the question can be answered without giving too much help, the answer will be posted to the class mailing list.
e) No libraries or subroutines other than the standard ones should be used (i.e. the scripts should not have a "use ..." statement).

1) Word guess

Let users choose a number between 0 and 4. The following array provides a word to be guessed according to the chosen number. @numbers=("chocolate", "strawberry", "pineapple", "marshmallow", "pistachio"). Split the chosen word into an array. Print as many "-" to the screen as the word has characters, for example, "----------" if the number was 1. Let the user then guess two characters. If the user guesses a character that is contained in the word, replace the "-" by the characters. In the example, if the user guesses "o" and "a", print "---a------". Next let the user guess the full word. If the user guesses the full word correctly print "Congratulations"; otherwise print "That's not it". Ask the user, if he/she wants to guess another word. If "yes" repeat the whole process starting from 'Let the user choose a number between 0 and 4'.

2) Database calculations

Write a script that reads a file called "input.txt" which is in the following format:

John Smith|A|A-|B+
Mary Miller|B+|A|A-    
Each line contains a student name (first name and last name) and three grades. The fields are delimited by the pipe symbol. To calcluate the final grade for each student, the letter grades need to be converted into numeric values as follows (there are no grades below B-). Use substitution for the conversion.
A 4.0
A- 3.7
B+ 3.3
B 3.0
B- 2.7
Then the average of the three grades is calculated. The resulting number is comverted back into a letter grade as follows. (You can use if statements to do this.)
A  3.85 - 4.00
A- 3.5  - 3.85
B+ 3.15 - 3.5
B  2.85 - 3.15
B- 2.5 - 2.85
The script then prints the students and their grades to the screen in the following format:
Smith, John: A- 
Miller, Mary: A-

3) Parsing mark up text

Example of XML:

<recipe>
<title>Two-Minute Fudge</title>
<ingredient-list>
<ingredient> 1 pound sugar </ingredient>
<ingredient> 1/2 cup butter </ingredient>
<ingredient> 1/4 cup milk </ingredient>
<ingredient> 1 tablespoon vanilla </ingredient>
<ingredient> 1 cup chopped nuts </ingredient>
</ingredient-list>
<instruction-list>
<step>Mix all ingredients</step>
<step>Microwave on HIGH 2 minutes</step>
<step>Stir until smooth</step>
</instruction-list>
</recipe>

Write a script that reads recipes in that format and outputs them in another format. Store ingredients and steps in an array each. Give the user two choices for the output format (each should be handled by a subroutine):
a) normal text
b) html (leave the title tags, print "ingredient list" and "instruction list" as h3 headings, print the instructions, steps as lists, add other required html tags)