The str method of the Bank class returns a string containing the accounts in random order. Design and implement a change that causes the accounts to be placed in the string by order of name. (Hint: You will also have to define some methods in the SavingsAccount class.) Grading When you have completed your program, click the Submit button to record your score.

Respuesta :

Answer:

using namespace std;

// function to print string in sorted order

void sortString(string &str)

{

  sort(str.begin(), str.end());

  cout << str;

}

// Driver program to test above function

int main()  

{

   string s = "pleaseordertheaccounts";

   sortString(s);

   return 0;

}

Explanation:

It can also work like:

using namespace std;

int main()

{

       char str[5][20], t[20];

       int i, j;

       cout<<"\n Enter Any Five Names : \n\n";

       for(i=0; i<5; i++)

       {

               cout<<" ";

               cin>>str[i];

       }

       for(i=1; i<5; i++)

       {

               for(j=1; j<5; j++)

               {

                       if(strcmp(str[j-1], str[j])>0)

                       {

                               strcpy(t, str[j-1]);

                               strcpy(str[j-1], str[j]);

                               strcpy(str[j], t);

                       }

               }

       }

       cout<<"\n Names Sorted in Alphabetical Order : \n\n";

       for(i=0; i<5; i++)

       {

               cout<<" ";

               cout<<str[i]<<"\n";

       }

       return 0;

}