bartleby

Concept explainers

Question
Book Icon
Chapter 18, Problem 2P
Program Plan Intro

Histogram of positive numbers

Program Plan:

  • Include required header file.
  • Include required “std” namespace.
  • Define main function
    • Declare a variable in “map” template class.
    • Initializes the variable “numbers” to “0”.
    • Display prompt statement.
    • Performs “while” loop. This loop will perform upto “numbers” equal to “-1”.
      • In this loop, first read the number from user.
      • If the number is not equal to “-1”, then check if the number is in map or not using “find” function.
        • If it is, then assign “mapResult[numbers]” is “1”.
        • Otherwise, increment the counter
    • Declare constant iter “result” in “map” template class.
    • Display the given result using “for” loop.

Blurred answer
Students have asked these similar questions
Please write a full C++ code and provide code and output  Two stacks of the same type are the same if they have the same number of elements and their elements at the corresponding positions are the same. Overload the relational operator == for the class linkedStackTypethat returns true if two stacks of the same type are the same; it returns false otherwise. Also, write the definition of the function template to overload this operator.
Write a function that gets a linked list of ints, and reverses it. For example - on input 1 -> 2 -> 3 -> 4, after the function finishes the execution, the list becomes 4 -> 3 -> 2 -> 1 - If the list has one element, then it doesn’t change - If the list is empty, then it doesn’t change You may use the data fields in the struct and the functions provided in LL.h and LL.c. // reverses a linked list void LL_reverse(LL_t* list);   Test for the Function: void test_q3() { LL_t* lst = LLcreate(); LL_add_to_tail(lst, 1); LL_add_to_tail(lst, 3); LL_add_to_tail(lst, 8); LL_add_to_tail(lst, 4); LL_add_to_tail(lst, 3); LL_reverse(lst); intcorrect[] = {3,4,8,3,1}; inti; node_t* n = lst->head; for(i=0;i<5;i++) { if (n==NULL) { printf("Q3 ERROR: node %d==NULL unexpected\n", i); return; } if (n->data != correct[i]) { printf("Q3 ERROR: node%d->data==%d, expected %d\n", i, n->data, correct[i]); return; } n = n->next; } if (n==NULL) printf("Q3 ok\n"); }     Support…
Write a function that gets a linked list of ints, and reverses it. For example - on input 1 -> 2 -> 3 -> 4, after the function finishes the execution, the list becomes 4 -> 3 -> 2 -> 1 - If the list has one element, then it doesn’t change - If the list is empty, then it doesn’t change You may use the data fields in the struct and the functions provided in LL.h and LL.c. // reverses a linked list void LL_reverse(LL_t* list);   Test for the Function; void test_q3() { LL_t* lst = LLcreate(); LL_add_to_tail(lst, 1); LL_add_to_tail(lst, 3); LL_add_to_tail(lst, 8); LL_add_to_tail(lst, 4); LL_add_to_tail(lst, 3); LL_reverse(lst); intcorrect[] = {3,4,8,3,1}; inti; node_t* n = lst->head; for(i=0;i<5;i++) { if (n==NULL) { printf("Q3 ERROR: node %d==NULL unexpected\n", i); return; } if (n->data != correct[i]) { printf("Q3 ERROR: node%d->data==%d, expected %d\n", i, n->data, correct[i]); return; } n = n->next; } if (n==NULL) printf("Q3 ok\n"); }   Support File…
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning