Question

In: Computer Science

In visual C# enter a string: "Mississippi". Results come out as" there are 11 letters with...

In visual C#

enter a string: "Mississippi".

Results come out as" there are 11 letters with 4 vowels and 7 consonants".

Create the following methods to complete this application:

Methods

int countLetters(string userInput)

  • Create integer variable to store the number of letters
  • Use foreach to cycle through each character in the string userInput
    • Check to see if the character is a letter (IsLetter). If it is, count as a letter
  • The method will return a numeric value which is the count of letters

int countVowels(string userInput)

  • Create integer variable to store the number of vowels
  • Use foreach to cycle through each character in the string userInput
    • Use if else if decision structure to check to:
      • If the character is NOT a letter (IsLetter), then you can continue (skip past the else if)
      • Else, if the letter is an upper case letter (IsUpper) then convert it to lower case (ToLower)
    • Use a switch decision structure to increase the variable created to count for the cases: a, e, i, o, u
  • The method will return a numeric value which is the count of vowels

int countConsonants(string userInput)

  • Call countVowels and store the result in a variable
  • Call countLetters and store the result in a variable
  • Subtract the number of vowels from the number of letters and store the result in a variable
  • The method will return a numeric value which is the count of consonants

Events

btnAnalyze_Click

  • Display results in lblResults after calling countLetters, countVowels, and countConsonants

HINTS:

  • Tutorial 8-1 p. 477-480 shows an example application that uses methods to determine whether a password has the appropriate characters based on the given criteria.

  • Use a "break;" clause to skip a section of an decision statement.

  • Reminder: Methods do not go in an event. Place the methods in the form namespace, but not in any event.

Solutions

Expert Solution

take 4 controls on the form & set following properties

1. Label, name = lblResults, text= Results:
2. Label, name = label2, text= Enter a string:
3. TextBox, name = txtInput
4. Button, name = btnAnalyze, text= Analyze

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace project1
{
    public partial class frmCountVowels : Form
    {
        public frmCountVowels()
        {
            InitializeComponent();
        }

        private void btnAnalyze_Click(object sender, EventArgs e)
        {
            int l = 0, v = 0, c = 0;
            l = countLetters(txtInput.Text); //get Letter count
            v = countVowels(txtInput.Text); //get Vowel count
            c = countConsonants(txtInput.Text); //get Consonants count
            lblResults.Text = "There are " + l + " letters with " + v + " vowels and " + c + " consonants";
        }

        int countLetters(string userInput)
        {
            int lettersCount = 0;
            foreach (char ch in userInput) //get each character from the userInput string
            {
                if (Char.IsLetter(ch)) //if character is a letter
                {
                    lettersCount++;   //increase count
                }
            }
            return lettersCount;
        }

        int countVowels(string userInput)
        {
            int a = 0, e = 0, i = 0, o = 0, u = 0;
            int vCount = 0;
            char ch;

            foreach (char letter in userInput) //get each character from the userInput string
            {
                ch = letter;
                if (!Char.IsLetter(ch)) //if character is not letter
                {
                    continue;   //skip to next character
                }
                else if (ch == Char.ToUpper(ch))   //if character is uppercase
                {
                    ch = Char.ToLower(ch);      //convert it to lowercase
                }

                switch (ch)
                {
                    case 'a':
                        a++;
                        vCount++;
                        break;
                    case 'e':
                        e++;
                        vCount++;
                        break;
                    case 'i':
                        i++;
                        vCount++;
                        break;
                    case 'o':
                        o++;
                        vCount++;
                        break;
                    case 'u':
                        u++;
                        vCount++;
                        break;
                }
            }
            return vCount;
        }

        int countConsonants(string userInput)
        {
            int consonantsCount = 0, vowels = 0, letters = 0;
            vowels = countVowels(userInput);    //get Vowel count
            letters = countLetters(userInput);  //get Letter count

            consonantsCount = letters - vowels;

            return consonantsCount;
        }
    }
}

output


Related Solutions

