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...
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...
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,...
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).
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
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.
Write a program that reads a file called document.txt which is a text file containing an...
Write a program that reads a file called document.txt which is a text file containing an excerpt from a novel. Your program should print out every word in the file that contains a capital letter on a new line to the stdout. For example: assuming document.txt contains the text C++
Write a program that reads in characters until end of file. The program should count and...
Write a program that reads in characters until end of file. The program should count and print the number of characters, printable characters, vowels, digits, and consonants in the input. Use functions to check whether a character is a vowel, a consonant, or a printable character. Define and use macros to test if a character is a digit or a letter.
Write scores of 20 students on a quiz to a file. The file should be named...
Write scores of 20 students on a quiz to a file. The file should be named scores.txt. The scores should be random numbers between 0-10. Next, read the scores from scores.txt and double them and print the scores to screen. c++
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT