Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is a c# language using Visual Studio 2015. my question is: How can I identi

ID: 671099 • Letter: T

Question

This is a c# language using Visual Studio 2015.

my question is:

How can I identify the upper and lower case characters? If I enter a sentence with both upper and lower case charaters, the program will distinguish them , so they will count the each number of upper and lower case characters. I want to change this that from A to Z and including the space character, how many times each character appears in the text. Ignore the case of the character, so uppercase 'A' and lowercase 'a' are the same character for the purposes of this assignment. And only print the number of occurances for characters that appear at least once.

Here is the codes that i got so far.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

using Microsoft.VisualBasic;

namespace SentenceAnalyzer2

{

class Program

{

static void Main(string[] args)

{

string sentence = Interaction.InputBox("Enter any sentence ", "Sentence Analyzer");

sentence = sentence.Trim();

char[] sentArrays = new char[sentence.Length];

// count the total number of characters.

for (int i = 0; i < sentArrays.Length; i++)

{

sentArrays[i] = sentence[i];

}

// output string.

string str = " ";

str += "Your sentence was: ";

str += """ + sentence + "" ";

str += "Total number of characters: " + sentArrays.Length + " ";

// count the number of characters.

int[] countArray = new int[sentArrays.Length];

for (int i = 0; i < countArray.Length; i++)

countArray[i] = 0;

Array.Sort(sentArrays);

for (int i = 0; i < sentArrays.Length; ++i)

{

for (int j = 0; j < sentArrays.Length; ++j)

{

if (sentArrays[i] == sentArrays[j])

{

countArray[i]++;

}

}

}

// count the spaces.

int count = 0;

for (int i = 0; i < countArray.Length; i++)

{

if (sentArrays[i] == ' ')

count++;

else

str += "Number of " + sentArrays[i] + "'s: " + countArray[i] + " ";

}

str += "Number of spaces: " + count + " ";

// count the most and least frequent characters.

int max = 0, min = 0;

char maxChar = ' ', minChar = ' ';

// int index1 =0 , index2 = 0;

for (int i = 0; i < sentArrays.Length; i++)

{

if (countArray[i] >= max)

{

max = countArray[i];

maxChar = sentArrays[i];

}

else if (countArray[i] <= 1)

{

min = countArray[i];

minChar = sentArrays[i];

}

}

str += " The most frequent character was: " + maxChar + " ";

str += " The least frequent character was: " + minChar + " ";

MessageBox.Show(str, "Sentence Analyzer");

}

}

}

InputBox dialog will look like the following, assuming the user types in what is shown as their sentence like this.

Explanation / Answer

Sample output:

Code to copy:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

using Microsoft.VisualBasic;

namespace SentenceAnalyzer2

{

    class Program

    {

        static void Main(string[] args)

        {

            string orgSentence = Interaction.InputBox("Enter any sentence ",   "Sentence Analyzer");

            orgSentence = orgSentence.Trim();

            string sentence = orgSentence.ToLower();

            char[] sentArrays = new char[sentence.Length];

        

            int spaceCount=0;

            int[] count = new int[26];

            for (int i = 0; i < 26; i++)

            {

                count[i] = 0;

            }

            // count the total number of characters.

            for (int i = 0; i < sentArrays.Length; i++)

            {

                sentArrays[i] = sentence[i];

                if (sentArrays[i] == ' ')

                    spaceCount++;

                else

                    count[(int)(sentArrays[i] - 96)]++;

               

            }

           

            int max = count[0], min = 9999999;

            char maxChar=' ', minChar=' ';

            for (int i = 0; i < count.Length; i++)

            {

                if (count[i] >= max)

                {

                    max = count[i];

                    maxChar = (char)(i + 96);

                }

                else if (count[i] < min && count[i]!=0)

                {

                    min = count[i];

                    minChar = (char)(i + 96);

                }

            }

           

            // output string.

            string str = " ";

            str += "Your sentence was: ";

            str += """ + orgSentence + "" ";

            str += "Total number of characters: " + sentArrays.Length + " ";

            for (int i = 0; i < count.Length; i++)

            {

                if (count[i] != 0)

                {

                    str += "Number of " + (char)(i + 96) + "'s: " + count[i]

                            + " ";

                }           

            }

            str += "Number of spaces: " + spaceCount + " ";

          

            str += " The most frequent character was: " + maxChar + " ";

     str += " The least frequent character was: " + minChar + " ";

     MessageBox.Show(str, "Sentence Analyzer");

           

        }

    }

   }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote