Question

In: Computer Science

Write a C++ program that reads a file consisting of students’ test scores in the range...

Write a C++ program that reads a file consisting of students’ test scores
in the range 0–200. It should then determine the number of students
having scores in each of the following ranges: 0–24, 25–49, 50–74,
75–99, 100–124, 125–149, 150–174, and 175–200. Output the
score ranges and the number of students. (Run your program with the
following input data: 76, 89, 150, 135, 200, 76, 12, 100, 150, 28,
178, 189, 167, 200, 175, 150, 87, 99, 129, 149, 176, 200, 87,
35, 157, 189.)

Solutions

Expert Solution

Thanks for the question, here is the code in C++

Note: Please refer the screenshot for the input file having the scores data. Also, when you run the program make sure you update the filename correctly in the below line -

char * filename ="F:\\scores.txt";

Have included comments so that you can follow the code. Let me know in case you have any questions.

============================================================================

#include<iostream>
#include<fstream>
using namespace std;

// utlility function that accepts a number and returns

// the index in the array where it should be counted

int get_index(int n){
  
   if(n>=200)return 7;
   return n/25;
  
}

// accepts an int array and prints the frequency in the range

void displayHistogram(int range[], int size){
  
   for(int i=0;i<size;i++){
       if(i!=size-1)
       cout<<25*i<<"-"<<i*25+24<<" : "<<range[i]<<endl;
       else
       cout<<25*i<<"-"<<i*25+25<<" : "<<range[i]<<endl;
      
      
   }
}

int main(){

// update the filename of the input file in the below line.
   char * filename ="F:\\scores.txt";
   ifstream infile(filename);
   int range[8]{0};
   if(infile.is_open()){
       int score;
       while(infile>>score){
           range[get_index(score)]+=1;
          
       }
       infile.close();
       displayHistogram(range,8);
      
   }else{
       cout<<"Unable to read data from file: "<<filename<<endl;
   }
}


Related Solutions

Write a program that reads a file consisting of students’ test scores in the range 0–200....
Write a program that reads a file consisting of students’ test scores in the range 0–200. It should then determine the number of students having scores in each of the following ranges: 0–24, 25–49, 50–74, 75–99, 100–124, 125–149, 150–174, and 175–200. Output the score ranges and the number of students. (Run your program with the following input data: 76, 89, 150, 135, 200, 76, 12, 100, 150, 28, 178, 189, 167, 200, 175, 150, 87, 99, 129, 149, 176, 200,...
Write a program that reads students’ names followed by their test scores. The program should output...
Write a program that reads students’ names followed by their test scores. The program should output each student’s name followed by the test scores and the relevant grade. It should also find and print the highest test score and the name of the students having the highest test score. Student data should be stored in a struct variable of type studentType, which has four components: studentFName and studentLName of type string, testScore of type int (testScore is between 0 and...
C++ Write a program that prompts for a file name and then reads the file to...
C++ Write a program that prompts for a file name and then reads the file to check for balanced curly braces, {; parentheses, (); and square brackets, []. Use a stack to store the most recent unmatched left symbol. The program should ignore any character that is not a parenthesis, curly brace, or square bracket. Note that proper nesting is required. For instance, [a(b]c) is invalid. Display the line number the error occurred on. These are a few of the...
(Please write in C++) Write a program that reads in a line consisting of a student’s...
(Please write in C++) Write a program that reads in a line consisting of a student’s name, Social Security number, user ID, and password. The program outputs the string in which all the digits of the Social Security number and all the characters in the password are replaced by x. (The Social Security number is in the form 000-00-0000, and the user ID and the password do not contain any spaces.) Your program should not use the operator [ ]...
In c++ Write a program that reads a string consisting of a positive integer or a...
In c++ Write a program that reads a string consisting of a positive integer or a positive decimal number and converts the number to the numeric format. If the string consists of a decimal number, the program must use a stack to convert the decimal number to the numeric format. Use the STL stack
In c++, write a program that reads a string consisting of a positive integer or a...
In c++, write a program that reads a string consisting of a positive integer or a positive decimal number and converts the number to the numeric format. If the string consists of a decimal number, the program must use a stack to convert the decimal number to the numeric format.
In java, Write a program that reads a data file containing final exam scores for a...
In java, Write a program that reads a data file containing final exam scores for a class and determines the number of passing scores (those greater than 60) and the number of failing scores (those less than 60). The average score as well as the range of scores should also be determined. The program should request the name of the data file from the end user. The file may contain any number of scores. Using a loop, read and process...
Write a C program that Reads a text file(any file)  and writes it to a binary file....
Write a C program that Reads a text file(any file)  and writes it to a binary file. Reads the binary file and converts it to a text file.
In C++, write a program that reads data from a text file. Include in this program...
In C++, write a program that reads data from a text file. Include in this program functions that calculate the mean and the standard deviation. Make sure that the only global variables are the actual data points, the mean, the standard deviation, and the number of data entered. All other variables must be local to the function. At the top of the program make sure you use functional prototypes instead of writing each function before the main function... ALL LINES...
In C++ Write a program to store exam scores into a file. The program will ask...
In C++ Write a program to store exam scores into a file. The program will ask the user how many exam scores to enter. Then it will ask the user for each exam score and store them in a file called scores.dat The file output should have the following format: Exam 1: 97 Exam 2: 85
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT