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

Dear Viewer, Please do tell me the exact algorithem to use and evalute thestring

ID: 3611400 • Letter: D

Question

Dear Viewer, Please do tell me the exact algorithem to use and evalute thestring sorting method in C++, purily based on C type pointersstring. e.g., I would like to use char *name [20], // which is holding the names of 20persons Note: here I can use the standard string method form #include<string>, but I don't want this, actually I want a robustapproach on C pointer like strings, If you know then do tell me andgive a chance to say thanks. Dear Viewer, Please do tell me the exact algorithem to use and evalute thestring sorting method in C++, purily based on C type pointersstring. e.g., I would like to use char *name [20], // which is holding the names of 20persons Note: here I can use the standard string method form #include<string>, but I don't want this, actually I want a robustapproach on C pointer like strings, If you know then do tell me andgive a chance to say thanks.

Explanation / Answer

Dear, #include <string>
#include <iostream>
using namespace std;

void selectionSort(string [], int);
void showArray(string [], int);

int main()
{
   const int SIZE = 20;
   string name[SIZE] ={ "Collins, Bill", "Smith, Bart","Michalski, Jacob","Griffin, Jim", "Sanchez, Manny", "Rubin,Sarah",
"Taylor, Tyrone", "Johnson, Jill", "Allison, Jeff","Moreno, Juan","Wolfe, Bill", "Whitman, Jean","Moretti, Bella", "Wu, Hong","Patel, Renee","Harrison, Rose", "Smith, Cathy", "Conroy,Patrick","Kelly, Sean", "Holland, Beth" };

cout << " The unsorted string is: ";
showArray(name, SIZE);
selectionSort(name, SIZE);
cout << " The sorted string is: ";
showArray(name, SIZE);

return 0;
}

void selectionSort(string name[], int elems)
{
   int startScan, minIndex;
   string strName;
for(startScan = 0; startScan < (elems - 1);startScan++)
{
    minIndex = startScan;
   strName = name[startScan];
   for(int index = startScan + 1; index < elems;index++)
   {
      if(name[index] < strName)
       {
          strName =name[index];
          minIndex =index;
        }
    }
   name[minIndex] = name[startScan];
   name[startScan] = strName;
}
}
void showArray(string name[], int elems)
{
   for(int count = 0; count < elems; count++)
cout << count << ": " << name[count]<< endl;
} I hope this is helpful foryou................. #include <string>
#include <iostream>
using namespace std;

void selectionSort(string [], int);
void showArray(string [], int);

int main()
{
   const int SIZE = 20;
   string name[SIZE] ={ "Collins, Bill", "Smith, Bart","Michalski, Jacob","Griffin, Jim", "Sanchez, Manny", "Rubin,Sarah",
"Taylor, Tyrone", "Johnson, Jill", "Allison, Jeff","Moreno, Juan","Wolfe, Bill", "Whitman, Jean","Moretti, Bella", "Wu, Hong","Patel, Renee","Harrison, Rose", "Smith, Cathy", "Conroy,Patrick","Kelly, Sean", "Holland, Beth" };

cout << " The unsorted string is: ";
showArray(name, SIZE);
selectionSort(name, SIZE);
cout << " The sorted string is: ";
showArray(name, SIZE);

return 0;
}

void selectionSort(string name[], int elems)
{
   int startScan, minIndex;
   string strName;
for(startScan = 0; startScan < (elems - 1);startScan++)
{
    minIndex = startScan;
   strName = name[startScan];
   for(int index = startScan + 1; index < elems;index++)
   {
      if(name[index] < strName)
       {
          strName =name[index];
          minIndex =index;
        }
    }
   name[minIndex] = name[startScan];
   name[startScan] = strName;
}
}
void showArray(string name[], int elems)
{
   for(int count = 0; count < elems; count++)
cout << count << ": " << name[count]<< endl;
} I hope this is helpful foryou................. I hope this is helpful foryou................. I hope this is helpful foryou.................
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