Question

For this assignment, you are to write a program that does the following: (C++) • read exam scores...

For this assignment, you are to write a program that does the following: (C++)

• read exam scores from a file name data.txt into an array, and

• after reading all the scores, output the following to the monitor: the average score and the total number of scores.

In addition, the program must use the following functions:

//precondition: fileName is name of the file to open, inFile is the input file 2 of 2

//postcondition: inFile is opened. If inFile cannot be opened, a message is

// written to cout and the program exits void openFile(string filename, ifstream& inFile);

//precondition: a score array, size is a’s length //postcondition:avg contains score score average float calculateAverage(float a, int size) Remember to perform all required operations on the files, otherwise you receive a significant deduction. Failure to conform to the specification will result in significant deductions (up to 50 points).

Finally, every function must be commented with preconditions and post conditions. Failure to include these things will result in a 20 point deduction. Each line of the data file will contain a score. You can assume that each non-empty line in the file contains a score and nothing else. You can assume that there will be no more than 25 scores in the file, but there may be any number from two to 25.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>
#include<fstream>
#include<cstdlib>
using namespace std;
float calculateAverage(float a, int size)
{
   return a/size;
}
void openFile(string filename, ifstream& inFile)
{
   inFile.open(filename);
   if(!inFile)
   {
       cout<<"Unable to open the file exiting the prgram."<<endl;
       exit(0);
   }
   float scores[25],sum=0;
   int count=0;
   while(inFile>>scores[count])
   {      
       sum+=scores[count];
       count++;
   }
   cout<<"Sum of all the score grade is :"<<sum<<endl;
   cout<<"Avrage of the score is : "<<calculateAverage(sum,count)<<endl<<endl;
}


int main()
{
   ifstream inFile;
   openFile("grades.txt",inFile);
   return 1;
}

output

Sum of all the score grade is :1307.5 Avrage of the score is : 81.7188 Press any key to continue .. . - 01:37 26-04-2019 3 O

grades.txt

grades-Notepad File Edit Format View Help 7 8 1 8 9 9 8 8 8 6 6 6 99 8 7 8 85.5 Lni, Col 1 O Type here to search rP ^后偏恒di) E

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.

Add a comment
Know the answer?
Add Answer to:
For this assignment, you are to write a program that does the following: (C++) • read exam scores...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • For this assignment, you are to write a program that does the following: • read exam scores from a file name data.txt into an array, and • after reading all the scores, output the following to the mon...

    For this assignment, you are to write a program that does the following: • read exam scores from a file name data.txt into an array, and • after reading all the scores, output the following to the monitor: the average score and the total number of scores. In addition, the program must use the following functions: //precondition: fileName is name of the file to open, inFile is the input file 2 of 2 //postcondition: inFile is opened. If inFile cannot...

  • For this assignment, you are to write a program that does the following:  read temperatures...

    For this assignment, you are to write a program that does the following:  read temperatures from a file name data.txt into an array, and  after reading all the temperatures, output the following to the monitor: the average temperature, the minimum temperature, and the total number of temperatures read. In addition, the program must use the following functions: //precondition: fileName is name of the file to open, inFile is the input file //postcondition: inFile is opened. If inFile cannot...

  • Microsoft Visual Studios 2017 Write a C++ program that computes a student’s grade for an assignment...

    Microsoft Visual Studios 2017 Write a C++ program that computes a student’s grade for an assignment as a percentage given the student’s score and total points. The final score must be rounded up to the nearest whole value using the ceil function in the <cmath> header file. You must also display the floating-point result up to 5 decimal places. The input to the program must come from a file containing a single line with the score and total separated by...

  • The following program is in c++ ; I am trying to read in games from a...

    The following program is in c++ ; I am trying to read in games from a file and when doing so I am only reading in parts of the file. It is giving me a segmentation fault error I am going to post my code below if anyone is able to help me debug the program I would greatly appreciate it. The program is too large to be submitted as a single question on here :( --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- void Business::addGamesFromFile() {...

  • C++ please make it sifferent and unique Description Write a program that will read data from...

    C++ please make it sifferent and unique Description Write a program that will read data from the file "p6.dat". The file (that you will create) always contains 15 test scores (whole numbers between O and 100). The test scores are scores for 5 students taking 3 tests, and are arranged, in the file, by the student - that is the first 3 numbers are the test scores for test 1, 2, and 3 for the first student, etc. The program...

  • Can anyone help me with my C hw? Exercise 3 You will write a new program...

    Can anyone help me with my C hw? Exercise 3 You will write a new program that combines dynamically allocating an array and saving that array to a file. These are the tasks your program must perform Open an output file named "data.txt" and prepare it for writing in text mode o If the file handle is NULL, quit the program o By default, it is created and stored in the same directory as your source code file Prompt the...

  • In c++ Write a program that contains a class called Player. This class should contain two...

    In c++ Write a program that contains a class called Player. This class should contain two member variables: name, score. Here are the specifications: You should write get/set methods for all member variables. You should write a default constructor initializes the member variables to appropriate default values. Create an instance of Player in main. You should set the values on the instance and then print them out on the console. In Main Declare a variable that can hold a dynamcially...

  • C++ Redo PROG8, a previous program using functions and/or arrays. Complete as many levels as you...

    C++ Redo PROG8, a previous program using functions and/or arrays. Complete as many levels as you can. Level 1: (20 points) Write FUNCTIONS for each of the following: a) Validate #students, #scores. b) Compute letter grade based on average. c) Display student letter grade. d) Display course average. Level 2: (15 points) Use ARRAYS for each of the following. e) Read a student's scores into array. f) Calculate the student's average based on scores in array. g) Display the student's...

  • Use C++! This program uses the class myStack to determine the highest GPA from a list of students with their GPA.The program also outputs the names of the students who received the highest GPA. Redo t...

    Use C++! This program uses the class myStack to determine the highest GPA from a list of students with their GPA.The program also outputs the names of the students who received the highest GPA. Redo this program so that it uses the STL list and STL queue! Thank you! HighestGPAData.txt* 3.4 Randy 3.2 Kathy 2.5 Colt 3.4 Tom 3.8 Ron 3.8 Mickey 3.6 Peter 3.5 Donald 3.8 Cindy 3.7 Dome 3.9 Andy 3.8 Fox 3.9 Minnie 2.7 Gilda 3.9 Vinay...

  • CIS 22A C++ Project Exam Statistics Here is what your program will do: first it welcomes...

    CIS 22A C++ Project Exam Statistics Here is what your program will do: first it welcomes the user and displays the purpose of the program. It then prompts the user to enter the name of an input file (such as scores.txt). Assume the file contains the scores of the final exams; each score is preceded by a 5 characters student id. Create the input file: copy and paste the following data into a new text file named scores.txt DH232 89...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT