--

closed account (3vMSy60M)

Last edited on
Hello enque,

Where does the input come from?

What code do you have so far? And post what you have. We can work from there.

If you set up your output as:

Ch Fr 1 2 3 4 5 6
-------------------
a 6 a a a a a a
e 3 e e e
o 4 o o o o 


It sets the first line off as headings. The spacing can be worked on later.

Andy
closed account (3vMSy60M)
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
#include <string>
#include <algorithm>
#include <cctype>
#include <iomanip>

// print the counts of occurrences of char ch in str
void print_counts( const std::string& str, char ch )
{
    // https://en.cppreference.com/w/cpp/algorithm/count
    const auto n = std::count( str.begin(), str.end(), ch ) ; 

    if( n > 0 ) // note: std::string( n, ch ) - a string of size n, where each character is ch
        std::cout << ch << std::setw(4) << n << "  " << std::string( n, ch ) << '\n' ;
}

int main()
{
    const std::string vowels = "aeiou" ;

    std::string str ;
    std::getline( std::cin, str ) ;
    std::cout << str << "\n\n" ;
    
    // range based loop: http://www.stroustrup.com/C++11FAQ.html#for
    for( char& c : str ) c = std::tolower(c) ; // convert to all lower case

    // print the histogram of vowels
    for( char v : vowels ) print_counts( str, v ) ;
}

http://coliru.stacked-crooked.com/a/cc63e2898fffcc04
Topic archived. No new replies allowed.