Code:
#include <iostream>
#include <string>
using namespace std;
//structures
struct StudentRecords
{
string name;
int id;
int scores[4];
double avg;
char grade;
};
StudentRecords getStudent();
void fillRecs( StudentRecords [], int);
void display( const StudentRecords [], int);
void main()
{
//Declare and Allocate Record
StudentRecords student[5];
fillRecs(student, 5);
display(student, 5);
}
StudentRecords getStudent()
{
StudentRecords student;
double a = 0;
cout << "Enter student name ----> ";
getline(cin, student.name);
cout << endl;
cout << "Enter student ID number ---> ";
cin >> student.id;
cout << endl;
cout<<"Enter the student scores: ";
for(int i=0; i<4; i++)
{
cin>>student.scores[i];
a+= student.scores[i];
}
a = a/4;
student.avg = a;
cout<<endl;
return student;
}
void fillRecs( StudentRecords r[], int n)
{
for( int i=0; i<n; i++)
r[i] = getStudent();
}
void display( const StudentRecords r[], int n)
{
for( int j=0; j<n; j++)
{
cout << "Name " << r[j].name << endl;
cout<<"id: "<<r[j].id<<endl;
cout<<"Scores: ";
for(int i=0; i<4; i++)
cout<<r[j].scores[i]<<" ";
cout<<endl;
cout<<"avg: "<<r[j].avg<<endl;
}
}