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

All code must be in C++ using G++ compiler Populate an array of size 100 with in

ID: 3811903 • Letter: A

Question

All code must be in C++ using 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 RandomNums. For Example: Terminal Sum 1st element: RandomNums 1st element RandomNums 100 t element Terminal Suma 2nd element RandomNums 2nd element RandomNums 99th 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()
{
int arr[100];
int t[50];

srand((unsigned)time(0));

for(int i=0; i<100; i++)
{
arr[i] = (rand()%100)+1;
}

cout<<"The contents of Random Nums :" <<endl;

for(int j=0 ;j<100;j++)
{
cout<<arr[j]<<" ";
}
cout<<endl;
int temp;
for(int k=1;k<(100-1);k++)
{
for(int l=0;l<(100-k-1);l++)
if(arr[l]<arr[l+1])
{
temp=arr[l];
arr[l]=arr[l+1];
arr[l+1]=temp;
}
}
  
cout<<"Random array after sorting in decreasing order"<<endl;
  
for(int m=0;m<100;m++)
{
cout<<arr[m]<<" ";
}
cout<<endl;
  
cout<<"Contents of TerminalSum"<<endl;
  
for(int n=0,p=99;p<=50;n++,p--)
{
t[n] = arr[n]+ arr[p];
cout<<t[n]<<" ";
}
cout<<endl;
  
  
int tempr;
for (int q= 1; q < 50; q++)
{
for (int r = q; r >= 1; r--)
{
if (t[r] < t[r-1])
{
tempr = t[r];
t[r] = t[r-1];
t[r-1] = tempr;
}
else
break;
}
}
  
cout<<"TerminalSum after sorting in increasing order"<<endl;
for(int s=0;s<50;s++)
{
cout<<t[s]<<" ";
}
return 0;
}

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