Apostrophe in word in c++ translator progam

185 views Asked by At

I'm writing a program for a translator. Now, i'm a writing a class for words and it is as follows, i'm having trouble writing the method to return all the words with an apostrophe in a sentence. What should i write after bool Words::isApostophePresent(){

if(.....)

 Words::Words() {}

string Words::getWord(){
      return word;
}

void Words::setWord(string w){
     word=w;
}

int Words::getNumCharacters(){
   return word.length();
}

vector<char> Words::getCharacters(){
      int numChars=word.length();
      for (int i=0;i<numChars;i++){
           characters.push_back(word[i]);
      }
      return characters;
}

bool Words::isFirstCharacterUppercase(){

   if(isupper(word[0])){
      firstCharacterUppercase=1;
   }
   else {
      firstCharacterUppercase=0;
   }
   return firstCharacterUppercase;
}

bool Words::isApostophePresent(){

   if()





}
Words::~Words(){}
1

There are 1 answers

3
systemcpro On
#include <string>
#include <iostream>

const std::string STR1 = "Hello'World";
const std::string STR2 = "Hello World";

bool hasApostrophe(const std::string& s){ 
  return s.find("'", 0, 1) != std::string::npos; 
}

int main(int, char**){

    std::cout << STR1 << " has apostrophe = " << hasApostrophe(STR1) << '\n';
    std::cout << STR2 << " has apostrophe = " << hasApostrophe(STR2) << '\n';
    return 0;
}