# average grade and standard deviation for the class C++ help check code

Page 1 of 1

## 1 Replies - 2293 Views - Last Post: 10 March 2011 - 06:17 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=221206&amp;s=494780902b57871929f8d30f3c719a05&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 persons

• New D.I.C Head

Reputation: 1
• Posts: 17
• Joined: 23-February 11

# average grade and standard deviation for the class C++ help check code

Posted 10 March 2011 - 12:11 AM

Input a class of student grades and student 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]).

Here is a code I tried:
```
#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)
else grades[i] = 'F';
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);
}
```

Is This A Good Question/Topic? 0

## Replies To: average grade and standard deviation for the class C++ help check code

• Saucy!

Reputation: 6219
• Posts: 23,965
• Joined: 23-August 08

## Re: average grade and standard deviation for the class C++ help check code

Posted 10 March 2011 - 06:17 AM

Are you receiving any errors? Does this code not work that way you intended it? When asking for help there are a couple items that are vital in order for someone to properly help you:
• Post the code you're having problems with
• Post the exact error you're receiving, if you are receiving one
• If no error explain what the code is doing versus what you want it to do
• Post your question in the body of your post, not the description field