VB icon

Name Sorter

Email
Submitted on: 2/28/2020 4:05:25 PM
By: Thomas1965 
Level: Intermediate
User Rating: Unrated
Compatibility: C++ (general)
Views: 678
 
     This app lets you enter names and outputs them in sorted order.

 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: Name Sorter
// Description:This app lets you enter names and outputs them in sorted order.
// By: Thomas1965
//**************************************

#include <iostream>
#include <string>
#include <sstream>
#include <set>
#include <iterator>
void print_intro();
std::set<std::string>get_names();
void print_result(const std::set<std::string>& names);
int main()
{
 print_intro();
 std::set<std::string>names = get_names();
 print_result(names);
}
void print_intro()
{
 std::cout << "Name Sorter 1.0\n";
 std::cout << "===============\n\n";
 std::cout << "This app lets you enter names and outputs them\n";
"in sorted order\n";
 std::cout << "Enter some names separated by space and hit return:\n";
}
std::set<std::string>get_names()
{
 std::set<std::string>names;
 std::string input; // holds all the names in the line
 std::string name; // one individual name extracted from the line
 std::getline(std::cin, input);
 // splitting the line into tokens(names)
 std::istringstream iss(input);
 while (iss >> name)
names.insert(name);
 return names;
}
void print_result(const std::set<std::string>& names)
{
 std::cout << "The names in sorted order are:\n";
 for (const auto& name : names)
std::cout << name << "\n";
}


Other 31 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.