User Tools

Site Tools


haas:fall2013:common:discrete-p03-20121011142000

Set Program: Part 1

Overview

With our covering of sets, it makes sense to reinforce those concepts through code. I'd like you to develop the beginnings of a program that will manipulate sets.

Criteria

Write a program that does the following:

  • Prompt the user to input a value (the set elements), keep reading them in until the user specifies a terminating value (say, -1).
  • As sets must have unique elements in their membership, the program should check for and prevent the inclusion of any duplicate values into the set.
  • Once the set building is complete, display the set in the mathematical-esque set notation we viewed (see example below).

Assumptions

You may develop the program with the following assumptions in mind:

  • Stick to one type of data (byte-valued whole numbers, ASCII chars, etc. don't try to be universal).
  • In future iterations of this program, we'll be using multiple sets, but you may assume support for only a single set at this time.
  • If you are in Data Structures, this is an excellent program to practice using Linked Lists in. Singly or Doubly can work.
  • If you are not in Data Structures, obviously you'll want to use some sort of container, and if you're not familiar with Linked Lists, you've really only got one choice remaining: arrays.
  • If using an array, you obviously will have to assume a max size for your set.

Example Output

You resulting program should operate in a manner similar to the following (output doesn't have to exactly match):

lab46:~/src/discrete/p03$ ./setprog
Enter a unique value (-1 to quit): 1
Enter a unique value (-1 to quit): 2
Enter a unique value (-1 to quit): 4
Enter a unique value (-1 to quit): 8
Enter a unique value (-1 to quit): 16
Enter a unique value (-1 to quit): 4
Duplicate Value Detected! Discarding...
Enter a unique value (-1 to quit): 32
Enter a unique value (-1 to quit): 64
Enter a unique value (-1 to quit): -1

Set Built. Displaying...

A = { 1, 2, 4, 8, 16, 32, 64 }

lab46:~/src/discrete/p03$ 

Submission

I will be evaluating your program one-on-one at the start of class, when this is due. If you do not show up, you will not receive credit any for it.

Please be sure your program also meets the following criteria:

  • Codebase is documented. You must have comments sprinkled throughout your code.
  • Code is uniformly and optimized for readability in its indentation. I will be evaluating indentation!
  • Your code must compile and run, without warnings or issues, with the above requirements (I may ask for a specific set membership).
  • The displaying of the set MUST conform to that set notation (note the spacing, the commas, and the lack of a comma following the last element).
  • Your code must adequately detect and omit duplicates.
  • Your working, compilable code should be added/commit/pushed to your repository located in the ~/src/discrete/submit/p03/ directory.
haas/fall2013/common/discrete-p03-20121011142000.txt · Last modified: 2012/09/30 16:01 by 127.0.0.1