Ask Question
11 November, 09:56

Write a program that uses the map template class to compute a histogram of positive numbers entered by the user. The map's key should be the number that is entered, and the value should be a counter of the number of times the key has been entered so far. Use - 1 as a sentinel value to signal the end of user input. 512355321-1Then the program should output the followings:The number 3 occurs 2 timesThe number 5 occurs 3 timesThe number 12 occurs 1 timesThe

+5
Answers (1)
  1. 11 November, 12:55
    0
    See explaination

    Explanation:

    #include

    #include

    #include

    #include

    #include

    #include

    using namespace std;

    int main ()

    {

    map histogram;

    int a=0;

    while (a>=0)

    {

    cout << " enter value of a";

    cin >>a;

    histogram[a]++;

    }

    map::iterator it;

    for (it=histogram. begin (); it! = histogram. end (); it++)

    {

    cout << (*it). first << " occurs " << setw (3) << (*it). second << (((*it). second = = 1) ? " time." : " times.") <
    }

    return 0;

    }
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a program that uses the map template class to compute a histogram of positive numbers entered by the user. The map's key should be ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers