Lab 6 - Tallying

Due: Oct 25, 11:55pm

Moodle Link

N001_0690_002.jpg

Instructions

  • Turn in the code (a cpp file or ideone.com link), and the run outputs as requested below.
  • Remember to format the code as described and the book and text, and to include comments including complete commetns at the beginning of the program.
  • You will need to do a sort for this problem. You may use the sort function given in class, or write your own!

Grading Table

Requirement Grading Comments Points Score
Good clean, easy to understand input and output operations (All sort code included)   10  
Program handles input error conditions appropriately   10  
Complete source code with good formatting and organization, variables names, and comments   10  
Functions: Logic divided up into cohesive functions with a single purpose   20  
Runs: Run examples from trials with correct output on required trial data   50  

Problem

Write a program that reads in a list of integers into an array with base type int . The program will require the user to input the numbers. You may assume that there are fewer than 50 entries in the array. If the user specifies more than 50, you should provide an error message, and ask them to reenter. The output is to be a two-column list. The first column is a list of the distinct array elements; the second column is the count of the number of occurrences of that element. The list should be sorted on entries in the first column, smallest to largest.

For example, for the following input:

Input the number of entries: 16
Enter the numbers:-12 3 -12 4 1 1 -12 1 -1 1 2 3 4 2 3 -12
Number  Count
-12     4
-1      1
1       4
2       2
3       3
4       2

Hints

  1. Don't try to code this program until you work out an algorithm on paper, and can manually step through it on paper!
  2. It is MUCH easier to count the number of occurances if you sort the numbers first, then do the counting.
  3. Use additional arrays to store the unique numbers found, and the matching counts for each of those unique numbers.

Turn In

Runs of the following:

Trials

#1

Input the number of entries:40
Enter the numbers:3 5 4 5 7 6 8 2 3 2 3 1 2 1 1 1 5 4 5 6 4 6 4 6 4 2 5 4 6 2 7 6 7 4 8 5 7 8 9 2

#2

Input the number of entries:20
Enter the numbers:23 54 23 -12 54 34 54 -34 14 0 -17 54 -12 0 0 54 34 0 12 45

#3

Input the number of entries:50
Enter the numbers:1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 

#4

Show how the program responds to bad input with too many entries (>50) selected, and zero numbers selected.

Solutions


  • N001_0690_002.jpg:
Topic attachments
I Attachment History Action Size Date Who Comment
JPEGjpg N001_0690_002.jpg r1 manage 1503.6 K 2016-09-30 - 18:41 JimSkon  
Edit | Attach | Watch | Print version | History: r11 | r9 < r8 < r7 < r6 | Backlinks | Raw View | Raw edit | More topic actions...
Topic revision: r7 - 2016-10-17 - JimSkon
 
  • Edit
  • Attach
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback