Question

USE C++ TO WRITE THIS CODE, MUST USE AN ARRAY An unknown number of grades as...

USE C++ TO WRITE THIS CODE, MUST USE AN ARRAY

An unknown number of grades as integers, but no more than 30, are to be read from the file grades.dat. You may assume each grade will be a valid value between 0 and 100 (no validation necessary) and all "grades" are out of a maximum 100 points. Output the Number of Grades read in from the file. Calculate and output the Total Points Earned. Calculate and output the Total Possible Points. (Remember each grade is out of a possible 100 points max.) Following these, output each individual grade and its percentage of the Total Points Earned. Format these so that they are lined up in two columns. The first column should be 20 characters wide and contain the grade; the second column should be 8 characters wide containing the percentage. A percent sign should be output after the second field. The percentages should be rounded to the nearest tenth. Finally, output the Final Grade as a percentage, such that it lines up with second column previously. See the sample input and output that follows:

Sample Input: assuming grades.dat contained the following

100
95
87
90
76
            

Sample Output:

Number of Grades:           5
Total Points Earned:      448
Max Possible Points:      500

                 100    20.0%
                  95    19.0%
                  87    17.4%
                  90    18.0%
                  76    15.2%

Final Grade:            89.6%

Homework Answers

Answer #1

Here is code:

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

int main()
{
const int ISIZE = 30;
int grades[ISIZE];
int num, count = 0, total = 0;
ifstream dataFile;
dataFile.open(".\\files\\grades.dat");
if (!dataFile)
cout << "Error opening data file\n";
else
{ // Input daily grade
count = 0;
while (dataFile >> num && count < ISIZE)
{
grades[count] = num;
total += num;
count++;
}
cout << "Number of Grades: " << count << endl;
cout << "Total Points Earned: " << total << endl;
cout << "Max Possible Points: " << count * 100 << endl << endl;
// <<
for (int i = 0; i < count; i++)
{
cout << setprecision(1);
cout << fixed;
cout << std::setw(20) << grades[i] << std::setw(8) << (grades[i] / float(count * 100)) * 100 << "%" << endl;
}
cout << "\n\nFinal Grade:" << (total / float(count * 100)) * 100 << "%" << endl;

dataFile.close();
cout << endl;
}
return 0;
}

Output:

Know the answer?
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
Similar Questions
PART B- Javascript Using a text editor (VS Code or Notepad) and a web browser, you...
PART B- Javascript Using a text editor (VS Code or Notepad) and a web browser, you will demonstrate how to create an HTML file, externally link a JavaScript file, and write some source code in the JavaScript file. a..Create two blank files to be an HTML file and a JavaScript file. The file names should be partA.html and partA.js. b.. Create a basic HTML webpage structure. c..Link the JavaScript file to the HTML file using the <script> tag. d.. Prompt...
C++ Write a program that calculates and prints the total grade for n assignments as a...
C++ Write a program that calculates and prints the total grade for n assignments as a percentage. Prompt the user to enter the value of n, followed by the number of points received and number of points possible for each assignment . Calculate and print the total number of points received, total number of points possible, and the overall percentage: (total points received / total points possible) * 100. Output: Enter·number·of·assignments·to·input:3↵ Enter·number·of·points·received·for·assignment·1 :10↵ Enter·number·of·possible·points·for·assignment·1 :10↵ Enter·number·of·points·received·for·assignment·2 :7↵ Enter·number·of·possible·points·for·assignment·2 :12↵ Enter·number·of·points·received·for·assignment·3...
You've been hired by Text Turtles to write a C++ console application that determines the reading...
You've been hired by Text Turtles to write a C++ console application that determines the reading grade level of the text in a file. The text comes from two files: SampleText1.txt and SampleText2.txt. Sample text1= It has often been said there's so much to be read you never can cram all those words in your head. So the writer who breeds more words than he needs is making a chore for the reader who reads. That's why my belief is...
please write the code in java so it can run on jGRASP import java.util.Scanner; 2 import...
please write the code in java so it can run on jGRASP import java.util.Scanner; 2 import java.io.*; //This imports input and output (io) classes that we use 3 //to read and write to files. The * is the wildcard that will 4 //make all of the io classes available if I need them 5 //It saves me from having to import each io class separately. 6 /** 7 This program reads numbers from a file, calculates the 8 mean (average)...
we will be taking data in as a file. you cannot use the data values in...
we will be taking data in as a file. you cannot use the data values in your source file but you must read in everything into variables and use it from there. First we need to include <fstream> at the top of our file. We will need to create an input file stream to work and ifstream. ifstream is a datatype. Create a variable with the datatype being ifstream. Variable is drfine by using the member accessor operator to call...
Programing lanugaue is C++ Plan and code a menu-driven modular program utilizing an array An input...
Programing lanugaue is C++ Plan and code a menu-driven modular program utilizing an array An input file has an unknown number of numeric values(could be empty too).Read the numbers from the input fileand store even numbers in one arrayand odd numbers in another array.Create menu options to Display count of even numbers, count of odd numbersand the sum values in each array Determine the average of each array Determine the median of each array Sort each array in ascending order(use...
Machine Problem 3 - Linked List C++ For this assignment you will write a program that...
Machine Problem 3 - Linked List C++ For this assignment you will write a program that inserts 20 random integers from 0 to 100 in order in a linked list object. The program will create another linked list, but with 15 random integers from 0 – 100 in order. The program then will merge those two ordered linked list into a single ordered list. The function merge should receive references to each of the list objects to be merged and...
write a program that automates the process of generating the final student report for DC faculty...
write a program that automates the process of generating the final student report for DC faculty considering the following restrictions. Consider declaring three arrays for processing the student data: studID studName studGrade The student ID is a random number generated by the 5-digit system in the range of (10000 - 99999). Create a function to assign the student ID generated in an array of numbers. Consider the following to generate the random number: Add the libraries: #include <stdlib.h> #include <ctime>...
Using MATLAB or Octave, use documenting code to Write a script that prompts the user for...
Using MATLAB or Octave, use documenting code to Write a script that prompts the user for an integer between 0 and 9999, inclusive. The script should then calculate the digit in each of the 1000’s, 100’s, 10’s, and 1’s place of the number. Create a variable for each of the 4 extracted digits. For example, if your variables are named nThousands, nHundreds, nTens, and nOnes, then, in the case of 9471, they would be end up being set to 9,...
Using If and LookUp Formulas Formatting Grades Input boxes in tan Output boxes in yellow Given...
Using If and LookUp Formulas Formatting Grades Input boxes in tan Output boxes in yellow Given data in blue Answers in red Professor Streterstein is a bit absentminded. His instructor’s grade book is a mess, and he would like your help cleaning it up and making it easier to use. In Professor Streterstein’s course, the maximum possible points a student can earn is 750. The following table displays the grade equivalent to total points for the course. Professor Streterstein's Course...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT