Tags: %TAGME{ tpaction="" web="KenyonCpp" tag="" }% view all tags

Lab 5

Due: Oct 6, 11:55pm


  • 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.


Feature %
Program correctness and completeness with respect to defination 70%
Code Format (Indenting, variable names) 10%
Code Comments 10%
Turning in complete run of every function at least twice with difference values. 10%


1. One problem we have encountered is using cin for numeric data. If we enter a non-nueric value when the system is expecting a numberic value, the cin object goes into an error state, and all further =cin='s are ignored.One solution to this problem was persented here: Link.

What we want to do is write a function that gets the next integer from cin, and returns both the integer and a true, but if the input is NOT an integer, it returns zero and false. This will allow us to know if the input number is an integer, and handle the situation of non-interger input smoothly.

The method we will employ

2. 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 meaage, 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 each element. The list should be sorted on entries in the first column, largest to smallest.

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

the output should be

N Count
4 2
3 3
2 2
1 4
-1 1
-12 4
Edit | Attach | Watch | Print version | History: r8 | r5 < r4 < r3 < r2 | Backlinks | Raw View | Raw edit | More topic actions...
Topic revision: r3 - 2015-10-05 - JimSkon
  • Edit
  • Attach
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2020 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback