Question

In C++ format: Define a function called DisplayMax. It will have 3 parameters of two different types of known parameter lists which are either void DisplayMax(string idI, double value[], int size) or void DisplayMax(int idn, short value几int size). The first and second parameters are parallel arrays. (Parallel Arrays are two arrays whose data is related by a common index. For example: with the string array and double array, index 5 of the string array would have some name, and index 5 of the double array would have an associated value to that name (say, score).) The first parameter is an array of IDs either in the form of a name (as a string) or a numeric ID (as an int). The second parameter is an array that either holds doubles, in the case of a string ID, or shorts, in the case of an int ID. The third parameter the size of both arrays. Write one function that will take either set of arguments in, and display the max of that array in the form The max value of <double/short value> belongs to <string/int ID>. Examples Given: id => string[] = {Tamir, Anna, Martina, Caspar, Fanny} value => double[] = {3.34, 6.12, 8.34, 1.22. 0.58) size->int 5 Output: The max value of 8.34 belongs to Martina. Given: id => int] = {4534, 5676, 8554 2921, 4674, 57991 value => short-(15, 45, 12, 44, 25, 1} size => int 6 Output: The max value of 45 belongs to 5676.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>

using namespace std;
void DisplayMax(string id[], double value[], int size) {
double max = value[0];
int maxIndex = 0;
for(int i=1;i<size;i++) {
if(max < value[i]) {
max = value[i];
maxIndex = i;
}
}
cout<<"The max value of "<<max<<" belongs to "<<id[maxIndex]<<endl;
}
int main()
{
  

string id[5] = {"Tamir","Anna","Martina","Caspar","Fanny"};
double value[5] = {3.34,6.12,8.34,1.22,0.58};
int size = 5;
DisplayMax(id, value, size);
return 0;
}

Output:

$g++ -o main *.cpp
$main
The max value of 8.34 belongs to Martina
Add a comment
Know the answer?
Add Answer to:
In C++ format: Define a function called DisplayMax. It will have 3 parameters of two different...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Define an ordinary function called DisplayMin that has three parameters: the first two parameters are parallel...

    Define an ordinary function called DisplayMin that has three parameters: the first two parameters are parallel arrays of different types and the third argument is of type size_t representing the size of both arrays. The function DisplayMin must work when called with various types of actual arguments, for example string DisplayMin(string names[], int calories[], int size) or int DisplayMin(int calories[], float prices[], int size). (Parallel Arrays are two arrays whose data is related by a common index. For example: with...

  • Write a program that works with two arrays of the same size that are related to...

    Write a program that works with two arrays of the same size that are related to each other in some way (or parallel arrays). Your two arrays must be of different data types. For example, one array can hold values that are used in a formula that produces the contents of the second array. Some examples might be:  from a previous program, populations and the associated flowrates for those populations (an int array of populations and a double array...

  • C Programming write two functions, similar to what you see in the sample program. The first will ask the user to enter some information (I have included the type in parentheses) First Name (char[]) L...

    C Programming write two functions, similar to what you see in the sample program. The first will ask the user to enter some information (I have included the type in parentheses) First Name (char[]) Last Name (char[]) Age (int) Height in Inches (double) Weight in Pounds (double) You will use pass-by-reference to modify the values of the arguments passed in from the main(). Remember that arrays require no special notation, as they are passed by reference automatically, but the other...

  • Write a c program that finds the uncommon elements from two array elements using pointers only...

    Write a c program that finds the uncommon elements from two array elements using pointers only . For example : Enter the length of the array one : 5 Enter the elements of the array one: 9 8 5 6 3 Enter the length of the array two: 4 Enter the elements of the array two: 6 9 2 1 output: 8 5 3 2 1 void uncommon_ele(int *a, int n1, int *b, int n2, int *c, int*size); The function...

  • How to create a constructor that uses parameters from different classes? I have to create a...

    How to create a constructor that uses parameters from different classes? I have to create a constructor for the PrefferedCustomer class that takes parameters(name, address,phone number, customer id, mailing list status, purchase amount) but these parameters are in superclasses Person and Customer. I have to create an object like the example below....... PreferredCustomer preferredcustomer1 = new PreferredCustomer("John Adams", "Los Angeles, CA", "3235331234", 933, true, 400); System.out.println(preferredcustomer1.toString() + "\n"); public class Person { private String name; private String address; private long...

  • A method called linearSearch(), which takes as parameters an array of int followed by three values...

    A method called linearSearch(), which takes as parameters an array of int followed by three values of type int, and returns a value of type int. The first int parameter represents a key, the second int parameter represents a starting position, and the third int parameter represents an end position. If the key occurs in the array between the start position (inclusive) and the end position (exclusive), the method returns the position of the first occurrence of the key in...

  • c++ write a function that has 3 parameters, two arrays of integers of the same size...

    c++ write a function that has 3 parameters, two arrays of integers of the same size , and the size of the arrays. the function should add the two arrays and store the results in a third array, then print out the contents of the third array name it arraya

  • Update your first program to dynamically allocate the item ID and GPA arrays. The number of...

    Update your first program to dynamically allocate the item ID and GPA arrays. The number of items will be the first number in the updated “student2.txt” data file. A sample file is shown below: 3 1827356 3.75 9271837 2.93 3829174 3.14 Your program should read the first number in the file, then dynamically allocate the arrays, then read the data from the file and process it as before. You’ll need to define the array pointers in main and pass them...

  • C Programming Language 2(a) Define a struct with 1 int array named i, 1 float array...

    C Programming Language 2(a) Define a struct with 1 int array named i, 1 float array named f, and one double array named d, each of size M. (b)Declare array x with N of those structs. (c)Write a void function to traverse array x (using a pointer) assigning to each element in each array d (in each struct in array x) the sum of the corresponding elements in arrays i and f (in the same struct). Use 3 pointers (of...

  • help ASAP 3. Write a string C++ function named UnsignedPartialSum() that takes two string parameters and...

    help ASAP 3. Write a string C++ function named UnsignedPartialSum() that takes two string parameters and an int parameter. If both string parameters represent binary numbers and the int parameter is equal to a positive number less than or equal to the length of the longest string parameter, the function should return a binary string whose length is equal to two times the length of the maximum length of the two string parameters whose value is equal to the sum...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT