Question: Chapter 16 Programming Exercise #20 C++ Programming: From Problem Analysis to Program Design ***Every time I run my program my output seems to output a

Chapter 16 Programming Exercise #20

C++ Programming: From Problem Analysis to Program Design

***Every time I run my program my output seems to output a long string of numbers as well as provide me a warning as my int variables of index and iteration are unused variables.

I am wanting to know how to fix this problem so that I could get a correct output and to fix any errors and warnings that may arise when running and/or building this program.

"main.cpp"

//Header files #include #include #include #include

//Standard Library using namespace std;

//Declare Global constant values const int NUMBER_OF_PEOPLE = 10; const int NUMBER_OF_TESTS = 5;

//Function prototypes void read(string names[], int nameSize, double scores[][NUMBER_OF_TESTS], int scoresRowSize);

void calculate(double matrix[], double scores[][NUMBER_OF_TESTS], int scoresRow_Size);

void print(double matrix[], string names[], int namesSize);

void sort(double matrix[], string names[], int namesSize);

//Step into function main int main() { //Declaring arrays string names[NUMBER_OF_PEOPLE]; double scores[NUMBER_OF_PEOPLE][NUMBER_OF_TESTS]; double grades[NUMBER_OF_PEOPLE];

//Calling read function read(names, 10, scores, 10);

//Calling calculate function calculate(grades, scores, 10); cout

//Calling print function print(grades, names, 10);

//Calling sort function sort(grades, names, 10); cout

//Display sorted data print(grades, names, 10);

return 0; }//end function main

//Function prototype definitions

//Function read void read(string names[], int namesSize, double scores[][NUMBER_OF_TESTS], int scoresRowSize) { ifstream infile;

//open file for reading data infile.open("input.txt"); int counterNames = 0, counterScores = 0;

//reading data from file and placing in arrays while(counterNames > names[counterNames]; while (counterScores > scores[counterNames][counterScores]; counterScores++; } counterScores = 0; counterNames++; } }//End read function

//Function definition to calculate grade void calculate(double matrix[], double scores[][NUMBER_OF_TESTS], int scoresRow_Size) { //Declare and initialize local variables int counter = 0; int num = 0; double total = 0; double average = 0;

cout

//Calculating grade while (counter

num++; } average = (total / NUMBER_OF_TESTS); matrix[counter] = average; total = 0; average = 0; num = 0;

counter++; } }//End Calculate function

//Function definition to print data void print(double matrix[], string names[], int namesSize) { cout

counter++; } }//End print data definition

//Sorting function to sore the names and scores void sort(double matrix[], string names[], int namesSize) { //Variable declaration string temp; double tem; int iteration; int index;

//Bubble sort to sort arrays for (int iteration = 0; iteration names [index + 1]) { //swap names temp = names[index]; names[index] = names [index + 1]; names[index + 1] = temp;

//Swap average scores tem = matrix[index]; matrix[index] = matrix[index + 1]; matrix[index + 1] = tem; } }//End of inner loop }//End of outer loop }//End of function

 Chapter 16 Programming Exercise #20 C++ Programming: From Problem Analysis to

"Input.txt"

Johnson 85 83 77 91 76 Aniston 80 90 95 93 48 Cooper 78 81 11 90 73 Gupta 92 83 30 69 87 Blair 23 45 96 38 59 Clark 60 85 45 39 67 Kennedy 77 31 52 74 83 Bronson 93 94 89 77 97 Sunny 79 85 28 93 82 Smith 85 72 49 75 63

eJ varning : unused variable 'index' [-Wunused-variable]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!