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 #include #include #include #include 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; }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
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 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY