In: Computer Science
Write a program that will find the class average of fifteen (15) test scores for five (5) different tests. The class average must be stored into an integer array. You are to have three separate arrays: Note: _jd represents the initials of the programmer. Your array and function names should be named by replace the initials jd with your first and last initials Arrays Student Names Scores Averages Name of array students_jd scores_jd averages_jd Size of array [15][10] [15][5] .[5] Data for array Initialized in code Read from data file Calculated and stored Excluding the main function, your program should have three additional functions that will get the scores, calculate the averages and display your output. Functions Read Input File Calculate Average Output Results Name of function get_jd calc_jd prt_jd Properties of function Called from main Called from main Called from main Definition of Function Should pass scores array and add data to array Should pass average array and add averages to array Should pass students, scores and average array and print data Data file should be named da
I don't really understand what you wrote in the functions part...like properies of function called from main called from main called from main? If this isn't what you need or something you can't modify into what you're looking for let me know though.
#include<iostream>
#include<fstream>
using namespace std;
// define the classes
const int maxStudents = 15;
const int maxTests = 5;
void getData(ifstream &dFile, char students_id[15][10], int scores_id[15][5])
//assuming file looks like this per line, <studentID>< test1> <test2> <test3> <test4>< test5>
{
for(int i = 0; i < maxStudents; i++)
{
dFile >> students_id[i];
for(int j = 0; j < maxTests; j++)
dFile >> scores_id[i][j];
}
}
void calcAvg(int scores_id[15][5], float averages_id[])
{
float total;
for(int i = 0; i < maxStudents; i++)
{
total = 0.0;
for(int j = 0; j < maxTests; j++)
total += scores_id[i][j];
averages_id[i] = total / 5.0;
}
}
void printResults(char students_id[15][10], float averages_id[])
{
for(int i = 0; i < maxStudents; i++)
{
cout << students_id[i] << "'s average: " << averages_id[i] << endl;
}
}
int main()
{
char students_id[maxStudents][10];
int scores_id[maxStudents][5];
float averages_id[maxStudents];
ifstream dFile; //variables declared
if(dFile.good()) dFile.open("data_jd.txt", ios::in); //data file opened for input
getData(dFile, students_id, scores_id); //fill up arrays with data
calcAvg(scores_id, averages_id);
printResults(students_id, averages_id);
dFile.close(); //closes data file
system("pause");
return 0;
}
---
data file tested with
student01 51 88 57 91 88
student02 84 68 70 66 95
student03 97 61 53 76 76
student04 79 72 90 54 62
student05 65 92 75 90 73
student06 82 56 79 93 70
student07 72 88 79 50 95
student08 71 94 62 70 97
student09 83 73 82 84 65
student10 100 76 79 73 60
student11 52 70 50 57 62
student12 67 84 61 51 74
student13 94 78 94 86 92
student14 79 62 98 79 59
student15 55 77 55 82 84