This is C# language using visual studio 2015. my question is: please modify my c
ID: 671159 • Letter: T
Question
This is C# language using visual studio 2015.
my question is:
please modify my codes to get an output like the given picture. When I execute my program, some outputs are different with the ouput that i have to show. Can anybody help with me? please modify it correctly... Thank you very much!!
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();
sentence = sentence.ToLower();
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 result = "Your sentence was: "" + sentence + "" ";
result += "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 and characters.
int count = 0;
for (int i = 0; i < countArray.Length; i++)
{
if (sentArrays[i] == ' ')
count++;
else
result += "Number of " + sentArrays[i] + "'s: " + countArray[i] + " ";
}
result += "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];
}
if (countArray[i] <= 1)
{
min = countArray[i];
minChar = sentArrays[i];
}
}
result += " The most frequent character was: " + maxChar + " ";
result += " The least frequent character was: " + minChar + " ";
MessageBox.Show(result, "Sentence Analyzer");
}
}
}
This is the output that I have to show up.
Your InputBox dialog will look like the following, assuming the user types in what is shown as their sentence Sentence Analyzer Enter any sentence OK Cancel This is a sample sentence And your MessageBox giving the output should look something like the following Sentence Analyzer Your sentence was: "This is a sample sentence" Total number of characters: 25 Number of a's: 2 Number of c's: 1 Number of e's: 4 Number of h's:1 Number of i's: 2 Number of I's:1 Number of m's: 1 Number of n's: 2 Number of p's: 1 Number of s's: 4 Number of t's: 2 Number of spaces: 4 The most frequent character was: s The least frequent character was: c OKExplanation / Answer
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();
sentence = sentence.ToLower();
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 result = "Your sentence was: "" + sentence + "" ";
result += "Total number of characters: " + sentArrays.Length + " ";
Array.Sort(sentArrays);
SortedDictionary<char, int> dict = new SortedDictionary<char, int>();
for (int i = 0; i < sentArrays.Length; i++){
if (dict.ContainsKey(sentArrays[i])== false)
dict.add(sentArrays[i],1);
else
dict[sentArrays[i]] += 1;
}
foreach(KeyValuePair<char, int> entry in myDic){
if (entry.key == ' ')
result += "Number of space : " + entry.value + " ";
else
result += "Number of " + entry.key + "'s: " + entry.value + " ";
}
int max = 0, min = sentArrays.Length + 1;
char maxChar = ' ', minChar = ' ';
foreach(KeyValuePair<char, int> entry in myDic){
if (entry.value < min){
min = entry.value;
minChar = entry.key;
}
else if (entry.value > max){
max = entry.value;
maxChar = entry.key;
}
}
result += " The most frequent character was: " + maxChar + " ";
result += " The least frequent character was: " + minChar + " ";
MessageBox.Show(result, "Sentence Analyzer");
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.