For this lab, you will complete a program that allows a teacher to enter the first name and a test score for the students in his or her class. Assume that the teacher has already entered the names and test scores of some of the students in the class and have stored this information in a text file called student_scores.txt. The contents of that file resembles the following example below.

(Example text file)

James 88
Ronda 92
Benjamin 85
Sarah 97
Frank 89

The program will allow the teacher to add student scores, delete student scores, and display all student scores. All of this information must be maintained in the student_scores.txt file so that the teacher can access this information at any time; even after the application has closed. Your program must contain a menu and three additional functions to the main; addStudentScores(), deleteStudentScores(), and displayStudentScores.

(1) Display a program header and the user menu to allow the user to make a menu selection. The program must repeat until the user selects option 4 to exit the program.

Ex.

Student Test Score Entry Program
--------------------------------

1. Add Student Score
2. Delete Student Score
3. Display Student Scores
4. Exit Program
Enter Selection:
4

The program will now exit!

(2) Write an addStudentScores() function that allows the teacher to add any number of student scores to the file. The program should ask the teacher how many student scores to enter, then append the text file with the appropriate number of student test scores. A confirmation message should also appear to confirm that the new student scores have been added to the file. Note that all new scores must follow the same format that already exists in the text file with the student name and test score on the same line.

Ex.

Student Test Score Entry Program
--------------------------------

1. Add Student Score
2. Delete Student Score
3. Display Student Scores
4. Exit Program
Enter Selection:
1

Number of student scores to enter:
2
Enter student's name:
Mary
Enter student's test score:
97
Enter student's name:
Brian
Enter student's test score:
79

New test scores saved to file!

(3) Write a deleteStudentScores() function that allows a teacher to enter only the name of a student and have that student and his or her score deleted from the file. A message of Student not found! should be displayed if the teacher enters a name of a student not in the text file. Or a message of [StudentName] has been deleted from the file! should be displayed to confirm that the student has been deleted from the text file.

Hints:

  • You will need to read from and write to the file.
  • Think about using a Boolean to determine if the name is present in the file.
  • Think about whether you need to confirm how the teacher enters the student's name.
  • Remember that the student's name is only contained in the first part of each line.

Ex.

Student Test Score Entry Program
--------------------------------

1. Add Student Score
2. Delete Student Score
3. Display Student Scores
4. Exit Program
Enter Selection:
2

Enter the student's name to delete:
Ronald
Student not found!

1. Add Student Score
2. Delete Student Score
3. Display Student Scores
4. Exit Program
Enter Selection:
2

Enter the student's name to delete:
Sarah
Sarah has been deleted from the file!

(4) Write a displayStudentScores() function that allows the teacher to display all of the student scores in the text file.

Ex.

Student Test Score Entry Program
--------------------------------

1. Add Student Score
2. Delete Student Score
3. Display Student Scores
4. Exit Program
Enter Selection:
3

Student Scores
--------------
James 88
Ronda 92
Benjamin 85
Frank 89
Mary 97
Brian 79
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.