Define a function called DisplayMax that has 3 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 DisplayMax must work when called with various types of actual arguments, for example
string DisplayMax(string names[], int calories[], int size)
or
int DisplayMax(int calories[], float prices[], int size).
(Parallel Arrays are two arrays whose data is related by a
common index. For example: with the string array and int array,
index 3 of the string array would have some name, and index 3 of
the int array would have an associated value to that name (say,
number of calories).)
Write one function that will take either set of arguments in, displays and return the value from the first second array corresponding to the max value from the second first array, in the form “The max value of <int/float value> belongs to <string/int value>.”
Test your function by calling it with different inputs from a main() function and then printing the result of the function in the main program.
Examples:
Given:
names => string[] = {“Yogurt Lemon”, “Chocolate Delight”, “Choco Chip”, “Frozen Sorbet”, “Melon”}
calories => int[] = {300, 650, 550, 450, 50}
size => int = 5
Output:
“The max value of 650 belongs to Chocolate Delight.”
Given:
calories => int[] = {300, 35, 650, 550, 450, 50}
prices => float[] = {2.99, .99, 2.79, 3.19, 1.79, 2.15}
size => int = 6
Output:
“The max value of 650 belongs to 2.79.”
#include <iostream>
using namespace std;
string DisplayMax(string names[], int calories[], int
size)
{
int max = calories[0];
int index = 0;
for(int i=1;i<5;i++)
{
if(calories[i] > max)
{
max =
calories[i];
index = i;
}
}
cout<<"The max value of "<<max<<"
belongs to ";
return names[index];
}
int DisplayMax(int calories[], float prices[], int size)
{
int max = prices[0];
int index = 0;
for(int i=1;i<5;i++)
{
if(calories[i] > max)
{
max =
calories[i];
index = i;
}
}
cout<<"\nThe max value of "<<max<<"
belongs to ";
return index;
}
int main() {
string names[] = {"Yogurt Lemon", "Chocolate Delight",
"Choco Chip", "Frozen Sorbet", "Melon"};
int calories[] = {300, 650, 550, 450, 50};
float prices [] = {2.99, .99, 2.79, 3.19, 1.79,
2.15};
int size = 5;
string str;
str = DisplayMax(names,calories,size);
cout<<str<<".";
int index;
index = DisplayMax(calories,prices,size);
cout<<prices[index]<<".";
return 0;
}
Output:
The max value of 650 belongs to Chocolate Delight. The max value of 650 belongs to 0.99.
Do ask if any doubt. Please upvote.
Define a function called DisplayMax that has 3 parameters: the first two parameters are parallel arrays...
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...
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...
A function that takes three parameters: an int array, an int n that is the size of the array and an int pointer max that is to assign the maximum value in the array. The function will find and return the index of the first occurrence of the maximum value in the array and assign the maximum value to the pointer. For example, in the array {1, 2, 6, 5, 6, 4, 3, 6, 4}, the maximum value is 6...
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
c++ Write a function has Match that takes 3 parameters: 2 arrays of strings and an int that represents the length of each array The function returns true if at any position, the two arrays have the same string, false if not. For example: {"a", "b", "cat", "d"} and {"1", "2", "cat", "4"} would match
c++ question need help Write a function pairWise that takes four parameters: two arrays of int and the size of the first array. The size of the first array is guaranteed to be exactly twice the size of the 2nd array The function takes each pair of integers from the first array and stores the product in the 2nd array. ex: if the first array is {2, 7, 3, 4}, then the second array will end up with {14, 12}
c++ question need help Write a function pairWise that takes four parameters: two arrays of int and the size of the first array. The size of the first array is guaranteed to be exactly twice the size of the 2nd array The function takes each pair of integers from the first array and stores the product in the 2nd array. ex: if the first array is {2, 7, 3, 4}, then the second array will end up with {14, 12}
Parallel Arrays Summary In this lab, you use what you have learned about parallel arrays to complete a partially completed Java program. The program should either print the name and price for a coffee add-in from the Jumpin’ Jive coffee shop or it should print the message: "Sorry, we do not carry that.". Read the problem description carefully before you begin. The data file provided for this lab includes the necessary variable declarations and input statements. You need to write...
Parallel Arrays are two arrays, often containing elements of different datatypes that are synced with a common index. For this problem you are going to create a function called FindHighest that will accept two parameters: names and calls. The names list will contain the names of individuals that work on a help desk. The calls list will contain the number of calls they received in one day. Your function will return back to main the name of the person who...
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...