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

C++ 3. Write a computer program that prompts the user for two numbers, n for the

ID: 647972 • Letter: C

Question

C++ 3. Write a computer program that prompts the user for two numbers, n for the number of items in the array to sort, and num_ifor a number of iterations. Then do the following: Initiate a variable running_time to 0 Create a for loop that iterates num_i times. In the body of the loop, Create an array of n random integers Get the time and set this to start-time. You will have to figure out what the appropriate command is in the programming language you are using to find them time Use sophisticated bubble sort to sort the array Get the time and set this to end-time Subtract end-time from start-time and add the result to running_time Once the program has run, note The number of items sorted The number of iterations The running time Repeat the process nine times, using 5, 25 and 50 as the size of the array, and 10, 100 and 1000 as the number of iterations. 4. Repeat 3 using selection sort.

Explanation / Answer

#include<iostream>
#include<conio.h>

using namespace std;


template <class T>
void s_sort(T a[],int n)
{
int i,j,t;
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(a[j]<a[i]) //for descending order use if(a[j]>a[i])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
}


int main()
{
int a[100],i,n;
cout<<"Enter The number of Element: ";
cin>>n;
cout<<" Enter Elements: ";
for(i=0;i<n;i++)
{

cout<<" Enter:";
cin>>a[i];
}
s_sort(a,n);
cout<<" After Sorting ";
for(i=0;i<n;i++)
{
cout<<a[i]<<" ";
}
getch();
return 0;
}