Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In C++ Design a modular program which asks the user to enter a list of numbers.

ID: 3855433 • Letter: I

Question

In C++

Design a modular program which asks the user to enter a list of numbers. The numbers must be stored in an array. The program then finds the index of the first occurrence of the smallest element in the array and the last occurrence of the largest element in the array. The program displays the position and value of each of these items.

Please have:

Your structure chart as a screen shot or picture

Your source code for with

The name of your program as a comment at the top of the file

Your IPO chart incorporated as comments after the name of the file

IPO charts for your functions as comments before the prototypes of your functions

A screen shot or picture of the results after running your program with your test data

Explanation / Answer

// finds the index of the first occurrence of the smallest element in the array and the last occurrence of the largest element in the array.

#include <iostream>

using namespace std;

int main()
{
  
     int arr[100], minimum,maximum,n, c, location = 1, loc=1;

    cout << "Enter total number of elements(1 to 100): ";
    cin >> n;
    cout << endl;


    for(c = 0; c < n; c++)
    {
       cout << "Enter Number " << c + 1 << " : ";
       cin >> arr[c];
    }

   maximum= minimum = arr[0];

    for ( c = 1 ; c < n ; c++ )
    {
        if ( arr[c] < minimum )
        {
           minimum = arr[c];
           location = c+1;
   
        }

if ( arr[c] > maximum )
        {
           maximum = arr[c];
           loc = c+1;

        }
    }

            
        cout<<"smallest elememt is"<<minimum<< " and location is"<<location;
        cout<<"largest element is"<<maximum<<" and location is"<<loc;
return 0;
    }