Question

In: Computer Science

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, 87, 35, 157, 189.

Solutions

Expert Solution

SOLUTION:

Dear Student, I am pasting the code with comments of above query and also attaching it's snapshots .

PROGRAM:

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

int main()
{
//declaring variables
ifstream file("marks.txt"); // open the marks.txt file
double marks[26];
int i, st_num=0;
int scr0_24=0, scr25_49=0, scr50_74=0, // initializing variables to 0
scr75_99=0, scr100_124=0, scr125_149=0,
scr150_174=0, scr175_200=0;

//initializing marks in array
for(i=0; i<26; i++)
{
marks[i] = 0;
}

//taking marks from the marks.txt file
for(i=0; i<26; i++)
{
file >> marks[i];
st_num++;
}

file.close(); // now close the file

//finding number of people for each score range
for(i=0; i<26; i++)
{
if(marks[i] <= 24)
scr0_24++;
if(marks[i] >= 25 && marks[i] <= 49)
scr25_49++;
if(marks[i] >= 50 && marks[i] <= 74)
scr50_74++;
if(marks[i] >= 75 && marks[i] <= 99)
scr75_99++;
if(marks[i] >= 100 && marks[i] <= 124)
scr100_124++;
if(marks[i] >= 125 && marks[i] <= 149)
scr125_149++;
if(marks[i] >= 150 && marks[i] <= 174)
scr150_174++;
if(marks[i] >= 175 && marks[i] <= 200)
scr175_200++;
}

// Now print the result in particular range
cout << "Number of students: " << st_num << endl;
cout << "0-24: " << scr0_24 << endl;
cout << "25-49: " << scr25_49 << endl;
cout << "50-74: " << scr50_74 << endl;
cout << "75-99: " << scr75_99 << endl;
cout << "100-124: " << scr100_124 << endl;
cout << "125-149: " << scr125_149 << endl;
cout << "150-174: " << scr150_174 << endl;
cout << "175-200: " << scr175_200 << endl;

return 0;
}

SNAPSHOTS:

TEXT FILE "marks.txt":

OUTPUT:


Related Solutions

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,...
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...
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...
A psychologist has developed a personality test on which scores can range from 0 to 200....
A psychologist has developed a personality test on which scores can range from 0 to 200. The mean score of well-adjusted people is 100. It is assumed that the less well-adjusted an individual is, the more the individual’s score will differ from the mean value. The Dean of Students at XYZ University is interested in discovering whether the students at XYZ are well-adjusted, on average. Fifteen students are randomly sampled. Their scores are: 80, 60, 120, 140, 200, 70, 30,...
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.
Write a program that reads a file (provided as attachment to this assignment) and write the...
Write a program that reads a file (provided as attachment to this assignment) and write the file to a different file with line numbers inserted at the beginning of each line. Such as Example File Input: This is a test Example File Output 1. This is a test. (Please comment and document your code and take your time no rush).
Write a program that reads a file line by line, and reads each line’s tokens to...
Write a program that reads a file line by line, and reads each line’s tokens to create a Student object that gets inserted into an ArrayList that holds Student objects.  Each line from the file to read will contain two strings for first and last name, and three floats for three test grades.  After reading the file and filling the ArrayList with Student objects, sort the ArrayList and output the contents of the ArrayList so that the students with the highest average...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT