Question

In: Computer Science

Here is a Problem I need to solve: 5) Write a function to determine is a...

Here is a Problem I need to solve:

5) Write a function to determine is a given word is legal. A word is illegal if it contains no vowels. For this problem,
the letter Y is considered to be a legal vowel. Pass in a word to this function and it will determine if the word is
legal or not. You can make the following assumptions about the word you a passing to this function.
1) The string being passed is a combination of letters only (no non-letter check needed)
2) The string being passed is null terminated
3) Letters may be capital or lower case and it has no effect on whether its a word

I think I am in the right direction below. But the problem is my proposed solution involves two separate functions. My question is how I can make this one function?

  1. int isVowel(char c){

  2. if(c>='A' && c<='Z')

  3. c=c+32;

  4. if(c=='a' || c=='e' || c=='i'|| c=='o'|| c=='u'|| c=='y')

  5. return 1;

  6. else

  7. return 0;

  8. }

  9. int validString(char *c){

  10. int i;

  11. for(i=0;c[i]!='\0';i++)

  12. if(isVowel(c[i]))

  13. return 1;

  14. return 0;

  15. }

Solutions

Expert Solution

input code:

output:

code:

#include <stdio.h>
int validString(char *c)
{
/*declare the variables*/
int i;

/*check the characters*/
for(i=0;c[i]!='\0';i++)
{
/*check vowel or not*/
if(*(c+i)=='a' || *(c+i)=='e' || *(c+i)=='i'|| *(c+i)=='o'|| *(c+i)=='u'|| *(c+i)=='y')
{
//return true if vowel
return 1;
}
}
/*else return FALSE*/
return 0;
}
int main()
{
/*declare the variables*/
char word[10];
/*take user input*/
printf("Enter a word:");
scanf("%s",word);
/*call the function*/
if(validString(word))
{
/*print Legal*/
printf("Legal word");
}
else
{
/*print Inlegal*/
printf("illegal word");
}

return 0;
}


Related Solutions

/* I been trying to solve this problem . this is my own coding /here is...
/* I been trying to solve this problem . this is my own coding /here is the HW INSTRUCTION Let the user to try of maximum 8 times to find the random number For every try display if the user find or not the number and the number of tries At the end of each game display to the user the number of tries to find the number Allow the user to play a maximum of 4 times, by asking...
I have the answer for this problem but I need to solve it using Excel's PV...
I have the answer for this problem but I need to solve it using Excel's PV function for both products and I cannot seem to figure it out. What would I insert for each portion of the equation into excel? It has been answered on another question as number 2. http://www.chegg.com/homework-help/questions-and-answers/lou-barlow-divisional-manager-sage-company-opportunity-manufacture-sell-one-two-new-produc-q12342389?trackid=297667da&strackid=464d9914&ii=8
I need to write a function that takes a user-provided string like 1-3-5, and output a...
I need to write a function that takes a user-provided string like 1-3-5, and output a corresponding series of letters, where A is assigned to 1, B is assigned to 2, C is assigned to 3, etc. So in the case of 1-3-5 the output would be ACE. For 2-3-4, it should print BCD. For ?-3-4 or --3-4 it should still print BCD. **CANNOT USE LISTS, SETS, DICTS, ETC. CANNOT USE SPLIT FUNCTION. ** Here is the code I have...
Here is an outline for some code I need to write. This class used Intro to...
Here is an outline for some code I need to write. This class used Intro to Java Edition 11, and we only got to Chapter 9. There is no set right way that this program has to be done. Feel free to interpret this in a way that you wish. Mrs. Quackenbush is back! She now has bought a beverage establishment, The Green Dragon Inn, and needs to have a way to insure the consistency of the drinks her employees...
I need to write a function that counts the number of total wins and losses. I...
I need to write a function that counts the number of total wins and losses. I have a text file called analysis_data.txt with 1000 lines written Won Loss Won Loss Won Won ... The function need to do the following: Opens the analysis_data.txt file and reads through all the data, counting number of 'Won' and 'Loss' words stored in the file. Returns two integers: count of wins and count of losses from the text file. **Can't use the break statement
I need to write a function the will take in an array (of type double), and...
I need to write a function the will take in an array (of type double), and will return the array with all of the elements doubled while using pass-by-reference and addressing and/or pointers. This is what i have so far, but im messing up in line 31 where i call the function i believe so im not returning the correct array? please help edit. #include <iostream> #include <iomanip> using namespace std; double *doubleArray ( double arr[], int count, int SIZE);...
For an assignment I need to write a 5 page essay about any topic. I need...
For an assignment I need to write a 5 page essay about any topic. I need some some thinking of a topic and outlining of the topic.
Here is the entire problem; however the trial balance did not copy in correctly. I need...
Here is the entire problem; however the trial balance did not copy in correctly. I need to know how to calculate the basic consolidation entry (mostly income from Soda Company, Investment in Soda Company, NCI in NI and NCI in NA. Pop Corporation acquired 70 percent of Soda Company's voting common shares on January 1, 20X2, for $119,000. At that date, the noncontrolling interest had a fair value of $51,000 and Soda reported $70,000 of common stock outstanding and retained...
I need to solve math problem by using freemat or mathlab program. However, I can't understand...
I need to solve math problem by using freemat or mathlab program. However, I can't understand how to make a code it. This is one example for code ( freemat ) format long f = @(x) (x^2) % define f(x) = x^2 a=0 b=1 N=23 dx = (b-a)/N % dx = delta_x 1. Methods: (a) Left Rectangular Rule also known as Lower sum. (b) Right Rectangular Rule also know as upper sum. (c) Midpoint Rule (d) Trapezoid Rule (e) Simpson...
Problem 5: Find Smallest Elements In this problem, we will write a function to find the...
Problem 5: Find Smallest Elements In this problem, we will write a function to find the smallest elements of a list. Define a function named find_smallest() that accepts two parameters: x and n. The parameter x is expected to be a list of values of the same time, and n is expected to be an either integer, or the value None, and should have a default value of None. • If n is set to None, then the function should...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT