Question

Vowels and consonants Write a program that reads a word and prints the number of vowels...

Vowels and consonants
Write a program that reads a word and prints the number of vowels and consonants in the
word. For this exercise assume that ‘a’, ‘e’, ‘i’, ‘o’, ‘u’, and ‘y’ are vowels. For
example, if the user enters the input “Harry”, the program should print “The word
contains 2 vowels and 3 consonants”.

Homework Answers

Answer #1

In c++

#include<bits/stdc++.h>

using namespace std;

int main()
{
        //declaring the char array
        char arr[100];
        cout<<"Enter the word : ";
        //taking the word input
        cin>>arr;
        int cnst,vow,i;
        cnst=vow=i=0;
        //traversing the array till it founds the end end alphabet of the word
        while(arr[i]!='\0')
        {
                //checking for vowels
                if(arr[i]=='a' || arr[i]=='e' || arr[i]=='i' || arr[i]=='o' || arr[i]=='u' || arr[i]=='y')
                {
                        vow++;
                }
                //checking for capital letter vowels
                else if(arr[i]=='A' || arr[i]=='E' || arr[i]=='I' || arr[i]=='O' || arr[i]=='U' || arr[i]=='Y')
                {
                        vow++;
                }
                //else counting consonants
                else
                {
                        cnst++;
                }
                i++;
        }
        
        cout<<"The word contains "<<vow<<" vowels"<<" and "<<cnst<<" consonants.";
        
        return 0;
}

In Java

import java.util.*;

public class Main
{
        public static void main(String[] args)
        {
            //initializing the Scanner
                Scanner sc=new Scanner(System.in);
                String word;
                int n,i,vow,cnst;
                char check;
                vow=cnst=0;
                System.out.print("Enter the word : ");
                //taking the input
                word=sc.next();
                //calculating the word length
                n=word.length();
                for(i=0;i<n;i++)
                {
                    check=word.charAt(i);
                    //checking for vowels
                if(check=='a' || check=='e' || check=='i' || check=='o' || check=='u' || check=='y')
                {
                        vow++;
                }
                //checking for capital letter vowels
                else if(check=='A' || check=='E' || check=='I' || check=='O' || check=='U' || check=='Y')
                {
                        vow++;
                }
                //else counting consonants
                else
                {
                        cnst++;
                }
                }
                System.out.println("The word contains "+vow+" vowels and "+cnst+" consonants.");

        }
}
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a program that reads a word and then prints the word in reverse separated by...
Write a program that reads a word and then prints the word in reverse separated by a comma. 3 pts Note: No comma at the end of the reversed word. Enter word: Harry The reversed word is: y,r,r,a,H Python keep it simple
Lab Assignment | Count vowels Write a program that will use a while loop to count...
Lab Assignment | Count vowels Write a program that will use a while loop to count and display the number of vowels in the string provided as input by the end-user. This program will consider the letters a, e, i, o, and u (both upper and lower case) to be vowels. The user may enter a single word, a sentence, a paragraph, or nothing at all as input. Be sure to test each possibility. Python 3 please!
Write a program that reads a string and outputs the number of lowercase vowels in the...
Write a program that reads a string and outputs the number of lowercase vowels in the string. Your program must contain a function with a parameter of a char variable that returns an int. The function will return a 1 if the char being passed in is a lowercase vowel, and a 0 for any other character. The output for your main program should be: There are XXXX lowercase vowels in string yyyyyyyyyyyyyyyyyyyyyy Where XXXX is the count of lowercase...
problem 1 Write a program that asks the user for an integer and then prints out...
problem 1 Write a program that asks the user for an integer and then prints out all its factors. For example, when the user enters 84, the program should print 2 2 3 7 Validate the input to make sure that it is not a character or a string using do loop. in c plus plus
Write a JAVA program that reads in a string from standard input and determines the following:...
Write a JAVA program that reads in a string from standard input and determines the following: - How many vowels are in the string (FOR THE PURPOSE OF THIS PROGRAM 'Y' is NOT considered a vowel)? - How many upper case characters are in the string? - How many digits are in the string? - How many white space characters are in the string? - Modify the program to indicate which vowel occurs the most. In the case of a...
1 Design and implement FileCompare program that compares two text input files (file1.txt and file2.txt), line-by-line,...
1 Design and implement FileCompare program that compares two text input files (file1.txt and file2.txt), line-by-line, for equality. Print any lines that are not equivalent indicating the line numbers in both files. The language of implementation is java 2 . Create a program that reads a string input from the user, then determines and prints how many of each lowercase vowels (a, e. i, o, and u) appear in the entire string. Have a separate counter for each vowel. Also...
1)Write a program that asks a user for a number. If (and only if) the number...
1)Write a program that asks a user for a number. If (and only if) the number is greater than zero print “The number is valid” 2)Write a program that asks a user for a grade. If (and only if) the grade is greater than zero and less than 101, print “The grade is valid” 3)Write a program that asks a user how many widgets they want to buy and prints out what the user should pay. Widgets costs 10 dollars....
Write a Python program that reads in the month, day, and year of a date and...
Write a Python program that reads in the month, day, and year of a date and prints it in the dd/mm/yyyy format or mm/dd/yyyy format, the format depending on the user’s preference. The program also prints the message It is a magic date If the product of month and day is equal to the last two digits of the year. For example, April 20 1980 is a magic date because April (numeric value 4) multiplied by 20 is equal to...
design a program that prompts the user to enter a positive integer number and reads the...
design a program that prompts the user to enter a positive integer number and reads the user’s input. If the user input is not a positive number, the program should prompt them repeatedly until they enter a valid input. Once a valid input is received ,the program uses a loop to calculate the sum of the digits of the user’s input and displays the sum. For example, if the user enters the number 94311, the program should print the sum...
Write a python program that reads a word list and prints out all the anagrams in...
Write a python program that reads a word list and prints out all the anagrams in the word list. In earlier exercises you saw how to read a word list. Also, in earlier examples we saw how the sorted characters of a word are a useful canonical representation of an anagram (Hint: Therefore, useful as a key).
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT