Answer to Question #349902 in C++ for Magisk

Question #349902

Instructions

  1. Define the hasVowel() function with the following details
  2. Return type - int
  3. Name - hasVowel
  4. Parameter:
  5. char* - to hold the character array
  6. Return value - 1 if there is at least 1 vowel and 0 if there is none. Be sure to consider both the capital and small letter vowels when checking.

Given code

#include <iostream>

using namespace std;


int main(void) {

  char word[100];


  cout << "Enter the word: ";

  cin >> word;


  int result = hasVowel(word);


  if(result == 1) {

    cout << "There is a vowel in the word \"" << word << "\"";

  } else if(result == 0) {

    cout << "There is no vowel in the word \"" << word << "\"";

  }


  return 0;

}


Ex

Enter·the·word:·CodeChum

There·is·a·vowel·in·the·word·"CodeChum"


1
Expert's answer
2022-06-13T08:27:34-0400
#include <iostream>
#include <cstring>
using namespace std;

int hasVowel(char* word);

int main(void) {
  char word[100];

  cout << "Enter the word: ";
  cin >> word;

  int result = hasVowel(word);

  if(result == 1) {
    cout << "There is a vowel in the word \"" << word << "\"";
  } else if(result == 0) {
    cout << "There is no vowel in the word \"" << word << "\"";
  }

  return 0;
}

int hasVowel(char* word){
	int v = 0;
	char vowels[6] = {'a','o','e','u','i','y'};
	for(size_t i=0; i<strlen(word); i++){
	    for(int j=0; j<6; j++){
	        if(tolower(word[i]) == vowels[j]){
	            v = 1;
	        }
	    }
	};
	return v;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS