Question
please help me fill out the blanks to the prewritten code for c++
1. OBLJ UI SuuenLD, JUN, UML function find MultiMax that finds both the value ane handle ties, the find MultiMax function she
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>

using namespace std;

int findMultiIndex(int arr[], int n, int *indexMax, int *numberOfMaxIndixes) {

int maxValue = arr[0];

for (int i=0; i<n; i++) {

if (arr[i] > maxValue) {

maxValue = arr[i];

}

}

for (int i=0; i<n; i++) {

if (arr[i] == maxValue) {

indexMax[*numberOfMaxIndixes] = i;

(*numberOfMaxIndixes) ++;

}

}

return maxValue;

}

int main() {

int maxValue;

int indexMax[8] = {-1};

int arr[8] = {3, 2, 3, 4, 1, 4, 2, 4};

int numberOfMaxIndixes = 0;

maxValue = findMultiIndex(arr, 8, indexMax, &numberOfMaxIndixes);

cout << maxValue << endl;

cout << numberOfMaxIndixes << endl;

cout << "Max indices" << endl;

for (int i=0; i<numberOfMaxIndixes; i++) {

cout << indexMax[i] << " ";

}

}

1 2 #include <iostream> using namespace std; clang version 7.0.0-3-ubuntu0.18.04.1 (tags/RELEASE_700/final) ? clang++-7 -pthr

Add a comment
Know the answer?
Add Answer to:
please help me fill out the blanks to the prewritten code for c++ 1. OBLJ UI...
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
  • 1. (40 pts) Consider the following function. Complete the function that does the following: (a) Take...

    1. (40 pts) Consider the following function. Complete the function that does the following: (a) Take three arguments, int array, int as the length of the array, and int *max. (b) Find the maximum value and the minimum value in the array. (c) The pointer max points to the maximum value. (d) Return the pointer that points to the minimum value max)( findMinAndMax(int al l, int length, int int maxValue a[0], minValue al0 int int maxldx 0, minldx 0; for...

  • c++ Some pieces of the following code are missing. Fill in the blanks of the following...

    c++ Some pieces of the following code are missing. Fill in the blanks of the following program. Each answer must fit on a single line. include <iostream> #include <cstdib #include <ctimes using namespace std; randoml_event return 2 (rand() 5 random2 intre + rand 90 return ret: random1_1000X rand) intret 100 return ret: fint 2) return nt; return n2 is oder Is_odot if (n%2 0) return return true; int sum3 (int n, int n, int n3 X int sum= n1 +...

  • in c++ please program for this code #include <iostream> #include <fstream> #include <string> #include <cstring> //...

    in c++ please program for this code #include <iostream> #include <fstream> #include <string> #include <cstring> // for string tokenizer and c-style string processing #include <algorithm> // max function #include <stdlib.h> #include <time.h> using namespace std; // Extend the code here as needed class BTNode{ private: int nodeid; int data; int levelNum; BTNode* leftChildPtr; BTNode* rightChildPtr; public: BTNode(){} void setNodeId(int id){ nodeid = id; } int getNodeId(){ return nodeid; } void setData(int d){ data = d; } int getData(){ return data;...

  • C++ Code Pass By Reference Practice Write the following functions for basic array operations based on...

    C++ Code Pass By Reference Practice Write the following functions for basic array operations based on the function descriptions given below. Write the following functions for basic array operations based on the function descriptions given below. FindMinArray: This function will search an array of integers (passed to the function as a parameter) for its minimum value, then return that value. SumArray: This function will sum an array of integers (passed to the function through a parameter) then return that sum....

  • Using C++, fix the following code so that (1) Change the student array storage part so...

    Using C++, fix the following code so that (1) Change the student array storage part so that the data is loaded from a file "students.txt". Use an appropriate data    termination flag. (2) Sort the student array in ascending order of GPA using insertion sort. Print the sorted array (3) Sort the student array in ascending order of ID using insertion sort. Print the sorted array (4) Illustrate Binary search for a particular ID that would be found and one...

  • Can I get a C++ code and output for this program using classes instead of using...

    Can I get a C++ code and output for this program using classes instead of using struct. The following program implements a Last In First Out (LIFO) stack. ( I want to use class for function definitions too and if main need.) #include <iostream> using namespace std; const int MAX = 100; struct stack {    int s[MAX]; // an array of integers    int top; // the index of the last number }; void push(stack &, int); void pop(stack&,...

  • The code below is already completed using C++. Could you please explain why the input is...

    The code below is already completed using C++. Could you please explain why the input is 3 : 2 : 3 : 6 : 4 : -1 : 3 : 1 : 0 :? Please let me know really short explanation. #include <iostream> using namespace std ; int binarySearch(const int array[], int numElems, int value) { int first = 0, // First array element last = numElems - 1, // Last array element middle, // Midpoint of search position =...

  • C++ Look the source code and, 1. the function findMaxVisits is empty and one of its...

    C++ Look the source code and, 1. the function findMaxVisits is empty and one of its parameters does not behave as it should. supply the missing statements and repair the damaged parameter. do not use any non-local constants or variables. 2. the fill function has some errors. repair the function without changing its parameter list. do not use any non-local constants or variables. 3. the show function has some errors. repair the function without changing its parameter list. One error...

  • /// c ++ question plz help me fix this not a new code and explain to...

    /// c ++ question plz help me fix this not a new code and explain to me plz /// Write a function to verify the format of an email address: bool VeryifyEmail(char email[ ]); Do NOT parse the email array once character at a time. Use cstring functions to do most of the work. Take a look at the available cstring and string class functions on cplusplus website. Use a two dimensional array to store the acceptable top domain names:...

  • I have to a C++ program I need help with. Can you break it into the...

    I have to a C++ program I need help with. Can you break it into the two steps provided below. Suppose MAX_SIZE is a global constant int variable that has been declared and initialized to an appropriate positive value. 1. int maxValue(const array<int, MAX_SIZE>&, int); is the prototype for a function that returns the value of the largest element in the array parameter. The array may be only partially filled. The int parameter indicates how many items are actually in...

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