C programming

CS 159 – HW #07
5 Points Possible
Due: July 30, 2012 at 11:00pm.

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

Problem: You enjoy collecting marbles and keep them all in a jar. In this jar you have a variety of colors and for each
color present in your jar you have the same amount of marbles. For example, if you have 40 marbles in the jar and four
different colors (blue, red, green, white), then you will have 10 of each. Given that you’d rather not count ALL of the
marbles in your jar you remove at least one of each color and ALL of the marbles of at least one color and from this you
will calculate the total number of marbles in the jar.

Example Execution #1:

Enter data #1 or -1 to exit: 1
Enter data #2 or -1 to exit: 2
Enter data #3 or -1 to exit: 3
Enter data #4 or -1 to exit: 4
Enter data #5 or -1 to exit: 1
Enter data #6 or -1 to exit: 2
Enter data #7 or -1 to exit: 3
Enter data #8 or -1 to exit: 4
Enter data #9 or -1 to exit: 3
Enter data #10 or -1 to exit: 3
Enter data #11 or -1 to exit: 3
Enter data #12 or -1 to exit: 2
Enter data #13 or -1 to exit: 3
Enter data #14 or -1 to exit: 1
Enter data #15 or -1 to exit: 2
Enter data #16 or -1 to exit: -1

Total number of coins: 24

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

• Explanation – there are four unique colors (1, 2, 3,
and 4) and all of the marbles of the third color (3)
have been removed from the jar. The total of
marbles is 24.

Example Execution #2:

Enter data #1 or -1 to exit: 3
Enter data #2 or -1 to exit: 3
Enter data #3 or -1 to exit: 3
Enter data #4 or -1 to exit: 5
Enter data #5 or -1 to exit: 5
Enter data #6 or -1 to exit: 5
Enter data #7 or -1 to exit: 8
Enter data #8 or -1 to exit: 2
Enter data #9 or -1 to exit: 8
Enter data #10 or -1 to exit: 2
Enter data #11 or -1 to exit: 2
Enter data #12 or -1 to exit: 8
Enter data #13 or -1 to exit: -1

Total number of coins: 12

• Explanation – there are four unique colors and three
of each. All marbles have been removed from the
jar.

Additional Requirements:

1. Accept input and produce output exactly as seen in the example executions.
◦ There is no input to validate.
◦ The user will always enter at least two values before enter the -1 to indicate the end of input.
◦ The maximum number of marbles that may be entered as input is 500.

2. You MUST make good use of user-defined functions! Failing to meet this requirement will result in a zero
for the assignment.
◦ Recall what is acceptable in a main function and those tasks that must be factored into user-defined

functions.
◦ Tasks such as input, output, and calculations should be delegated to functions and should not be left inside of

the main function.
3. DO NOT use any material found outside of the first EIGHT chapters of the C text.

◦ You may reference the course resources when it comes to the sorting algorithms. Be sure to list your source
for any course that you take from the course resources.

4. DO NOT make use of control-forcing statements such as exit, break, continue, or multiple return statements
inside of single function.

5. Variables with global scope are never permitted in an assignment.
6. A program must compile to be considered for partial credit.

Academic Integrity Reminder:

• Please review the policies of the course as they relate to academic integrity. The assignment you submit should be
your own original work. You should be consulting only course staff regarding your specific algorithm for
assistance. Collaboration is not permitted on individual homework assignments.

Course Programming and Documentation Standards Reminders:

• Use the course function header (head_fx) for every user-defined function in your program.
◦ List and comment all parameters to a function, one per line, in the course function header.
◦ All function declarations will appear in the global declaration section of your program.
◦ The user-defined function definitions will appear in your program after main and can be in any order.

• Make good use of symbolic constants and minimize your use of literal constants.
• All arrays will be declared of a fixed size. This size should be represented by a symbolic/defined constant.
• Place a single space between all operators and operands.
• Comment all variables to the right of each declaration. Declare only one variable per line.
• Do not permit your local declaration and executable statement sections to overlap in a function!
• Select meaningful identifiers (names) for all variables and functions in your program.
• Indent all code found within the main and all user-defined functions exactly two spaces.

◦ And indent all code found inside of selection and repetition constructs (those with a body, all code between
{ and }) two additional spaces.

• Do not single (or double) space the entire program, use blank lines when appropriate.

When you submit… only the last attempt of a submission is kept for grading. All other submissions are over-written and
cannot be recovered. You may make multiple submissions but only the last attempt is retained and graded.

• Verify in the e-mail sent to you by the course that you have submitted the correct file, to the correct assignment
(hw07), and to the correct lab section. Forwarding course e-mails from Purdue to external e-mail services may
result in the mail being undelivered or end up being identified as spam.

• Leave time prior to the due date to seek assistance should you experience difficulties completing or submitting
this assignment.

• All attempts to submit via a method other than through the sage server as set up during the first week of the
semester will be denied consideration. (Reference: http://goo.gl/dMm4i)

Assignment deadlines… are firm and the electronic submission will disable promptly as advertised. We can only grade
what you submit as expected (including the correct assignment and lab section) prior to the assignment deadline.

All course programming and documentation standards are in effect for this and each
assignment this semester. Please review this document in your course notes packet.

http://goo.gl/dMm4i

Still stressed from student homework?
Get quality assistance from academic writers!

Order your essay today and save 25% with the discount code LAVENDER