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
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...
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...
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 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...
Question 2: Write a C program that read 100 integers from the attached file (integers.txt) into...
Question 2: Write a C program that read 100 integers from the attached file (integers.txt) into an array and copy the integers from the array into a Binary Search Tree (BST). The program prints out the following: The number of comparisons made to search for a given integer in the BST And The number of comparisons made to search for the same integer in the array Question 3 Run the program developed in Question 2 ten times. The given values...
C Program Write a program to count the frequency of each alphabet letter (A-Z a-z, total...
C Program Write a program to count the frequency of each alphabet letter (A-Z a-z, total 52 case sensitive) and five special characters (‘.’, ‘,’, ‘:’, ‘;’ and ‘!’) in all the .txt files under a given directory. The program should include a header count.h, alphabetcount.c to count the frequency of alphabet letters; and specialcharcount.c to count the frequency of special characters. Please only add code to where it says //ADDCODEHERE and keep function names the same. I have also...
The Data A central tenet to being a good instructor, I believe, is to be a...
The Data A central tenet to being a good instructor, I believe, is to be a reflective practitioner of your craft. From time to time I find it to be necessary to review and reflect on my work as an instructor from a grade perspective. On our moodle page you will find a link to a second word document titled “300 Grades”. This data sheet contains both the alphanumeric grade (page 1) and the numerical equivalent (page 2) for every...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in Lab 2 to obtain a diameter value from the user and compute the volume of a sphere (we assumed that to be the shape of a balloon) in a new program, and implement the following restriction on the user’s input: the user should enter a value for the diameter which is at least 8 inches but not larger than 60 inches. Using an if-else...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT