Have a list of nouns that you consider proper.
Use a while loop in combination with getline.
for each line the user enters, check if that word or phrase is in the list of proper nouns.
if it is, capitalize the first letter.
#include <cctype> // hint: std::tolower, std::toupper
#include <iostream>
#include <string>
int main()
{
// Prompt user to enter words, each separated by a new line
// provide an array that serves as a list of proper nounds
// e.g.
std::string proper_nouns[] = { "Apple", "Arabic", "Aramaic", "Charlie", "Gauss", "Greek", "Jesus", "Latin", "Lina Medina", "Paris", "Pope Urban II", "Tobago", "United States"};
std::string output;
std::string line;
while (getline(std::cin, line))
{
// if (line matches a word inside proper_nouns) (Hint: compare all strings as lowercase)
// line = proper_nouns[index_of_match];
output += line;
}
std::cout << output << std::endl;
}
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
usingnamespace std;
vector<string> split(const string& line)
{
vector<string> result;
istringstream iss(line);
string s;
while(iss >> s)
result.push_back(s);
return result;
}
int main()
{
string input;
getline(cin, input);
vector<string> words = split(input);
for (string& word: words)
{
// if word is proper noun - see Ganado's post
// then capitalize first letter
}
// print all the world
}
Consider "holly", "lily", "rose". Are they flowers (lower case) or girls' names (proper nouns)? In the case of "rose" it could even be the past tense of a verb: "Everyone stood when Rose rose from her chair".
its intractable. we run into this at work a lot, where people go round and round about standardization and then it works on 90% of text but not some cases and they don't get it. This is why a lot of places all-caps your name when mailing etc.
The only way to do it is to have an AI that perfectly understands the text and can identify the context of the words and make a decision. And, we are not there yet (we are close but never perfect), see the bird and bicycle problem.
its probably best to keep politics out of the forum. Programmers already have a bad political reputation due to the antics of certain monopolistic giant corps, lets not make that worse or prove people right.
It's tricky. Microsoft Word's grammar checker allows you to set grammar rules, but I have to be careful not to let it quietly make its own changes when there are people's names around. Even the rules about capitalisation (particularly with language) seem to be different in different countries ("He is English" -> "Il est anglais").
jonnin wrote:
its probably best to keep politics out of the forum.
My apologies, @jonnin and @ganado. I have removed it.
word lets you configure it so that it gets it right nearly 100% of the time for your personal use-cases. I was saying its intractable to make a general purpose solution.
speaking of word and politics... lol... A couple of bosses ago my boss knew a rather important politician (one of the contenders for POTUS ) and name dropped constantly. So I hacked his word so that every time he typed the guy's name it put in something rude, and it was driving him nuts. I think he finally gave up and reloaded his system to fix it.