Please help me complete this code to calculate the average using the following p
ID: 3659261 • Letter: P
Question
Please help me complete this code to calculate the average using the following prototype
double findAverage(Student &myArray, int sz); and call it back to the main function
#include <iostream>
#include <string>
using namespace std;
struct Student{
string firstname, lastname;
int ID;
int score;
};
double findAverage(Student &myarray,int size){//function to find the average of the array values
int sum=0;
double avg;
for(int i=0;i<size;i++){//calculates the to total
sum+= myarray[i].score;
}
avg= (double)sum/(double)size;
return avg;
}
int main()
{
int counter = 1;
cout<<"Enter the size of the array: ";
int sz; cin>>sz;
Student *sPtr = new Student[sz];
cout<<"Let's populate the array ";
for(int i=0; i<sz; i++)
{
cout<<"Enter the firt name followed by last name: ";
cin>>sPtr[i].firstname;
cin>>sPtr[i].lastname;
cout<<"Enter ID for "<<sPtr[i].firstname<<": ";
cin>>sPtr[i].ID;
cout<<"Enter score for "<<sPtr[i].firstname<<": ";
cin>>sPtr[i].score;
cout<<endl;
}
cout<<"Let's print the class list ";
cout<< " Sl FirstName LastName ID Grade";
for(int i=0; i< sz; i++) {
cout<< " "<<counter++<<" "<< sPtr[i].firstname<< " "<< sPtr[i].lastname<< " "<<sPtr[i].ID<< " "<< sPtr[i].score<<endl;
}
}
Explanation / Answer
/ Includes #include #include #include using namespace std; //Function Prototype double mean(double[] , int size); double standardDev(double[] , int size, double mean); // Start of Main int main () { //Variables int arraySize = 50; double number = [50]; // Prompt the user about the program coutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.