#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
// Defining structure to store Student Grade records
struct Student {
string name;
int s1;
int s2;
int s3;
int s4;
float avg_grade;
};
//Defining function to compute average for a student
float average_grade(float a,float b,float c,float d){
float avg=(a+b+c+d)/4;
return avg;
}
//Defining function to display the details in array
void display(Student m[5])
{
cout << "Displaying array contents: "<< endl;
for (int i = 0; i < 5; i++)
{
cout << "Name: " << m[i].name << endl;
cout <<"Average: " <<fixed<<setprecision(2)<< m[i].avg_grade <<"\n"<<endl;
}
}
int main()
{
string names[]={"Spider_man","Iron_man","Black_panther","Dr.Strange","Thor"};
float exams[][4]={{98,96,93,88},{60,91,99,74},{95,85,94,88},{100,100,99,100},{58,83,76,60}};
Student* GradeList;
GradeList = new (nothrow) Student[5]; //created dynamic array of structures
for(int i=0;i<5;i++){ //floating the dynamic array with the students details
GradeList[i].name = names[i];
GradeList[i].s1=exams[i][0];
GradeList[i].s2=exams[i][1];
GradeList[i].s3=exams[i][2];
GradeList[i].s4=exams[i][3];
GradeList[i].avg_grade = average_grade(exams[i][0],exams[i][1],exams[i][2],exams[i][3]); //storing average
}
display(GradeList);
return 0;
}
Note: Please do this in C++ Currently, Marvel Academy's student grade records are stored parallel arrays...