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

Write a program that asks the user to enter a sentence. The program then reads t

ID: 3643689 • Letter: W

Question

Write a program that asks the user to enter a sentence. The program then reads the sentence and counts the number of each character in the sentence. Output the total number of characters in the sentence and the frequency of each character with a frequency greater than zero. Use the string class as the object into which the sentence is stored. You should use an array declared as int frequency[256] to count the frequency of each character in the string. Remember that you can index into the frequency array by a character in the string. That is, frequency[inputString[i]] is legal. Do not over think this problem. It really doesn

Explanation / Answer

I will be very happy to help you out..her are the two programs that you asked for-I hope you give me the best rating and you get the best grades!! :)

Program 1

#include<stdio.h>

#include<string.h>

main()
{
char string[100];
int c = 0, count[26] = {0};
printf("Enter a string ");
gets(string);
while ( string[c] != '' )
{
if ( string[c] >= 'a' && string[c] <= 'z' )
count[string[c]-'a']++;
c++;
}
for ( c = 0 ; c < 26 ; c++ )
{
if( count[c] != 0 )
printf("%c=%d ",c+'a',count[c]);
}
return 0;
}

Program 2

#include<iostream.h>

int main()

{int chcount = 0;

const char ent=' ';

char ch;

cout<<"Enter a string ";

cin.get(ch);

while ( ch!= ent )

{

chcount++;

cout.put(ch);

cin.get(ch);

}

cout<<" The no. of characters="<<chcount<<" ";
return 0;}

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