I am a beginner to C++ and I am having some issues with my output of my code. Here is the question.
----------------------------------------------------------------------------------------------------------------
Project objective: write a program that takes a list of final scores for a class and determines: 1) the mean (Greek letter mu), 2) the standard deviation (Greek letter sigma), and 3) the number of grades in each category (A, A-, B+, B-, C+, C, C-, D+, D, and F).
Prompt the user for the name of a file containing the final scores, up to 100 scores, such as (without the commas):
100, 94, 59, 83, 57, 11, 92, 76, 37, 89, 74, 59, 65, 79, 49, 89, 89, 75, 64, 82, 15, 74, 82, 68, 92, 61, 33, 95, 91, 82, 89, 64, 43, 93, 86, 65, 72, 40, 42, 90, 81, 62, 90, 89, 35, 81, 48, 33, 94, 81, 76, 86, 67, 70, 100, 80, 83, 78, 96, 58
Note: m = 71.47 s = 20.98
Determine the maximum score, the minimum score, the range of scores (maximum – minimum) and a table with column headings:
Grade
Number of scores
using the following scoring (where m is the mean, s is the standard deviation, and x is an individual score):
A : m+ 4/3 s <= x
A– : m+ 3/3 s <= x < m+ 4/3 s
B+ : m+ 2/3 s <= x < m+ 3/3 s
B : m+ 1/3 s <= x < m+ 2/3 s
B– : m+ 0/3 s <= x < m+ 1/3 s
C+ : m– 1/3 s <= x < m+ 0/3 s
C : m– 2/3 s <= x < m– 1/3 s
C– : m– 3/3 s <= x < m– 2/3 s
D+ : m– 4/3 s <= x < m– 3/3 s
D : m– 5/3 s <= x < m– 4/3 s
F : x < m– 5/3 s
----------------------------------------------------------------------------------------------------------------
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
#include <iostream>
#include <cmath>
#include <fstream>
#include <iomanip>
using namespace std;
float deviation(float sum, float mean, float N);
float mean(float vector[], int size);
float sum(float vector[], int size);
int main()
{
ifstream inFile;
float N;
int size = 0;
const int Numlist = 1000;
float totalSum;
float avg = 0.0;
int max = 100;
int min = 11;
double m = 71.47;
double s = 20.98;
double List[Numlist];
inFile.open("input.txt");
if (inFile.fail())
{
cout << "Error: could not open input.txt" << endl;
exit(EXIT_FAILURE);
}
for (int count = 0; count < Numlist; ++count){
inFile >> List[count];
if (!inFile)break;
}
float standard_deviation[100];
inFile >> N;
while ((!inFile.eof()) && (size<Numlist))
{
standard_deviation[size] = N;
size++;
inFile >> N;
}
totalSum = sum(standard_deviation, size);
avg = mean(standard_deviation, size);
cout << "Standard Deviation = " << deviation(totalSum, avg, size) << endl;
cout << "Mean = " << mean(avg) << endl;
cout << "Maximum Score = " << max << endl;
cout << "Minimum Score = " << min << endl;
cout << "Range = " << (max - min) << endl;
cout << "Grade" << "\t" << "Number of Scores" << "\t" << endl;
system("pause");
return 0;
}
//-----------------------------
//Sum Function
//-----------------------------
float sum(float vector[], int size)
{
float theSum;
theSum = 0.0;
for (int N = 0; N < size; N++)
{
theSum += vector[N];
}
return theSum;
}
//-----------------------------
//Mean Function
//-----------------------------
float mean(float vector[], int size)
{
float sum = 0.0, mean = 0.0;
for (int i = 0; i < size; i++)
{
mean += vector[size];
}
if (size == 0)
mean = 0.0;
else
mean = mean / size;
return mean;
}
//-----------------------------
//Deviation function
//-----------------------------
float deviation(float sum, float mean, float N)
{
double S;
double U;
U = (pow(sum - mean, 2));
S = (sqrt(U / N));
return S;
}
|
I believe my issue is in the Mean function, I am getting an error for (avg) at line 51:
cout << "Mean = " << mean(avg) << endl;
"Error: argument of type "float" is incompatible with parameter of type "float*"
I cant seem to find the issue.
I am also having issues trying to understand how to format the table, and how to categorize the individual grades into the correct letter grades.