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

In this assignment, you are supposed to process series of input strings and cate

ID: 3681637 • Letter: I

Question

In this assignment, you are supposed to process series of input strings and categorize the elements in them using all knowledge and skills you have learned already. The input strings have several elements (words, phrases and sentences) separated by e.g. "Hi,Nice 2 meet comma u, Nox in Nixon, to go" The elements in strings have four categories: 1. Single word: Like "algorithm' "lab" etc. No digit, no symbol or spaces. 2. Palindrome: A word, phrase or sentence that reads the same backward or forward, e.g. "No x in Nixon 3. Words/phrases/sentences with digits: Like Assignment4", Nice 2 meet u 4. Others: Phrases or sentences with no digit or are not palindrome. Use enumerated types to represent the four categories above, the four categories in enumerated types are: SINGLEWORD, PALINDROME, WITHDIGITS and OTHERS Define a class Strings (note it is not the string in C++) in individual and .cpp files (All variables should be private) l An enumerated type variable indicating the element's category 2. A string content storing the word or phrase 3. String content's size in terms of number of characters (spaces not included) 4. Necessary functions to set or get the variables Your program is supposed to accomplish the following:

Explanation / Answer

Please find below the program.

#include <iostream>
using namespace std;

int main()
{
   const int sentencesize = 50;
   char sentence[sentencesize];
   int rcntr = 0;//reverse counter ... circles through sentence from end to beginning
   bool decider = true;
   cout << "Please enter the sentence or phrase that you want to check:n";
   cin.getline(sentence, sentencesize);

   //calculate the number of characters entered
   for (rcntr = 0; sentence[rcntr] != ''; rcntr++);
   //..............................................
int loopvar = rcntr/2;
for (int i = 0; i <= loopvar; i++)
   {
       rcntr--;
       if (isalpha(sentence[i]) && isalpha(sentence[rcntr]))
       {
           if ( tolower(sentence[i]) == tolower(sentence[rcntr]) )
           {
               continue;
           }
           else
           {
               cout << "It is not a palindrome.n";
               decider = false;
               break;
           }
       }
       else
       {
               if (!(isalpha(sentence[i])))
                   rcntr++;
               else if (!(isalpha(sentence[rcntr])))
                   i--;
       }
   }
   if (decider)
   {
       cout << "It is a palindrome.n";
   }
   system("pause");
   return 0;
}