I having trouble with my bubble sort in my sorting function(sort_array) Am not sure if its a syntax error or its logic it just that every time i run It will display half my program.
//********************** 5 points *******************
//code a range based for loop to print out the contents of the inst_names array
for (auto name : inst_names)
{
cout << name << " ";
}
//generate a random number between 5 and 10 and place it in arr_size
int arr_size = rand() % 5 + 10;
string *names_arr = new string [arr_size];
for (int i = 0; i < arr_size; i++)
{
names_arr[i] = inst_names[i];
}
//create a string array with arr_size elements and place address of this newly created
//array into the names_arr pointer variable. Populate this newly created
//array ffrom elements in the inst_names array
//********************** 5 points *******************
cout << "\n---Before sort---\n";
//**************** 15 points for print_arr function **************
print_array(names_arr, arr_size);
//The print_array function prints the elements in the array whose address
//is maintained in the names_arr pointer
//Remember to create a function prototype for the function
sort_array(names_arr, arr_size);
//**************** 15 points for sort_arr function **************
//The sort_array function must sort the elements in the array whose address
//is maintained in the names_arr pointer
//Remember to create a function prototype for the function!
Sincerely, what's wrong in using the "code" tags?
Anyway, as far as I can see you don't have the swap() function. Or perhaps you forgot to copy&paste it?
Your main problems are the array bounds that you are exceeding in your sort_array() routine.
The code below works (I think!) with minimal changes to your code. However, you can improve the bubble sort as the passes get successively shorter (as one end of the array will be increasingly sorted) and you could also stop once you get a pass with no swaps.
Also, it just takes the first arr_size elements from your master array - but I leave that for you to sort out.