I have a bit of code that is intended to read a file ("students.txt") and calculate the average, highest, and lowest scores from given information. (students.txt reads: " Mark Thompson 72.50James Taylor 100.00Daniel Price 80.2Busy Phillips 63.0 " ) This is the code I have: I have tweaked it to output the highest and lowest but I cannot get it to read the file. I have saved the file into the directory of the program but nothing seems to be working. I am also stumped on the formatting of the calculations.   //////////////////////////////////////////// #include <iostream>#include <fstream>#include <cmath>#include <string>#include <iomanip>using namespace std; int main() { ifstream inFile; // This is a declaration of the inFile that holds all the gradesstring fileName; // This is the filename that the user will enterconst int min = 63.0; // This is a constant min used to find the lowest scoreconst int max = 100.0; // This is the constant max used to find the highest score fstream instream;instream.open("students.txt"); // Opens file cout << "Enter the input file name: "; // Prompts user to express desired file to be readcin >> fileName; if (!instream) cout << "File did not open correctly" << endl; // Alerts user that file did not open properly.return 1; cout << "The highest grade of " << max << " is held by James Taylor." << endl; // Articulates student with the highest gradecout << "The lowest grade of " << min << " is held by Busy Phillips." << endl; // Articulate student with the lowest gradeinstream.close(); return 0;}

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter13: File Input And Output
Section: Chapter Questions
Problem 6PE
icon
Related questions
Question

I have a bit of code that is intended to read a file ("students.txt") and calculate the average, highest, and lowest scores from given information.

(students.txt reads: "

Mark Thompson 72.50
James Taylor 100.00
Daniel Price 80.2
Busy Phillips 63.0

" )

This is the code I have:

I have tweaked it to output the highest and lowest but I cannot get it to read the file. I have saved the file into the directory of the program but nothing seems to be working. I am also stumped on the formatting of the calculations.

 

////////////////////////////////////////////

#include <iostream>
#include <fstream>
#include <cmath>
#include <string>
#include <iomanip>
using namespace std;

int main() {

ifstream inFile; // This is a declaration of the inFile that holds all the grades
string fileName; // This is the filename that the user will enter
const int min = 63.0; // This is a constant min used to find the lowest score
const int max = 100.0; // This is the constant max used to find the highest score


fstream instream;
instream.open("students.txt"); // Opens file

cout << "Enter the input file name: "; // Prompts user to express desired file to be read
cin >> fileName;

if (!instream)

cout << "File did not open correctly" << endl; // Alerts user that file did not open properly.
return 1;

cout << "The highest grade of " << max << " is held by James Taylor." << endl; // Articulates student with the highest grade
cout << "The lowest grade of " << min << " is held by Busy Phillips." << endl; // Articulate student with the lowest grade
instream.close();


return 0;
}

Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Constants and Variables
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT