#include <iostream>
#include <conio>
#include <cstring>
#include <iomanip>
#include <ctype>
#define SIZE 26
void count(char[]);
void main ()
{
char sentence [1000];
cout<<"enteer your string" <<endl;
cin.getline (sentence, 1000);
count(sentence);
cin.get();
cin.get();
}
void count(char s[])
{
char alphabet[]= {'a' , 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
int i, count[SIZE]= {0};
for (i=0 ; i<strlen(s) ; i++)
{
s[i]=tolower(s[i]);
for (int j= 0 ; j<SIZE; j++)
if (s[i] == alphabet [j])
count [j]++;
}
for (i= 0 ; i<SIZE; i++)
if (count [i]>0)
cout<<count[i]<<" "<<alphabet[i]<<endl;
}
and here's the struct code I tried to convert.
Struct array
{
double numbers (int a);
void count_sentence (char s[]);
};
void main ()
{
const int max_size = 1000;
char sentence [1000];
cout<<"enter your string" <<endl;
cin.getline (sentence, 1000);
count_sentence(sentence);
cin.get();
cin.get();
}
void count_sentence(char s[])
{
char alphabet[]= {'a' , 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
int i, count_sentence[max_size]= {0};
for (i=0 ; i<strlen(s) ; i++)
{
s[i]=tolower(s[i]);
for (int j= 0 ; j<max_size; j++)
if (s[i] == alphabet [j])
count_sentence [j]++;
}
for (i= 0 ; i<max_size; i++)
if (count [i]>0)
cout<<count_sentence[i]<<" "<<alphabet[i]<<endl;
}
void count_numbers (int a)
{
for (i=0 ; i<max_size ; i++);
{
loop_number[i];
int i, count_numbers[max_size]= {0};
for (i=0 ; i<strlen(a) ; i++)
{
a[i]=(a[i]);
for (int j= 0 ; j<max_size; j++)
if (a[i] == loop_numbers [j])
count [j]++;
}
for (i= 0 ; i<max_size; i++)
if (count_numbers [i]>0)
cout<<count_numbers[i]<<" "<<loop_number[i]<<endl;
}
there so many errors, I'm new to C++ i've made some changes but still this is all I can do, can someone help me? the code above is mine, with a help from our instructor (for some improvements for the first code, just a little bit).

New Topic/Question
Reply



MultiQuote




|