Answer to Question #342385 in C++ for Magisk

Question #342385

Instructions:

  1. Declare and define hasConsonant() function with he following details: int return type name hasConsonant parameter char
  2. Return value - 1if there is atleast 1 consonant and 0 if there is none. Include Both capital and small letters when checking


Code:

#include <iostream>

using namespace std;


// TODO: Declare the hasConsonant() function here

int hasConsonant(int code)

  

int main(void) {

  char code[100];


  cout << "Enter the code: ";

  cin >> code;


  int result = hasConsonant(code);


  if(result == 1) {

    cout << "ALERT! There is a consonant in the code!";

  } else if(result == 0) {

    cout << "There is no consonant in the code. Situation is under control!";

  }


  return 0;

}


// TODO: Define the hasConsonant() function here


1
Expert's answer
2022-05-18T15:26:28-0400
#include <iostream>

using namespace std;




// TODO: Declare the hasConsonant() function here

int hasConsonant(char[100]);




int hasConsonant(int code);




int main() {

 char code[100];

 cout << "Enter the code: ";

 cin >> code;

 int result = hasConsonant(code);




 if(result == 1) {

  cout << "ALERT! There is a consonant in the code!";

 }

else if(result == 0) {

  cout << "There is no consonant in the code. Situation is under control!";

 }

return 0;

}

// TODO: Define the hasConsonant() function here

int hasConsonant(char* text){

  for(int i =0;i<100;i++){

    switch(text[i]){

      case 'a':  case 'o':  case 'u':  case 'e':  case 'y':  case 'i': return 1;

    }

  }

  return 0;

}

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