502,411 views
7 votes
7 votes
Allow the user to enter the names of several local businesses. Sort the business names and display the results. Continue this process until they are out of business names. Please use good functional decomposition to make your development easier. (Perhaps one for sorting a vector of strings, another for swapping two strings, one for As an example the program interaction might look something like (the parts in blue are typed by the user): $ /busisort.out Welcome to the Business Sorting Program!!! Please enter the name of a business: WalMart Your business is: WalMart Another business? y Please enter the name of a business: JC Penney Your businesses are: JC Penney WalMart Another business? Y Please enter the name of a business: Merlin Muffler Your businesses are: JC Penney Merlin Muffler WalMart Another business? yes Please enter the name of a business: Appleby's Your businesses are: Appleby's JC Penney Merlin Muffler WalMart Another business? Yes Please enter the name of a business: Zippy's Your businesses are: Appleby's JC Penney Merlin Muffler WalMart Zippy's Another business?

User BrandonS
by
3.0k points

1 Answer

11 votes
11 votes

Answer:

Here the code is given as follows,

Step-by-step explanation:

Code:

#include <iostream>

#include <string>

#include <list>

using namespace std;

std::string readName ();

void display (list <std::string>);

bool promptContinue ();

int main()

{

std::string Business = "";

list <std::string> Array;

bool Continue = true;

do {

//enter input items

Array.push_back(readName ());

//sort business

Array.sort();

//display business

display (Array);

}while(promptContinue ());

return 0;

} //end of main function

std::string readName ()

{

std::string _Business = "";

cout << "Please enter the name of a business: ";

getline (cin, _Business);

return _Business;

}

void display (list <std::string> _Array)

{

cout << "Your businesses are: " << endl;

int i = 0;

while (i < _Array.size ())

{

cout << _Array.front () << endl;

_Array.push_back (_Array.front ()); // This loops the front of the list to the back this makes it possible to not use an iterator

_Array.pop_front ();

i++;

}

}

bool promptContinue ()

{

std::string prompt = "";

cout << "Another Business? ";

cin >> prompt;

cin.ignore (); // Clear the whitespace leftover from cin

return (prompt == "yes");

}

User Aremyst
by
3.0k points