Question

In: Computer Science

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++

Solutions

Expert Solution

Program:

#include <iostream>

#include <ctime>

#include <iomanip>

#include <fstream>

using namespace std;

int main()

{

srand(time(0)); //seed random number generator

int scores[20],a; // variable declaration

ifstream infile; // input file declaration

ofstream outFile("scores.txt"); // output file declaration

infile.open("scores.txt"); // Syntax for open the file

for(int i=0;i<20;i++)

{

scores[i] = rand() %11; // random number between 0 and 10

outFile <<scores[i]<<endl; // write the scores into the file

}

cout<<"Double the scores in the file:"<<endl;

while (infile >> a) // read the file content

{

int doubleScore=2*a;

cout<<doubleScore<<" "; // store the values in file

}

infile.close(); // close the file

cout<<endl;

return 0;

}

Output:

Any doubts leave a comment

Please Rate My Answer


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 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 class named UpperCaseFile. The class's constructor should accept two file names as arguments. The...
Write a class named UpperCaseFile. The class's constructor should accept two file names as arguments. The first ofile should be opened for reading and the second file should be opened for writing. The class should read the contents of the first file, change all characters to uppercase, and store the results in the second file. The second file will be a copy of the first file, excpet all the characters will be uppercase. Use notepad or another text editor to...
Write a program that creates an output file named rand_nums.txt. Open the file and write 100...
Write a program that creates an output file named rand_nums.txt. Open the file and write 100 random integers between -50 and +50 (inclusive) to the file. Be sure to handle any file IO exceptions. Remember to close the file. Write a program that opens rand_nums.txt for input. Create two output files pos.txt and neg.txt. Read through the input file, one line at a time, converting each line into an integer (no exception handling, yet). If the number is positive, write...
A) Quiz scores of statistics students were obtained by a teacher and listed below. Construct a...
A) Quiz scores of statistics students were obtained by a teacher and listed below. Construct a frequency distribution beginning with a lower class limit of 0 and use a class width of 2. What frequency is listed for the third class? 0, 4, 5, 4, 3, 6, 8,2, 4, 10 B) A frequency table of grades has five classes (A, B, C, D, F) with frequencies of 23, 24, 12, 7, and 24 respectively. Using percentages, what are the relative...
The table below shows the scores of a group of students on a 10-point quiz. Test...
The table below shows the scores of a group of students on a 10-point quiz. Test ScoreFrequency 3 4 4 3 5 3 6 2 7 1 8 1 9 1 10 6 The mean score on this test is: The median score on this test is
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...
A group of students takes a 10 point quiz. You have the scores for each student...
A group of students takes a 10 point quiz. You have the scores for each student and decide to calculate the correlation between (a) the number of correct answers on the quiz with (b) the number of incorrect answers on the quiz. A. What would r equal? If you’re stuck, think about this a bit. If you’re really stuck, it may help to make a scatterplot based 10 students getting various scores on the quiz. _________________ (1 point) B. How...
A statistics professor gave a 5-point quiz to the 50 students in his class. Scores on...
A statistics professor gave a 5-point quiz to the 50 students in his class. Scores on the quiz could range from 0 to 5: The following frequency table resulted: (1.5 points) Quiz Score f rf cf crf c% 5 4 .08 50 1.00 100% 4 10 .20 46 .96 96% 3 14 .28 36 .72 72% 2 10 .20 22 .44 44% 1 8 .16 12 .24 24% 0 4 .08 4 .08 8% 1. Compute the values that define...
Student scores on a chapter quiz are:
Student scores on a chapter quiz are:                 6 3 4 9 7 5 5 2 10 9 8 4 4 7 6 3 2 10 9 5 a) Find the mean, median, mode and midrange for this data. b) Find the range, standard deviation and variance for this data. c) Find the z-score for the value 7 and the cutoffs for the data set that are considered unusual.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT