Question

Write a C++ program that contains 2 functions. LastLargestIndex, that takes as paraneters an int array and // its size and re
0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE

int lastLargestIndex(int arr[], int n) {

if (n == 0) {

return -1;

}

int maxIndex = 0;

int max = arr[0];

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

if (max < arr[i]) {

maxIndex = i;

max = arr[i];

}

}

return maxIndex;

}

void printArray(int arr[], int n) {

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

cout << arr[i] << " ";

}

cout << endl;

}

NOTE: Please upvote the answer if you found it helpful.

Add a comment
Know the answer?
Add Answer to:
Write a C++ program that contains 2 functions. LastLargestIndex, that takes as paraneters an int array...
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
  • Write a C++ function, lastLargestIndex that takes as parameters an int array and its size and...

    Write a C++ function, lastLargestIndex that takes as parameters an int array and its size and returns the index of the "last occurrence" of the largest element in the array. Include another function to print the array. Also, write a program to test your function. [HINTS) Create an array of size 15 in the main function and initialize it with the values shown in the below sample output. Pass the array and its size to function lastLargestindex; function lastLargestindex returns...

  • One dimensional array What this code print #include <iostream> using namespace std; int main () {...

    One dimensional array What this code print #include <iostream> using namespace std; int main () { const int SIZE = 7; int numbers [SIZE] = {1, 2, 4, 8): // Initialize first 4 elements cout << “Here are the contents of the array:\n"; for (int index = 0; index < SIZE: index++} cout << numbers[index] << “ “; cout << endl; return 0; }

  • C++, Will Upvote: A) Try to get the following programs to run in your environment. B)...

    C++, Will Upvote: A) Try to get the following programs to run in your environment. B) If the programs will run, document each line of code with comments and describe any changes you had to make to the original code to get it to work. If the programs are unable to be modified to run with desirable results, explain why you think so. C) Description your solution and a synopsis of how your code is intended to work and the...

  • /* Array expander: Write a function that accepts an int array as argument. The function should...

    /* Array expander: Write a function that accepts an int array as argument. The function should create a new array that is n times the size of the argument array, where n is a user input. The function should copy the contents of the argument array to the new array, and initialize the unused elements of the second array with 0. The function should return a pointer to the new array */ #include <iostream> using namespace std; const int NUM_ELEM...

  • Who could write the array.cpp file ?   //main.cpp #include "array.hpp" #include <iostream> int main() { int...

    Who could write the array.cpp file ?   //main.cpp #include "array.hpp" #include <iostream> int main() { int n; std::cin >> n; array a(n); for (int i = 0; i < n; i++) { std::cin >> a.data()[i]; } std::cout << "array size:" << a.max_size() << std::endl; std::cout << "array front:" << a.front() << std::endl; std::cout << "array back:" << a.back() << std::endl; int* data = a.data(); std::cout << "array elements using data:" << std::endl; for (int i = 0; i < n;...

  • /* * Program5 for Arrays * * This program illustrates how to use a sequential search...

    /* * Program5 for Arrays * * This program illustrates how to use a sequential search to * find the position of the first apparance of a number in an array * * TODO#6: change the name to your name and date to the current date * * Created by Li Ma, April 17 2019 */ #include <iostream> using namespace std; //global constant const int ARRAY_SIZE = 10; //TODO#5: provide the function prototype for the function sequentialSearch int main() {...

  • I have to type and explain in class each code in every detail filled with //...

    I have to type and explain in class each code in every detail filled with // commentary. Explains how does work in every codes. 1) What does the below print #include <iostream> using namespace std ; int main() {    int var1 = 20 ;    int var2 = 30 ;    int* ptr1 ;    int* ptr2 ;    int* temp ;    ptr1 = &var1 ;    ptr2 = &var2 ;    cout << *ptr1 << endl ;...

  • // Program takes 5 numbers from a user (from console), stores them into an // array,...

    // Program takes 5 numbers from a user (from console), stores them into an // array, and then prints them to the screen (on the same line). // Add code to complete this program. You only need to add code where indicated // by "ADD HERE". #include <iostream> using namespace std; int main() { const int SIZE = 5; // size of array // ADD HERE - create an array of integers that will hold 5 integers. cout << "please...

  • * This program illustrates how to use a sequential search to find the position of the...

    * This program illustrates how to use a sequential search to find the position of the first apparance of a number in an array TODO#6: change the name to your name and date to the current date * * Created by John Doe, April 17 2019 */ #include using namespace std; //global constant const int ARRAY_SIZE = 10; //TODO#5: provide the function prototype for the function sequentialSearch int main() { //TODO#1: declare an integer array named intList with size of...

  • Modify PartTwo.cpp so that it is uses a vector, named vect, instead of an array. PartTwo.cpp...

    Modify PartTwo.cpp so that it is uses a vector, named vect, instead of an array. PartTwo.cpp Is posted here: // This program reads data from a file into an array. Then, it // asks the user for a number. It then compares the user number to // each element in the array, displays the array element if it is larger. // After looking at entire array, it displays the number of elements in the array larger // than the user...

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