Ask 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 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. 3 December, 05:40
    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?
Find 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 the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers