C++
//StudentDataStructure.txt
//Student records are stored in a parallel-array Data Structure. Here is the code to generate and populate Parallel-Array Data Structure:
const int NG = 4; //Number of Grades
string names[] = {"Amy Adams", "Bob Barr", "Carla Carr",
"Dan Dobbs", "Elena Evans"
};
int exams[][NG]= { {98,87,93,88},
{78,86,82,91},
{66,71,85,94},
{72,63,77,69},
{91,83,76,60}
};
---------------------------------------------------------------------------------
1 A) Create and Populate a Parallel-Array Data Structure using the code described in "StudentDataStructure.txt". B) Define a Record Data Structure for student records. It should have the same fields that you defined in the Parallel-Array Data Structure(part 1A) with additional fields for average test scores and grade.
2) Declare an array of records.
3) Populate the Record Data Structure with the data which resides in the Parallel-Array Data Structure(part 1A).
4) Define a function to display formatted student records.
5) Define a function to compute average and the populate average
field for each record.
6) Define a function to compute the grade and
the populate grade field for each record.
7) Define a function to compute class average.
8) Define a function to compute class standard deviation.
9) Display class average and standard deviation.
//C++ Code
#include<iostream>
#include<iomanip>
using namespace std;
struct Record {
string name;
int exams[4];
double average=0;
char grade = ' ';
};
/* a function to compute class standard deviation.*/
double calculateSDV(Record records[], int size);
/*a function to compute class average.*/
double calculateClassAvg(Record records[], int size);
/* a function to display formatted student records*/
void displayRecords(Record records[], int size);
/**
function to compute average and the populate average field for each record.
*/
void calculateAverage(Record records[], int size);
/*a function to compute the grade and
the populate grade field for each record.*/
void calculateGrade(Record records[], int size);
double calculateSDV(Record records[], int size)
{
double sdv = 0.0;
double mean = calculateClassAvg(records, size);
for (int i = 0; i < size; i++)
sdv += pow(records[i].average - mean, 2);
return sqrt(sdv / size);
}
double calculateClassAvg(Record records[], int size)
{
double total = 0;
for (size_t i = 0; i < size; i++)
{
total += records[i].average;
}
return total / size;
}
void calculateGrade(Record records[], int size)
{
for (size_t i = 0; i < size; i++)
{
if (records[i].average >= 80)
records[i].grade = 'A';
else if (records[i].average < 80 && records[i].average >= 60)
records[i].grade = 'B';
else if (records[i].average >= 40 && records[i].average < 60)
records[i].grade = 'C';
else
records[i].grade = 'D';
}
}
void calculateAverage(Record records[], int size)
{
double total = 0;
for (size_t i = 0; i < size; i++)
{
total = records[i].exams[0] + records[i].exams[1] + records[i].exams[2] + records[i].exams[3];
records[i].average = total / 4;
}
}
void displayRecords(Record records[], int size)
{
cout << fixed << setprecision(2);
for (int i = 0; i < size; i++)
{
cout << "(" << (i + 1) <<") Student's Name: "<<left<<setw(15)<<records[i].name<< "Marks are: " << records[i].exams[0]
<< " " << records[i].exams[1] << " " << records[i].exams[2]
<< " " << records[i].exams[3] << " Average: " << right << " " << records[i].average << " Grade: " << records[i].grade << endl;
}
}
int main()
{
/* Declare an array of records.*/
Record records[] = { {"Amy Adams",{98,87,93,88}} ,
{"Bob Barr", {78,86,82,91}},
{"Carla Carr",{66,71,85,94}},
{"Dan Dobbs",{72,63,77,69}},
{"Elena Evans",{91,83,76,60}} };
displayRecords(records, 5);
calculateAverage(records, 5);
calculateGrade(records, 5);
cout << endl;
displayRecords(records, 5);
double classAvg = calculateClassAvg(records, 5);
double sdv = calculateSDV(records, 5);
cout << "Class Average: " << classAvg << "\nStandard Deviation: " << sdv << endl;
return 0;
}
//Output
//If you need any help regarding this solution....... please leave a comment. thanks
Get Answers For Free
Most questions answered within 1 hours.