A small student-information data base is being formed. Currently, there are some of students represented in the data base. However,
more are expected to be added in the future (up to 50 total); a few may be removed, as well. Your task is to write a program to handle
the actions that need to be performed on this data base. Among these actions are the following.
1. ADD - add a new student record.
2. DELETE - remove a record currently in the data base.
3. FIND-BY-NAME - show all the information about one student (or display an error message if there is no such student).
4. FIND-BY-ID - show all the information about one student (or display an error message if there is no such student).
5. LIST - show all information about all students (listing them in alphabetical order).
6. RANK - based on the GPAs, display the student's names and GPAs in the order of their rank (highest to lowest).
You will be writing three versions of the program to perform these tasks. You are given a starter program to get you moving in the right direction. The starter is in a file called P1START.CPP which can be copied from O:\JLW\310 in the data centers, downloaded from 310LIB: on the VMS system, or copied from L:\JLW\310 in Tompkins lab. The starter program provides control for the overall project. The program begins by reading in information about the students from a file into an array. Then, the program accepts single character commands from the keyboard and calls a function that performs the task associated with that command. The commands and their tasks are A ADD, D DELETE, I FIND-BY-ID, L LIST, N - FIND-BY-NAME, R RANK and Q QUIT. For this last command, the program terminates (no function is to be called).
The starter program contains stubs for each of the functions, except the LIST function. ¬The information about each student is stored in a structure that has the following form.
struct inforec
{ char name[21]; // Holds up to 20 characters
int id; // A 4-digit ID number
float gpa; // Grade Point Average
int level; // A class level number (1 - 4)
char major[15] // Student's major
};
The data base records are in the file STUDENTS.DAT, are already in alphabetical order, and can be copied from the same sources as the starter program. Each record of the file contains a 20-character name, an ID number, a GPA in the form x.xx, a class level number, a major (up to 14 characters), and a newline (end of record) character.
For your first version of the student information program, you are to make the following changes to the starter version. MAKE SURE YOU UNDERSTAND WHAT THE STARTER PROGRAM IS DOING BEFORE YOU START CHANGING IT.
1. Allow all single letter commands to be entered in either uppercase or lowercase. For example, the LIST task should be performed if either L or l is entered.
2. Fill out the function to FIND-BY-ID a student record and display all the information about that one student. Ask the person running the program for the ID of the student to be found. Handle the "not found" case by displaying an error message if the person to be found is NOT in the data base.
3. Fill out the function to DELETE a student record. Ask the person running the program for the ID of the student to be deleted. After the deleted record is gone, the records in the array must remain in alphabetical order (with no gaps). Verify that the student to be deleted exists in the data base before attempting to delete it. If the student does NOT exist, display an error message.
Strong Suggestion: Make an additional function to help you do the FIND-BY-ID task. This function would do the searching of the array of student records for a designated record and return a value indicating where the record was found and if it was found. If you are clever, you can make this auxiliary function useful in locating the a record to be deleted, as well.
Demonstrate that the second version of the program works by running it and entering the following series of commands.
L
i { find 3007 }
D { delete 3861 }
i { find 4277 }
d { delete 2100 }
i { find 3861 }
d { delete 8023 }
D { delete 8099 }
I { find 6225 }
I { find 1806 }
l
q
Hand in a diskette with your source program on it. Also, hand in a printout listing of your program. The file name should be you-P1A.CPP
For the second version of your program, make the following changes to the first version.
1. Fill out the function to FIND-BY-NAME a student record and display all the information about that one student. Ask the person running the program for the name (or leading portion of the name) of the student to be found. If the name is not found, display an error message (as with FIND-BY-ID).
2. Fill out the function to ADD a new student record. Be sure to have the function request all the information for the new record from the person running the program. Be sure to check to make sure that the record to be added does NOT exist in the database; if it does exist, display an error message. The added record must be placed in the array so that the whole array remains in alphabetical order based on the name.
Demonstrate the second version of the program by running it and entering the following series of commands.
L
A { add Capp, Andy 4117 you make up the rest }
d { delete 2100 }
n { find Oop, Alley }
a { add Abner, Daisy Mae 1426 you make up the rest }
N { find Dallas, Steve }
d { delete 3861 }
i { find 4117 }
A { add Palooka, Joe 7633 you make up the rest }
i { find 6225 }
A { add Smith, Tina 3007 }
D { delete 8099 }
N { find Abner, Daisy Mae }
l
q
Hand in a diskette with your source program on it. Also, hand in a printout listing of your program. The file name should be you-P1B.CPP.
For the final version of the student information program, you are to make the following changes to the second version of the program.
1. Fill out the function to RANK the students based on their GPA and display the students' names in the order of their rank.
To do this, your program must sort the students based on their QPAs. You must do this sorting using an index or indirect sort. That is, you are not allowed to change the order of the records in the data base array; nor are you allowed to make a duplicate of both the names and GPAs and sort the duplicates. The only information that you are allowed to duplicate for this sorting are the GPAs; and the ranking can be done without duplicating any information from the student records.
2. When the Q command is entered and before terminating the program, write out the updated version of the student data base to a file called A:\NEW.DAT. The output records for STUDENTS.NEW must be in exactly the same form as the original records in STUDENTS.DAT. MAKE SURE YOU UNDERSTAND HOW LOADDATA WORKS BEFORE YOU TRY TO WRITE NEW.DAT.
Demonstrate that the third version of the program works by running it and entering a set of commands similar to those used to demonstrate the second version. However, you must include two or more R commands in the set (preferably one near the beginning and another near the end).
Hand in a diskette with the source file for your program. Also, hand in a printout listing of your program. The file name should be you-P1C.CPP