asked 151k views
0 votes
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.

1 Answer

0 votes

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;

}

Step-by-step explanation:

It can also work like:

using namespace std;

int main()

{

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

int i, j;

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

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<<"\\ Names Sorted in Alphabetical Order : \\\\";

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

{

cout<<" ";

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

}

return 0;

}

answered
User Alexmorhun
by
7.7k points