Main function.
44 {
46 std::string paragraph;
47 std::cout << "Please enter your paragraph: \n";
48 std::getline(std::cin, paragraph);
49 std::cout << "\nHello, your paragraph is:\n " << paragraph << "!\n";
50 std::cout << "\nThe size of your paragraph = " << paragraph.size()
51 << " characters. \n\n";
52
53 if (paragraph.empty()) {
54 std::cout << "\nThe paragraph is empty" << std::endl;
55 } else {
56 int ch = 0;
57 while (true) {
58 std::string word;
59 std::cout << "Please enter the word you are searching for: ";
60 std::getline(std::cin, word);
61 std::cout << "Ignore case-sensitive? 1 = Yes, 0 = No" << std::endl;
62 std::cin >> ch;
63 if (ch == 1) {
64 std::string lowerCase =
lower(
65 paragraph);
66
67 std::string lowerCaseWord =
69
70
71 std::cout << "Hello, your word is " << word << "!\n";
72 if (lowerCase.find(lowerCaseWord) == std::string::npos) {
73 std::cout << word << " does not exist in the sentence"
74 << std::endl;
75 } else {
76 std::cout << "The word " << word
77 << " is now found at location "
78 << lowerCase.find(lowerCaseWord) << std::endl
79 << std::endl;
80 }
81 } else {
82 std::cout << "Hello, your word is " << word << "!\n";
83 if (paragraph.find(word) == std::string::npos) {
84 std::cout << word << " does not exist in the sentence"
85 << std::endl;
86 } else {
87 std::cout << "The word " << word
88 << " is now found at location "
89 << paragraph.find(word) << std::endl
90 << std::endl;
91 }
92 }
93 std::cout << "\nPress Ctrl + C to exit the program.\n\n";
94 std::cin.get();
95 }
96 }
97 return 0;
98}
std::string lower(std::string word)
function to convert a C++ string to lower case
static void test()
Self-test implementations.