In visual C# enter a string: "Mississippi". Results come out as" there are 11 letters with...
In visual C# enter a string: "Mississippi". Results come out as" there are 11 letters with 4 vowels and 7 consonants". Create the following methods to complete this application: Methods int countLetters(string userInput) Create integer variable to store the number of letters Use foreach to cycle through each character in the string userInput Check to see if the character is a letter (IsLetter). If it is, count as a letter The method will return a numeric value which is the...
Assume user will enter letters or numbers that are out of range. When user inputs invalid...
Assume user will enter letters or numbers that are out of range. When user inputs invalid values, show an alert message and ask user to enter a valid value again. Validate first and then proceed with the program. isNaN() method may be useful. Must validate user input. 1. Suggested Filename: fortune.html & fortune.js Write a program that simulates a fortune cookie. The program should display one of five unique fortunes, depending on user input. The user must enter a number...
C++ Write a program that lets the user enter a two letters which are f and...
C++ Write a program that lets the user enter a two letters which are f and s with a length of 5. And outputs how many times it was occurred and lists the 2 most repeating pattern with 5lengths of f and s. The output display should always start at three-f(s) .Include an option where user can retry the program. Example: Input: sssfsfsfssssfffsfsssssfffsffffsfsfssffffsfsfsfssssfffffsffffffffffffssssssssfffsffffsssfsfsfsfssssfffsssfsfsffffffssssssffffsssfsfsfsss Output: The most repeating 5lengths of pattern is: fffsf and occurred 6times. Output2: The second most repeating...
How to write a C++ program that lets the user enter a string and checks if...
How to write a C++ program that lets the user enter a string and checks if it is an accepted polynomial. Accepted polynomials need to have one term per degree, no parentheses, spaces ignored.
Write a C++ function that lets the user enter alphabet letters into a static char array...
Write a C++ function that lets the user enter alphabet letters into a static char array until either the user enters a non-alphabet letter or, it has reached the MAXSIZE. You can use the isalpha([Char]) function to check if the input is an alphabet letter or not. void fillArray (char ar[], size_t& size){ // this is the function prototype }
String Manipulator Write a program to manipulate strings. (Visual Studio C++) In this program take a...
String Manipulator Write a program to manipulate strings. (Visual Studio C++) In this program take a whole paragraph with punctuations (up to 500 letters) either input from user, initialize or read from file and provide following functionalities within a class: a)   Declare class Paragraph_Analysis b)   Member Function: SearchWord (to search for a particular word) c)   Member Function: SearchLetter (to search for a particular letter) d)   Member Function: WordCount (to count total words) e)   Member Function: LetterCount (ONLY to count all...
C code please (1) Prompt the user to enter a string of their choosing. Store the...
C code please (1) Prompt the user to enter a string of their choosing. Store the text in a string. Output the string. (1 pt) Ex: Enter a sample text: we'll continue our quest in space. there will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. nothing ends here; our hopes and our journeys continue! You entered: we'll continue our quest in space. there will be more shuttle flights and...
C++ (1) Prompt the user to enter a string of their choosing (Hint: you will need...
C++ (1) Prompt the user to enter a string of their choosing (Hint: you will need to call the getline() function to read a string consisting of white spaces.) Store the text in a string. Output the string. (1 pt) Ex: Enter a sample text: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. Nothing ends here; our hopes and our journeys continue!...
why do we see different colors come out when all the colors of white light enter...
why do we see different colors come out when all the colors of white light enter the drop? explain not only what happens but why explain why there is a second rainbow further out from the primary rainbow how is the second rainbow different from the primary(other then its position in the sky what explains why the sky is darker between the primary and secondary rainbow than above the primary?
This is C++. It's based on structured data, chapter 11 of Starting out with C++. Please...
This is C++. It's based on structured data, chapter 11 of Starting out with C++. Please use basic operations. Please read the requirements carefully and make sure it's executable. The first 2 answers that I received are nowhere close. Thank you. Secret Codes! Create a program that will accept a message from the user and either encrypt ordecrypt it with the following algorithms: To encrypt: get the character you wish to encrypt find the index of that character in the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT