Question

CODE IN C++ 13.5 Alphabet Histogram Write a program that reads input character by character from...

CODE IN C++

13.5 Alphabet Histogram

Write a program that reads input character by character from the given data file "data.txt"

The program should be case insensitive and count the number of occurances of each character in the

alphabet. It should print a histogram of the results as follows:

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 :

THANK YOU

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main() {
    ifstream in("data.txt");
    if (in.is_open()) {
        int counts[26] = {0};
        char ch;
        while ((ch = (char) in.get()) != EOF) {
            if (ch >= 'a' && ch <= 'z') {
                ch -= 32;
            }
            counts[ch-'A']++;
        }
        for (int i = 0; i < 26; ++i) {
            cout << (char)('A'+i) << " : " << counts[i] << endl;
        }
        in.close();
    } else {
        cout << "data.txt does not exists!" << endl;
    }
    return 0;
}
Add a comment
Know the answer?
Add Answer to:
CODE IN C++ 13.5 Alphabet Histogram Write a program that reads input character by character from...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT