Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is a C++ Question. Write a program that dynamically allocates an array larg

ID: 3760614 • Letter: T

Question

This is a C++ Question.

Write a program that dynamically allocates an array large enough to hold a user-defined number of test scores. Once all the scores are entered by the user, the array must be passed to a function that sorts them in ascending order. It must use another function that calculates the average score. The program should display the sorted list of scores and average with appropriate headings. The program must use pointer notation instead of array notation. Validation: Do not accept negative numbers for test scores; keep prompting the user for a new grade. Do not accept negative numbers for the number of scores the user wants to enter. The output should look like this:

Score

67.40

67.80

77.60

99.60

Average Score: 78.10

Program must have the following functions

void getGrades(double* score, int size)

void displayGrades(double* score, int size, double avg)

void sort(double* score, int size)

double average(double* score, int numScores)

Explanation / Answer

#include <iostream>

using namespace std;
//method to display grades
void getGrades(double* score, int size){
double tot=0;
for(int i=0;i<size;i++){
tot = tot + score[i];
}
tot = tot/size;
if(tot > 80){
cout<<" A grade";
}
else if(tot > 70){
cout<<" B grade";
}
else{
cout<<" C grade";
}
}
//final displaying score details and average calculated too...
void displayGrades(double* score, int size, double avg){
for(int i=0;i<size;i++){
cout<<" "<<score[i];
}
cout<<" Average: "<<avg;
}
void sort(double* score, int size){
double temp;
//looping through array
for (int i = 0 ; i < ( size - 1 ); i++)
{
for (int j = 0 ; j < size - i - 1; j++)
{
if (score[j] > score[j+1]) //sorting ascending order
{
temp = score[j]; //swapping values
score[j] = score[j+1];
score[j+1] = temp;
}
}
}
}
//calculate sum of all array values and return sum/total as average
double average(double* score, int numScores){
double average;
double tot=0;
for(int i=0;i<size;i++){
tot = tot + score[i];
}
average = tot/size;
return average;
}
int main()
{
int N=20;
//dynamic array declared
double** arr = new double*[N];
cout<<"Enter scores: ";
//reading scores from user
for(int i=0;i<5;i++){
cin>>arr[i];
}
//calling methods
sort(*arr,5);
double avg = average(*arr,5);
displayGrades(*arr,5,avg);
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote