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

Allow the user to enter the names of several local businesses. Sort the business

ID: 3643394 • Letter: A

Question

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.
ex.
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? no

Thank you for using the BSP!!

Explanation / Answer

#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");
    }

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