c++ Write a summary report file that contains the average percent of total point
ID: 3661808 • Letter: C
Question
c++
Write a summary report file that contains the average percent of total points and maximum points for all students. Also, display the number of A's, B's, C's, D's and F's for the students. Your summary output file should look something like this:
Program requirements
You must use at least 2 one-dimension arrays - one for the student's 8 assignment grades and one for all the student total percents. Do not use 2 dimensional arrays - this will be covered in the next assignment.
Your solution must include at least 4 functions. One function must include an array argument and at least one must include a "pass by reference".
All files must be checked for a successful open. They should also be closed when you are finished with them.
Make sure you write the student id with a leading 0, if appropriate (i.e. the 7th id).
The percent of total points must be rounded to the nearest integer. For example, 377 points is 94%, 378 points is 95% and 379 points is 95%.
The letter grade is determined by the "integer" percent. For example, 350 points becomes 88% becomes B+.
Add headings to your output report file. They should be aligned and correctly identify the column data.
Email your source code. Your code will be checked for the output files.
Explanation / Answer
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
using namespace std;
// function to get average of total average points
static double getAverage(double[] avg, int size){
double total = 0;
for(int i=0;i<size;i++){
total = total + avg[i];
}
return total/size;
}
// function to get average of total maximum points
static int getAvgMaximumPoints(int[] max, int size){
int total = 0;
for(int i=0;i<size;i++){
total = total + max[i];
}
return total/size;
}
//method to get number of grades count
static void getGradesCount(int *grades, double[] avg, int size){
int a=0,b=0,c=0,d=0;
for(int i=0;i<size;i++){
if(avg[i]>90){
a++;
}
else if(avg[i]>85){
b++;
}
else if(avg[i]>80){
c++;
}
else{
d++;
}
grades[0]= a;
grades[1]= b;
grades[2]= c;
grades[3]= d;
}
}
int main()
{
std::ifstream readfile("file.txt");//reding numbers from text file
std::string eachline;
int count=0;
double average[10];
int maximum[10];
while (std::getline(readfile, eachline))
{
std::istringstream iss(eachline);
double avg;
int max;
while (iss >> avg >> max)//reading each value from file
{
average[count] = avg;
maximum[count] = max;
count++;
}
}
//calling functions
int grades[4];
double avg = getAverage(average,count);
int avgMax = getAvgMaximumPoints(maximum,count);
getGradesCount(grades,average,count);
//outputting to file
ofstream out_data("output.txt");
out_data<<"******************Total Ouptut Report data**************";
out_data << " Number of A's = "<<grades[0];
out_data << " Number of B's = "<<grades[1];
out_data << " Number of C's = "<<grades[2];
out_data << " Number of D's = "<<grades[3];
out_data<<" Average percent = : "<<positive;
out_data<<" Total Negative Numbers are: "<<avg;
out_data<<" Maximum points = "<<avgMax;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.