Recreating a Function to Reflect Passing Two Arrays

Hello,

I have an assignment for my Intermediate C++ programming class that is coming due very soon.

I searched the C++ Forum here, and Googled help with the assignment, looked through the C++ tutorial, and the reference page here, but not the help that I am specifically looking for, but it was interesting to see how different programs were written.

(The actual assignment is below my comments/questions)

I am thinking that I need to search the getTestScores array to find the students with the highest grade. Is that correct, or do I need to search another array for the highest grade?

I am thinking how am I need to recreate the getLowest function to reflect passing the string stuNames[5] and double studGrades[5] into it. Any suggestions/tips/questions on how to do that?

I am thinking that I need to create a getHighest function to display the name of the student with the highest grade. And that I can use some of the code that is used with the getLowest function.


Array declarations to plug into the program to display the highest grade with the correct student:

string stuNames [5];
double stuGrades [5];

We’ll assume that a user has entered data for the above students in a programming class.

Find Program 7-20 (complete program down below [that I didn't code but it is a textbook example I need help with in modifying] in the text (getLowest( ) function). Recreate the function to reflect passing two arrays (declarations shown above) and the array size to the getLowest( ) function. Update the code to display the name of student with the highest grade along with the grade value. Nothing needs to be returned from function getLowest( ).

Things to consider:
• Which array will you search to find the student with the highest grade?
• Once you find the highest grade, how will you connect the grade to the associated student?

Show the updated version of the getLowest( ) function reflecting the above information and use of parallel arrays.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
scores with the
// lowest score dropped.
#include <iostream>
#include <iomanip>
using namespace std;

// Function prototypes
void getTestScores(double[], int);
double getTotal(const double[], int);
double getLowest(const double[], int);

int main()
{

const int SIZE = 4; // Array size
double testScores[SIZE], // Array of test scores
total, // Total of the scores
lowestScore, // Lowest test score
average; // Average test score

// Set up numeric output formatting.
cout << fixed << showpoint << setprecision(1);

// Get the test scores from the user.
getTestScores(testScores, SIZE);

// Get the total of the test scores.
total = getTotal(testScores, SIZE);

// Get the lowest test score.
lowestScore = getLowest(testScores, SIZE);

// Subtract the lowest score from the total.
total −= lowestScore;

// Calculate the average. Divide by 3 because
// the lowest test score was dropped.
verage = total / (SIZE − 1);

// Display the average.
cout << "The average with the lowest score "
<< "dropped is " << average << ".\n";
}

void getTestScores(double scores[], int size)
{
// Loop counter
int index;

// Get each test score.
for(index = 0; index <= size − 1; index++)
{
cout << "Enter test score number "
<< (index + 1) << ": ";
cin >> scores[index];
}
}

double getTotal(const double numbers[], int size)
{
double total = 0; // Accumulator

// Add each element to total.
for (int count = 0; count < size; count++)
total += numbers[count];

// Return the total.
return total;
}

double getLowest(const double numbers[], int size)
{
double lowest; // To hold the lowest value

// Get the first array's first element.
lowest = numbers[0];

// Step through the rest of the array. When a
// value less than lowest is found, assign it
// to lowest.
for (int count = 1; count < size; count++)
{
if (numbers[count] < lowest)
lowest = numbers[count];

// Return the lowest value.
return lowest;
}
Last edited on
I am thinking that I need to search the getTestScores array to find the students with the highest grade. Is that correct, or do I need to search another array for the highest grade?
getTestScores(...) is a function not an array. So no, nothing to be changed there.

I am thinking how am I need to recreate the getLowest function to reflect passing the string stuNames[5] and double studGrades[5] into it. Any suggestions/tips/questions on how to do that?
Just pass the second array. E.g. void getLowest(const string stuNames[], const double numbers[], int size)

Using getLowest( ) to print the highest sounds rather nonsensical.
Thank you coder777.

Do you have any suggestions on how to reflect the array size of getLowest()?

And do you have any suggestions on how I can display the name of the student with the highest grade along with the grade value?
Topic archived. No new replies allowed.