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

All code must use C++ language with G++ compiler Populate an array of size 100 w

ID: 3811864 • Letter: A

Question

All code must use C++ language with G++ compiler

Populate an array of size 100 with integers 0 and 1000. Initialize the array using a random number generator with "time" as the seed value. Name the array RandomNums. Further, 1. Print the elements of the array RandomNums after initialization. 2. Perform a bubble sort on RandomNums, and sort the array in decreasing order 3. Print the elements of RandomNums after sorting 4. Create another array of size 50 name it as Terminalsum 5. Initialize each element of Terminalsum by adding each pair of terminal elements from Random Nums. For Example: TerminalSum 1st element RandomNums 1st element RandomNums 100 t element Terminalsum 2nd element RandomNums 2nd element RandomNums 99 element Terminalsum 50th element RandomNums 50th element RandomNums 51st element Print Terminalsum array after initialization. 6. Perform a selection sort on Terminalsum, and sort the array in increasing order 7. Print the elements of the array Terminalsum after sorting.

Explanation / Answer

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

int main()
{
   /* initialize random seed: */
srand (time(NULL));
int RandomNums[100],temp,TerminalSum[50],i,j;

cout<<"Random Numbers : "<<endl;
for(i=0;i<100;i++)
{
RandomNums[i] = rand() % 1000 + 1; //generate random numbers
cout<<RandomNums[i]<<" "; //print random numbers after initialization
}

//sorting

for(i=0;i<100;i++)
{
      for(j=0;j<100-i-1;j++)
      {
          if(RandomNums[j]>RandomNums[j+1])
          {
              temp = RandomNums[j];
              RandomNums[j] = RandomNums[j+1];
              RandomNums[j+1] = temp;
          }
      }
}
cout<<endl<<"Random Numbers after sorting : "<<endl;
for(i=0;i<100;i++)
{

cout<<RandomNums[i]<<" "; //print random numbers after sorting
}


for(i=0;i<50;i++)
{
      TerminalSum[i] = RandomNums[i] + RandomNums[99-i]; //initialize TerminalSum array
}

cout<<endl<<"Terminal Numbers : "<<endl;
for(i=0;i<50;i++)
{

cout<<TerminalSum[i]<<" "; //print TerminalSum after initialization
}

//sorting
for(i=0;i<50;i++)
{
      for(j=0;j<50-i-1;j++)
      {
          if(TerminalSum[j]>TerminalSum[j+1])
          {
              temp = TerminalSum[j];
              TerminalSum[j] = TerminalSum[j+1];
              TerminalSum[j+1] = temp;
          }
      }
}
cout<<" Terminal Numbers after sorting :"<<endl;
for(i=0;i<50;i++)
{

cout<<TerminalSum[i]<<" "; //print TerminalSum after sorting
}



   return 0;
}

Output:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote