Hello, Below is my current code. It works as intended but I would like to prompt the user to input the files name and open it that way instead of it being declared in the code itself. I tried a few things myself but couldnt gete it to work. Any help would be appricated. #include #include #include #include using namespace std; int main() { //open file ifstream file("StudentGrades.txt"); int number; string x; //declare array int *array = new int; int index = 0; //declare variable to store number of student int score24 = 0, score49 = 0, score74 = 0, score99 = 0, score124 = 0, score149 = 0, score174 = 0, score200 = 0; //Ensure array is not already full while (getline(file, x, ',')) { //convert to int number = stoi(x); //store it in a array array[index++] = number; } //check the every element and score based on score for(int i=0;i=0 && array[i] <=24) score24++; else if(array[i]>=25 && array[i] <=49) score49++; else if(array[i]>=50 && array[i] <=74) score74++; else if(array[i]>=75 && array[i] <=99) score99++; else if(array[i]>=100 && array[i] <=124) score124++; else if(array[i]>=125 && array[i] <=149) score149++; else if(array[i]>=150 && array[i] <=174) score174++; else if(array[i]>=175 && array[i] <=200) score200++; } //display score of the file cout<<"\nStudent test score from the file is: "<
Hello, Below is my current code. It works as intended but I would like to prompt the user to input the files name and open it that way instead of it being declared in the code itself. I tried a few things myself but couldnt gete it to work. Any help would be appricated. #include #include #include #include using namespace std; int main() { //open file ifstream file("StudentGrades.txt"); int number; string x; //declare array int *array = new int; int index = 0; //declare variable to store number of student int score24 = 0, score49 = 0, score74 = 0, score99 = 0, score124 = 0, score149 = 0, score174 = 0, score200 = 0; //Ensure array is not already full while (getline(file, x, ',')) { //convert to int number = stoi(x); //store it in a array array[index++] = number; } //check the every element and score based on score for(int i=0;i=0 && array[i] <=24) score24++; else if(array[i]>=25 && array[i] <=49) score49++; else if(array[i]>=50 && array[i] <=74) score74++; else if(array[i]>=75 && array[i] <=99) score99++; else if(array[i]>=100 && array[i] <=124) score124++; else if(array[i]>=125 && array[i] <=149) score149++; else if(array[i]>=150 && array[i] <=174) score174++; else if(array[i]>=175 && array[i] <=200) score200++; } //display score of the file cout<<"\nStudent test score from the file is: "<
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
Related questions
Question
Hello, Below is my current code. It works as intended but I would like to prompt the user to input the files name and open it that way instead of it being declared in the code itself. I tried a few things myself but couldnt gete it to work. Any help would be appricated.
#include <fstream>
#include<iostream>
#include <ctype.h>
#include <string>
using namespace std;
int main()
{
//open file
ifstream file("StudentGrades.txt");
int number;
string x;
//declare array
int *array = new int;
int index = 0;
//declare variable to store number of student
int score24 = 0, score49 = 0, score74 = 0, score99 = 0, score124 = 0, score149 = 0, score174 = 0, score200 = 0;
//Ensure array is not already full
while (getline(file, x, ','))
{
//convert to int
number = stoi(x);
//store it in a array
array[index++] = number;
}
//check the every element and score based on score
for(int i=0;i<index;i++)
{
if(array[i]>=0 && array[i] <=24)
score24++;
else if(array[i]>=25 && array[i] <=49)
score49++;
else if(array[i]>=50 && array[i] <=74)
score74++;
else if(array[i]>=75 && array[i] <=99)
score99++;
else if(array[i]>=100 && array[i] <=124)
score124++;
else if(array[i]>=125 && array[i] <=149)
score149++;
else if(array[i]>=150 && array[i] <=174)
score174++;
else if(array[i]>=175 && array[i] <=200)
score200++;
}
//display score of the file
cout<<"\nStudent test score from the file is: "<<endl;
for(int i=0;i<index;i++)
cout<<array[i]<<" ";
cout<<endl;
//display result
cout<<"\nScore ranges \t Number of students"<<endl;
cout<<"0-24 \t \t "<<score24<<endl;
cout<<"25-49 \t \t "<<score49<<endl;
cout<<"50-74 \t \t "<<score74<<endl;
cout<<"75-99 \t \t "<<score99<<endl;
cout<<"100-124 \t "<<score124<<endl;
cout<<"125-149 \t "<<score149<<endl;
cout<<"150-174 \t "<<score174<<endl;
cout<<"175-200 \t "<<score200<<endl;
cout<<endl;
//close the file
file.close();
}
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 3 steps with 1 images
Knowledge Booster
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.Recommended textbooks for you
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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education