Problem Statement – Modify the GPA Calculation program so that you input your grades from a file, Grades.txt. To include file I/O to your program, you must complete the following five steps: Include the header file fstream in the program. Declare file stream variable, ifstream inFile; Associate the file stream variable with the I/O source. Use the file stream variable with the extractor variable >> to get
Problem Statement – Modify the GPA Calculation program so that you input your grades from a file, Grades.txt. To include file I/O to your program, you must complete the following five steps:
- Include the header file fstream in the program.
- Declare file stream variable, ifstream inFile;
- Associate the file stream variable with the I/O source.
- Use the file stream variable with the extractor variable >> to get input.
- Close the file.
Be sure to include the additional comments for the file manipulation program statements. Please read chapter 3 on file manipulation to see a program that includes these instructions and look at supplementary slides in Module 5 in Materials and Resources.
You are also to create an input file and save it as Grades.txt using the tool NotePad. The file should have the following data in it:
Student #: 1001
Homework scores: 0, 0, 0
Quiz scores: 0, 0, 0
Program scores: 0, 0, 0
test scores: 0, 0, 0
Final Score: 0
Student #: 1002
Homework scores: 50, 50, 50
Quiz scores: 20, 20, 20
Program scores: 100, 100, 100
test scores: 100, 100, 100
Final Score: 120
Student #: 1003
Homework scores: 50, 25, 50
Quiz scores: 20, 15, 20
Program scores: 100, 90, 90
test scores: 100, 75, 65
Final Score: 90
In this file, the first line of the file is the student number, the second line contains the homework scores, the third line contains the quiz scores, the fourth line contains the program scores, the fifth line contains the test scores, and the sixth line contains the final score. You may modify the lines to reflect how you read information in from the standard I/O device.
Additionally, you should use a looping control structure to read in the data from the file. You are also to add a selection statement (one way or if else if statements) to find out the letter grade associated with your GPA. For example, if your GPA is equivalent to 91.50, then the letter grade would be a "A". You are then to add a switch statement to print out the letter grade. Letter grades can be either A, B, C, D or F. For example, "Your grade that you earned is A".
Prior to printing the letter grade, you must print your calculated GPA.
The output from the program should be as follows for each of the students:
The GPA for student 1002: 100
The earned letter grade: A.
Remember to test your program by including the Grade.txt file in the same directory as your program.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images