using namespace std;
const string empty_string = "";
const string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const int nalphas = 26;
int max(int a[], int size);
int main()
{
int* counts = new int[nalphas];
for (int idx = 0; idx < nalphas;="">
counts[idx] = 0;
cout < "enter="" input="" file="" name:="">
string file_name;
getline(cin, file_name);
ifstream finp;
finp.open(file_name);
assert(finp.good());
string line;
int alpha_count = 0;
while (!getline(finp, line).eof())
{
for (int idx = 0; idx < line.size();="">
{
char target = toupper(line[idx]);
int alpha_idx = alphabet.find(target);
if (alpha_idx >= 0)
{
counts[alpha_idx]++;
alpha_count++;
}
}
}
finp.close();
int mode = counts[max(counts, nalphas)];
int fwidth = static_cast(log10(alpha_count)) + 1;
for (int idx = 0; idx < nalphas;="">
{
cout < alphabet[idx]="">< '="" '="">< setw(fwidth)=""><>
if (counts[idx] == mode)
cout < '="" '=""><>
cout <>
}
cout < " ="" "="">< setw(fwidth)="">< alpha_count=""><>
system("pause");
return 0;
}
int max(int a[], int size)
{
if (size <>
return -1;
int max_idx = 0;
for (int idx = 1; idx < size;="">
if (a[idx] > a[max_idx])
max_idx = idx;
return max_idx;
}
-----------------------------------------------------------------------------------
Expert, there are two questions below that I have answered.
Please check to see if my answers are correct and if not please give correct answer/s.
1. Find the mode's count?
if (a[idx] > a[max_idx])
max_idx = idx;
return max_idx;
2. Find the values whose counts equal the mode's count?
if (counts[idx] == mode)
cout < '="" '=""><>
cout <>