# Calculate the average grade and standard deviation for the class. C++ help

### Question

• Input a class of student grades and stude

nt numbers. Calculate the average grade and standard deviation for the class. Print the student number and student grades in ascending order of the student grade.
Print the grade assigned to each student and the average for the class and the standard deviation. Assume the class has no more than 30 students.

input data
student number scores
321 60.5
542 50.5
524 75.0
235 83.0
565 95.5
123 65.0
257 75.6
258 79.5
259 45.6
260 99.0
261 94.5

Declare an array to hold the student numbers (int student[30]).
Declare another array to hold the corresponding scores
(float scores[30]).

This is my code:

#include <iostream>
#include <fstream>
#include <conio.h>
#include <cmath>
using namespace std;
#define in_file "data.txt"
#define out_file "result.txt"
int main ()
{
ifstream ins; // associates ins as an input stream
ofstream outs; // associates outs as an output stream
int student[30];
int count = 0;
float scores[30];
int counter = 0;

ins.open(in_file);
outs.open(out_file);
while (!ins.eof())
{
ins >> student[counter] >> scores[counter];
counter++;
ins.get(next_char); // to skip the end of line character
}
for (int i = 0; i < counter; i++)
{
cout << student[i] << " " << scores[i] << endl;
}
for (int i = counter -2; i >= 0 ; i = i – 1)
for (int j = 0; j <= i; j++)
if (scores[j] > scores[j + 1])
{
swapFloat (scores[j], scores[j + 1]);
swapInteger(student[j], student[j + 1]);
}

for (int i = 0; i < counter; i++)
if (scores[i] >= 90.0)
else if (scores[i] >= 80.0)
else if (scores[i] >= 70.0)
else if (scores[i] >= 60.0)
ins.close (); // closing input file
outs.close (); // closing output file
}
float findaverage(float scores[], int size)
{
float sum = 0.0;
// summing all the scores
for (int i = 0; i < size; i++)
sum = sum + scores[i];
// return the average which is sum divided by no of students
return sum/size;
}

float findsdev(float scores[], int size, float average)
{
float sumofdifference = 0.0;
for (int i = 0; i < size; i++)
{
sumofdifference += ((scores[i]) – average) * ((scores[i]) – average);
}
return sqrt (sumofdifference / size);
}

appreciate it

Thursday, March 10, 2011 7:08 AM

### All replies

• >appreciate it

Umm, appreciate what exactly?

I don't see any questions in your posts, or any description
of problems you're having. What are you expecting from
denizens of this forum?

Note that we avoid doing course assignments for students.
We will usually help by making suggestions for improvement
or in explaining why something doesn't work as desired.

But you need to explain what your problems are.

- Wayne
Thursday, March 10, 2011 7:23 AM