i'm a c++ beginner and now i got a question
i try many times but i stil can't solve it
so can anyboby here help me to solve?
here is my question:
Write a program that read in a sequence of characters in terms of sentences. Provide analysis of the input characters such as the number of characters of a, b and so on. Assume all characters are in lower case. Use a class concept in your program.
Sample outputs:
Enter your sentence: a program consists of a number of instructions separated by semicolon.
Analysis:
Character a: 5
Character b: 2
…..
character z: 0
this is my code:
#include<iostream>
using namespace std;
class analysis {
char sentence[80];
char str[80];
int counter;
int count;
public:
void read();
void compare();
void display();
void character();
};
void analysis::read()
{
cout << " Enter your sentence: " ;
cin.getline(sentence,80);
}
void analysis::character()
{
str={'a','b','c','d','e','f','g','h','i','j','k','l','m','o','p','q','r','s','t','u','v','w','x','y','z','\0'};
}
void analysis::compare()
{
for(int i=0; sentence[i]; i++)
{
for(int j=0; sentence[j]; j++)
{
if(strcmp(str,sentence)==0)
count+=counter[j];
}
}
}
void analysis::display()
{
cout << " ANALYSIS : " << endl;
for(int m=0; m<strlen(sentence); m++)
cout << " Character " << str[m] << " : " << counter[m] << endl;
}
void main()
{
analysis word;
word.read();
word.character();
word.compare();
word.display();
}
if i want to try to use the ASCII code, how can i use it?