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

Please help me finish solving this problem. Thank you. Write a program that can

ID: 3545723 • Letter: P

Question

Please help me finish solving this problem.  Thank you.

Write a program that can read an arbitrary number of int values from the user and store it in heap memory. The user should NOT be forced to specify the total number of inputs when the program starts. Instead, the user will input the values one by one so long as she wishes to do so. Read the value one by one and store in dynamically allocated memory in the heap. Sort the numbers using any sorting algorithm and display the output. Here is the outline:

Explanation / Answer

#include <iostream>


using namespace std;


int main()

{

const int N=2;

int *p=new int[N];

bool moreInput=true;

int a;

char ans;

int size =0;

while(moreInput)

{

cout<< "More? (y/n) ";

cin>>ans;

if(ans=='y')

{

cin>>a;

p[size]=a;

size+=1;

}

else

moreInput=false;

}

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

for(int j=i+1;j<size;j++) {

if(p[i]>p[j]) {

int temp = p[i];

p[i] = p[j];

p[j] = temp;

}

}

}

cout<<" The sorted array : ";

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

cout<<" "<<p[i];

}


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