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

Please help me the C++ programing Question: Rewrite the solution to the Star Sea

ID: 3582379 • Letter: P

Question

Please help me the C++ programing

Question: Rewrite the solution to the Star Search problem, see page 370 Programming Challenges, to use a dynamic array. Read the number of judges from the standard input device. Make sure the user enters numeric input; make sure that number of judges is greater than 0. Create a dynamic array, using the new operator, to store the judges' scores.

Here is my code

#include<iostream>
#include<cstdlib>

using namespace std;

int numJudges;

void getJudgeData(double *);
double findLowest(double *);
double findHighest(double *);
double calcSum(double *);
void calcAverage(double *);

int main()
{

   double *scores;
   scores = new double[4];
   scores[0] = 12;
   scores[1] = 21;
   scores[2] = 35;
   scores[3] = 98;
   scores[4] = 72;

   cout << "5 judge socre is : " << endl;

   getJudgeData(scores);

   calcAverage(scores);

   system("pause");
   return 0;

}

void getJudgeData(double *score)
{
   double x;
   for (int i = 0; i<5; i++)
   {

       cout << score[i] << ", ";

   }
}

double findLowest(double *scores)
{

   double lowest = 11;
   for (int i = 0; i<5; i++)
   {
       if (scores[i]<lowest)
           lowest = scores[i];
   }
   return lowest;
}

double findHighest(double *scores)
{

   double highest = 0;
   for (int i = 0; i<5; i++)
   {
       if (scores[i]>highest)
           highest = scores[i];
   }
   return highest;
}

double calcSum(double *scores)
{
   double total = 0;
   for (int i = 0; i<5; i++)
   {
       total += scores[i];
   }
   return total;
}

void calcAverage(double *scores)
{
   double lowest = findLowest(scores);
   double highest = findHighest(scores);
   double sum = calcSum(scores);

   double average = sum / 5;

   cout << "Highest score of five numbers: " << highest << endl;
   cout << "Lowest score of five numbers: " << lowest << endl;
   cout << "Your average score is (including highest and lowest scores which you received) :" << average << endl;
}

Here is the list that I have to change the code

1, no numJudges a global variable. It should a function parameter.

2. using 5 as the array size for findHighest, findLowest, calcSum.

3. program will crash because the array's size is 4 and the loops try to read values from the 5th array position

4. should not have changed getJudgeData's parameter list.

5. program does reject the lowest and highest scores

Explanation / Answer

solution

#include<iostream>
#include<cstdlib>
using namespace std;
int numofJudges;
void getJudgeData(double *,int numofJudges);
double findLowest(double *,int numofJudges);
double findHighest(double *,int numofJudges);
double calcSum(double *,int numofJudges);
void calcAverage(double *,int numofJudges);

int main()
{
double *scores;
int number=0;
cout<<"enter the how many no of scores you want "<<endl;
  
cin>>numofJudges;
scores = new double[numofJudges];
for(int i=0;i<numofJudges;i++)
{
   cout<<"enter the score"<<endl;
   cin>>number;
   scores[i]=number;
   }
   cout<<"the scores are:"<<endl;
getJudgeData(scores,numofJudges);
calcAverage(scores,numofJudges);
system("pause");
return 0;
}
void getJudgeData(double *score,int numofJudges)
{
double x;
for (int i = 0; i<numofJudges; i++)
{
cout << score[i] << ", ";
}
}
double findLowest(double *scores,int numofJudges)
{
double lowest = scores[1];
for (int i = 0; i<numofJudges; i++)
{
if (scores[i]<lowest)
lowest = scores[i];
}
return lowest;
}
double findHighest(double *scores,int numofJudges)
{
double highest = 0;
for (int i = 0; i<numofJudges; i++)
{
if (scores[i]>highest)
highest = scores[i];
}
return highest;
}

double calcSum(double *scores,int numofJudges)
{
double total = 0;
for (int i = 0; i<numofJudges; i++)
{
total += scores[i];
}
return total;
}
void calcAverage(double *scores,int numofJudges)
{
double lowest = findLowest(scores,numofJudges);
double highest = findHighest(scores,numofJudges);
double sum = calcSum(scores,numofJudges);
double average = sum / numofJudges;
cout << "Highest score of five numbers: " << highest << endl;
cout << "Lowest score of five numbers: " << lowest << endl;
cout << "Your average score is (including highest and lowest scores which you received) :" << average << endl;
}

output

enter the how many no of scores you want
6
enter the score
1
enter the score
23
enter the score
35
enter the score
36
enter the score
85
enter the score
12
the scores are:
1, 23, 35, 36, 85, 12, Highest score of five numbers: 85
Lowest score of five numbers: 1
Your average score is (including highest and lowest scores which you received) :
32
Press any key to continue . . .