Purchase Solution

C++: counting the occurrence of an item in a list

Not what you're looking for?

Ask Custom Question

Implement the function "count" which takes a list of items and an item as arguments, and returns the number of times the item occurs in the list.

template < typename T >
int count (const list < T > & aList, const T& item);

Write a C++ program that generates 20 random numbers in the range from 0 to 4. For each number, output its value and insert it into an integer list by using push_back(). In a loop, call the above count function, and display the number of occurrences of each value (0 to 4) in the list.

Purchase this Solution

Solution Summary

Attached program generates different set of random numbers during each run.

Purchase this Solution


Free BrainMass Quizzes
Inserting and deleting in a linked list

This quiz tests your understanding of how to insert and delete elements in a linked list. Understanding of the use of linked lists, and the related performance aspects, is an important fundamental skill of computer science data structures.

Java loops

This quiz checks your knowledge of for and while loops in Java. For and while loops are essential building blocks for all Java programs. Having a solid understanding of these constructs is critical for success in programming Java.

Basic Networking Questions

This quiz consists of some basic networking questions.

Excel Introductory Quiz

This quiz tests your knowledge of basics of MS-Excel.

Word 2010: Tables

Have you never worked with Tables in Word 2010? Maybe it has been a while since you have used a Table in Word and you need to brush up on your skills. Several keywords and popular options are discussed as you go through this quiz.