Homework 3
This assignment will help you to become familiar with Perl subroutines, references, multi-dimensional structures, and some more regular expressions.
Description
You are to write a program that will take in and store data about corporations. The data will include the company's name, city, state, president's name, and list of board members.
Your program will be implemented by a looping menu. Upon the start of your program, you should present the user with a menu of options. Prompt the user to choose an option (make sure your prompt specifies how the user should enter his/her choice). After completing the specified task (see below), print the menu again.
If the user enters an invalid choice, print an error message, and print the menu and prompt again.
The menu options are:
- Add a new company.
- Enter a company location.
- Enter a president's name.
- Add a board member.
- Remove a board member.
- Fill out template.
- Exit.
A description of each of these options follows.
Add a new company
Simply prompt the user for the name of a company. If that company already exists in your data, print an error, and return to the menu. Otherwise, save the company in your data.
Enter a company's location
Prompt the user for which company to edit, by displaying the names of the current companies. If the entered company name does not exist, print an error and return to the menu. Once the user has entered a valid company name, ask the user for the company's city, and then for the company's state. Save both pieces of info.
If the company's city and/or state has already been saved, simply overwrite the data with the new information.
Enter a president's name
Prompt the user for which company to edit, by displaying the names of the current companies. If the entered company name does not exist, print an error and return to the menu. Once the user has entered a valid company name, ask the user for the company's president's name (the full name, as one string). Save this info.
If the company's president has already been saved, simply overwrite the data with the new information.
Add a board member
Prompt the user for which comapny to edit, by displaying the names of the current companies. If the entered company name does not exist, print an error and return to the menu. Once the user has entered a valid company name, ask the user for the board member to add. The user will enter the board member's full name. If this board member already exists for this company, print an error and return to the menu. Otherwise, add the board member to this company.
Remove a board member
Prompt the user for which comapny to edit, by displaying the names of the current companies. If the entered company name does not exist, print an error and return to the menu. Once the user has entered a valid company name, print a list of current board members, and ask the user for the board member to remove. The user will enter the board member's full name. If this board member does not exist for this company, print an error and return to the menu. Otherwise, remove the board member from this company.
Fill out template
(First, please note that several good templating systems have already been written by the Perl community, and are available on CPAN (see Text::Template for an example). For educational purposes, you will write your own simplistic system for this assignment)
Prompt the user for a template file to fill out. If the entered file does not exist, isn't readable, or can't be opened, print an error message, and return to the menu. Next ask the user for which company's data to use, by printing a list of current company names. If the entered company doesn't exist, print an error message, and return to the menu.
The template will be a text file, consisting of large amounts of text and 'placeholders'. All place holders will be a sequence of capital letters enclosed in square brackets. Valid place holders are:
- [NAME]
- [CITY]
- [STATE]
- [PRESIDENT]
- [BOARD]
Create a new file, named by the company name followed by .txt. (If the company name is 'Microsoft', name your new file 'Microsoft.txt'). Write to this new file all the text from the template. All place holders should be replaced with the respective data from the company info. ('[NAME]' should be replaced by the actual company's name, etc). The brackets are part of the place holders, and should not appear in the replaced text. When replacing the [BOARD] placeholder, replace it with a comma-and-space separated list of the company's board members.
There is one other change that must be made from the template to the saved company file. Any and all instances of the phrases 'Rensselaer' or 'Rensselaer University' must be replaced by the acronym 'RPI'. Note that the entire phrase 'Rensselaer Polytechnic Institute' must not be replaced.
Exit
Simply exit the program.
Assumptions
Due to the complexity and length of this assignment, you are permitted to make several assumptions about the data and user choices:
- There will not be any place holders other than the ones I have listed above. (Note that this does not preclude the possibility of a template having additional [ or ] characters.)
- No company will have multiple board members with the same name. (Although two companies may have a board member with the same name).
- A user will never select 'Fill out template' with a company whose data is incomplete.
- Neither 'Rensselaer University' nor 'Rensselaer Polytechnic Institute' will span more than one line.
Notes
- Although I dislike, in general, forcing students to choose a
particular algorithm or data structure, for the purposes of testing
knowledge learned in recent weeks, I need to enforce two structural
policies on your code for this assignment:
- You must make good use of at least one multi-dimensional structure. 'Good use' means that the structure must be an important part of your program - you may not simply declare a 2-d array and never use it.
- All of the numbered tasks above must be implemented in their own subroutines. When the user selects an option from the main menu, your program should simply call the appropriate subroutine.
- No where in this assignment should your program exit because the user entered invalid or unexpected data. Whenever something 'wrong' or unexpected happens, you should print an error to the screen, and either re-prompt the user for valid input, or return to the menu (whichever 'makes sense' in each particular case). The only way your program should end is by the user selecting the 'Exit' option from the main menu.
Grading Criteria
| Add a new company | 5 |
|---|---|
| Save the company's president, city, state | 5 |
| Add a board member | 10 |
| Remove a board member | 15 |
| Create company text file. | 5 |
| Replace name, city, state, president placeholders | 10 |
| Replace board members place holder | 15 |
| Replace Rensselaer & Rensselaer University with RPI | 15 |
| Clean Compliation | 5 |
| Error Checking | 5 |
| Output Style | 5 |
| Code Style | 5 |
Compilation
Points are deducted for any warning messages your code produces. Note that warnings will be enabled when we run your program, regardless of whether or not you've enabled warnings within the code.
As a reminder, while use strict; is not a requirement
for the homework, it is a very strong suggestion (also keep in mind
that it is required before emailing for help.)
If your code produces compilation errors, you will lose all the points for compilation, and the remainder of your program will be graded subjectively based on the code you've written itself. You should never submit code that does not compile.
Output Style
Output, in this case, refers to the menu and prompts printed to the user. In general, output should be well formatted and clearly identifiable. All output on one single line is bad. The raw data, without being labeled, is also bad. If it hurts my (or the TA's) eyes to look at, it's bad.
Code Style
All code that you write should be well styled. Most important are three features: A consistent and helpful indentation scheme; Meaningful variable names; explanatory but not over-abundant comments.
For examples of well-styled code, please see perldoc perlstyle
Supplemental Files
The main homework page will soon have a transcript of a sample runthrough of the program, sample template files, sample output files, and a Frequently Asked Questions page.
Submission Instructions
This homework is due Tuesday, October 18, 2005 at 11:59:59pm. As a
reminder, your program must be functional on the machine
rcs-sun4.rpi.edu. To submit your homework, log in to
rcs-sun4.rpi.edu, and run the program:
~lallip/public/hw_submit.pl
Follow the prompts. You will receive an email confirmation of your
submission. If anything goes wrong, please email Paul at lallip@cs.rpi.edu ASAP.
Remember that you may submit infinite times. Only the last homework submission will be looked at.
The homework will be accepted until Wednesday, October 19, 2005 at 3:59:59pm for a reduction of 20 points. Please note that if you make a submission at 11:30pm on the due date, and another 2 hours later, only the late submission will be graded. If your program is not complete, please use the table above to determine if a 20 point deduction warrants you completing the assignment and submitting late.
