126k views
5 votes
Modify your "Star Search" program to read 100 scores from a text file, then execute the "Star Search" algorithm (drop the lowest and highest scores, then average the rest) and display the result, with three digits after the decimal point. As per the Star Search specifications, only scores from 0 - 10 will be accepted. Any score that is outside that range is to be rejected, and is not included in the average. That means that invalid scores can't be the high or low scores either. For example (using 10 scores): if the list is 6.1 -5.1 2.0 3.5 5.8 2.0 12.9 5.0 9.9 10.0 The -5.1 and 12.9 are rejected as invalid (not in the range 0-10). 2.0 and 10.0 are the low and high scores to be dropped. The remaining SIX scores are averaged. If you wish to use this data for testing, the answer is 5.383

1 Answer

4 votes

Answer:

See explaination

Step-by-step explanation:

#include <fstream>

#include <iostream>

#include <iomanip>

#include <cstring>

#include <cstdlib>

#include <ctime>

#include <vector>

using namespace std;

void getJudgeData(double &score);

double calcScore(double scores[]);

int findLowest(double scores[]);

int findHighest(double scores[]);

int main() {

const int COL=5;

int row;

double score;

cout<<"How many students data you want to enter ? ";

cin>>row;

// Creating 2-D array Dynamically

double** scores = new double*[row];

for (int i = 0; i < row; ++i)

scores[i] = new double[COL];

for(int i=0;i<row;i++)

{

cout<<"\\Performer#"<<(i+1)<<":"<<endl;

for(int j=0;j<COL;j++)

{

cout<<"Enter Score given by judge#"<<(j+1)<<":";

getJudgeData(scores[i][j]);

}

}

for(int i=0;i<row;i++)

{

cout<<"Performer#"<<(i+1)<<" score :"<<calcScore(scores[i])<<endl;

}

return 0;

}

void getJudgeData(double &score)

{

while(true)

{

cin>>score;

if(score<0 || score>10)

{

cout<<"Invalid.Must be between 0-10"<<endl;

cout<<"re-enter :";

}

else

{

break;

}

}

}

double calcScore(double scores[])

{

double sum=0;

int min= findLowest(scores);

int max= findHighest(scores);

for(int i=0;i<5;i++)

{

if(i!=min && i!=max)

{

sum+=scores[i];

}

}

return sum/3;

}

int findLowest(double scores[])

{

double min=scores[0];

int minIndex=0;

for(int i=0;i<5;i++)

{

if(min>scores[i])

{

min=scores[i];

minIndex=i;

}

}

return minIndex;

}

int findHighest(double scores[])

{

double max=scores[0];

int maxIndex=0;

for(int i=0;i<5;i++)

{

if(max<scores[i])

{

max=scores[i];

maxIndex=i;

}

}

return maxIndex;

}

User Elie
by
4.4k points