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

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;
        }
    }
}

take 4 controls on the form with 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

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...
Write a C++ function to print out all unique letters of a given string. You are...
Write a C++ function to print out all unique letters of a given string. You are free to use any C++ standard library functions and STL data structures and algorithms and your math knowledge here. Extend your function to check whether a given word is an English pangram (Links to an external site.). You may consider your test cases only consist with English alphabetical characters and the character.
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...
Need a c++ program to generate a random string of letters between 8 and 16 characters.
Need a c++ program to generate a random string of letters between 8 and 16 characters.
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 }
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.
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...
I've created a C# Windows form application in Visual stuidos it allows the user to enter...
I've created a C# Windows form application in Visual stuidos it allows the user to enter information, save that information to a database, then show that information in a datagridview. Everything works fine but the datgridview. It shows that rows have been added but not the text. I can see in my database the reports that have been added so I know its alteast saving the information. I don't know what I'm doing wrong. Please help! My code: using System;...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT