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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 4 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
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education