COP4020 Programming Assignment 3 Class Roster Management System in Scheme

advertisement
COP4020 Programming Assignment 3
Class Roster Management System in Scheme
Due November 8, 2015
Objective
Gain experience with functional programming in Scheme.
Summary
In this assignment, we will write a class roster management system that provides basic
functions for entering, removing, and displaying student information in a course roster using
the Scheme language. The course roster is stored as a table of student entries with each entry
having three fields: the unique student ID (a string of digits), the student name (a string of
characters), and the grade (an integer). The menu for the management system has the
following choices:
Class roster management system
============================
MENU
============================
0. Reset roster
1. Load roster from file
2. Store roster to file
3. Display roster sorted by ID
4. Display student info
5. Add a student to roster
6. Remove a student from roster
7. Exit
The Reset roster function resets the current roster to an empty roster. The Load roster from
file function prompts the user for a file name and loads the roster from the file. The Store
roster to file function prompts the user for a file name and stores the current roster in the
indicated file. The Display roster function displays the current roster, sorted by ID in
ascending order. The Display student info function prompts the user to input either the
student ID or name, and displays the student information (or reports that the student is not
in the roster). The Add a student function prompts the user for the student ID, name, and
grade (one in each line) and adds the student to the current roster (or reports that the
student’s ID or name is already in the roster). The Remove student function prompts the user
1
to input either the student ID or name, and removes the student from the roster (or reports
that the student is not in the roster). An example run is shown below.
You are only allowed to use pure functional constructs in this assignment; any use of
non-pure functional constructs such as set!, set-car!, and set-cdr!, will result in a maximum
score of 40 for the assignment. If you are unsure about whether a particular construct is
allowed, please email me about it first.
The program must be able to display the menu and perform at least the following two tasks:
enter one student information (add a student to roster) and display the student information
(display roster). Programs that cannot perform these two functions (this includes all
programs with compiling errors) will receive at most 10 points. If a program can perform
these two functions, it will be graded as follows. Note that there are two bonus functions for
5 points each. These are very similar to the Display roster sorted by ID and I encourage
everyone to try to implement them. If you do, make sure to add an entry to the menu for each
additional function.
• Reset roster (5 points)
• Exit (5 points)
• Add a student to roster (30 points)
• Display roster sorted by ID (25 points)
• Display roster sorted by name (BONUS 5 points)
• Display roster sorted by grade (BONUS 5 points)
• Display student info (15 points)
• Remove a student from roster (10 points)
• Store roster to file (5 points)
• Load roster from file (5 points)
Some other miscellaneous notes:
• My sample implementation of this assignment (minus bonus features) has 232 lines of
Scheme code.
• After you implement the basic menu code, you should implement the Add a student to
roster and one of the Display roster functions.
• Scheme has a very limited debugging support and compiling error reporting capability.
You should allocate much more time than your normal C++ coding for this assignment.
One good thing about this assignment is that once you get past the first two functions,
the rest will be much easier.
2
• You can assume that the input is correct: the code can have undefined behavior when
the input is wrong.
Assignment Submission
Submissions are due on November 8 at 11:59pm. You should submit your roster.scm file to
Blackboard with your name and FSUID in a comment at the top of the file.
Sample Execution
1 ]=> (load "roster")
;Loading "roster.scm" -- done
;Value: menu
1 ]=> (menu ’())
Class roster management system
============================
MENU
============================
0. Reset roster
1. Load roster from file
2. Store roster to file
3. Display roster sorted by ID
4. Display student info
5. Add a student to roster
6. Remove a student from roster
7. Exit
Enter your choice: 5
Add a student to the class roster:
Student ID: 1
Student name: John Doe
Grade: 82
Class roster management system
============================
MENU
============================
3
0.
1.
2.
3.
4.
5.
6.
7.
Reset roster
Load roster from file
Store roster to file
Display roster sorted by ID
Display student info
Add a student to roster
Remove a student from roster
Exit
Enter your choice: 5
Add a student to the class roster:
Student ID: 2
Student name: Joe Shmoe
Grade: 92
Class roster management system
============================
MENU
============================
0. Reset roster
1. Load roster from file
2. Store roster to file
3. Display roster sorted by ID
4. Display student info
5. Add a student to roster
6. Remove a student from roster
7. ExitEnter your choice: 3
Displaying roster, sorted by ID:
No.1: ID=1, Name=John Doe, Grade=82
No.2: ID=2, Name=Joe Shmoe, Grade=92
Class roster management system
============================
MENU
============================
0. Reset roster
1. Load roster from file
4
2.
3.
4.
5.
6.
7.
Store roster to file
Display roster sorted by ID
Display student info
Add a student to roster
Remove a student from roster
Exit
Enter your choice: 5
Add a student to the class roster:
Student ID: 3
Student name: Jane Smith
Grade: 96
Class roster management system
============================
MENU
============================
0. Reset roster
1. Load roster from file
2. Store roster to file
3. Display roster sorted by ID
4. Display student info
5. Add a student to roster
6. Remove a student from roster
7. ExitEnter your choice: 3
Displaying roster, sorted by ID:
No.1: ID=1, Name=John Doe, Grade=82
No.2: ID=2, Name=Joe Shmoe, Grade=92
No.3: ID=3, Name=Jane Smith, Grade=96
Class roster management system
============================
MENU
============================
0. Reset roster
1. Load roster from file
2. Store roster to file
5
3.
4.
5.
6.
7.
Display roster sorted by ID
Display student info
Add a student to roster
Remove a student from roster
Exit
Enter your choice: 4
Enter student name or ID: 2
ID=2, Name=Joe Shmoe, Grade=92
Class roster management system
============================
MENU
============================
0. Reset roster
1. Load roster from file
2. Store roster to file
3. Display roster sorted by ID
4. Display student info
5. Add a student to roster
6. Remove a student from roster
7. Exit
Enter your choice: 4
Enter student name or ID: Jane Smith
ID=3, Name=Jane Smith, Grade=96
Class roster management system
============================
MENU
============================
0. Reset roster
1. Load roster from file
2. Store roster to file
3. Display roster sorted by ID
4. Display student info
5. Add a student to roster
6. Remove a student from roster
6
7. Exit
Enter your choice: 2
Store roster to file: oldroster.txt
Class roster management system
============================
MENU
============================
0. Reset roster
1. Load roster from file
2. Store roster to file
3. Display roster sorted by ID
4. Display student info
5. Add a student to roster
6. Remove a student from roster
7. Exit
Enter your choice: 6 Enter a student
name or ID: 1 Student with ID 1
deleted.
Class roster management system
============================
MENU
============================
0. Reset roster
1. Load roster from file
2. Store roster to file
3. Display roster sorted by ID
4. Display student info
5. Add a student to roster
6. Remove a student from roster
7. Exit
7
Enter your choice: 6 Enter a student name or ID:
Jane Smith Student with name Jane Smith
deleted.
Class roster management system
============================
MENU
============================
0. Reset roster
1. Load roster from file
2. Store roster to file
3. Display roster sorted by ID
4. Display student info
5. Add a student to roster
6. Remove a student from roster
7. Exit
Enter your choice: 3
Displaying roster, sorted by ID:
No.1: ID=2, Name=Joe Shmoe, Grade=92 Class
roster management system
============================
MENU
============================
0. Reset roster
1. Load roster from file
2. Store roster to file
3. Display roster sorted by ID
4. Display student info
5. Add a student to roster
6. Remove a student from roster
7. ExitEnter your choice: 0
Roster reset (now empty).
Class roster management system
============================
MENU
8
============================
0. Reset roster
1. Load roster from file
2. Store roster to file
3. Display roster sorted by ID
4. Display student info
5. Add a student to roster
6. Remove a student from roster
7. ExitEnter your choice: 3
Displaying roster, sorted by ID: No records
to display.
Class roster management system
============================
MENU
============================
0. Reset roster
1. Load roster from file
2. Store roster to file
3. Display roster sorted by ID
4. Display student info
5. Add a student to roster
6. Remove a student from roster
7. Exit
Enter your choice: 1
Load roster from file: oldroster.txt
Class roster management system
============================
MENU
============================
0. Reset roster
1. Load roster from file
2. Store roster to file
3. Display roster sorted by ID
4. Display student info
5. Add a student to roster
6. Remove a student from roster
9
7. Exit
Enter your choice: 3
Displaying roster, sorted by ID:
No.1: ID=1, Name=John Doe, Grade=82
No.2: ID=2, Name=Joe Shmoe, Grade=92
No.3: ID=3, Name=Jane Smith, Grade=96
Class roster management system
============================
MENU
============================
0. Reset roster
1. Load roster from file
2. Store roster to file
3. Display roster sorted by ID
4. Display student info
5. Add a student to roster
6. Remove a student from roster
7. Exit
Enter your choice: 7
Goodbye!
;Value: #t
1 ]=> (exit)
Kill Scheme (y or n)? Yes Happy
Happy Joy Joy.
10
Download