Howdy all, my assignment is to define a structure for student grade records.
define a structure for student grade records.
2. declare an array of records and allocate on the Heap.
3. populate from the parallel arrays.
4. define a function to compute average and
populate average field.
5. define a function to display name and average.
6. demonstrate your functions and program
I am getting an error on line 10 saying i need to return an int? But it is a void function so it should work. Also any help with how to get my average to work would be awesome!
Also, your main function has a "return 0;" (line 18) at then end. Take that out, should fix your compile error
Why don't you try creating a variable in your structure that acts as an accumulator of grades, then divides by the amount of scores input? This could be easier.
That will create an array to store those structure variables, for each planet. Then you can modify your accumulator to traverse through each index and sum up the score for each student
1 2 3 4 5 6
int i = 0;
While ( i < sizeofarray)
{
structname.average += structname.testScore[i];
i++;
}
#include <iostream>
#include <iomanip>
#include "studentrec.h"
usingnamespace std;
studentrec populateRecord();
void computeavg ( studentrec& );
void showRecord( const studentrec& );
int main()
{
studentrec p = populateRecord();
//computeavg( p );
showRecord( p );
return 0;
}
studentrec populateRecord()
{
studentrec t;
cout<<"Enter Name: ";
getline( cin, t.name );
cout<<"Enter scores: ";
cin >> t.score_t[4];
cout<<endl;
return t;
}
void computeavg(studentrec& p)
{
int i = 0;
while ( i < 4)
{
p.avg += p.score_t[i];
i++;
}
}
void showRecord( const studentrec& p )
{
cout<<fixed<<setprecision(2);
cout<<"Name: "<<p.name<<endl
<<"Scores: "<<setw(8)<<p.scores_t[4]<<endl
<<"Average: "<<setw(8)<<p.avg<<endl
<<endl;
}
//header
include <string>
usingnamespace std;
struct studentrec //user defined data type
{
string name; //fields(structure members)
double avg;
int score_t[4];
}
Not sure if i declared that correctly in my header, or used it correctly in my code for that matter. I appreciate your patience, i just took 3 tests today so i am a bit frazzled still.