Sei sulla pagina 1di 3

COP 3223 Introduction to C Programming, Section 5, Fall 2015

Assignment 5
Assigned Thursday 1st October and Due Thursday 8th October 2015 at 11:30 pm.
This assignment is worth a maximum of 100 points
Objectives
By completing this program students will demonstrate their knowledge of
1. How loops work in C
2. C syntax for reading input from a text file
3. Storing data in a 1D array
4. Manipulating data stored in a 1D array
5. Reading data from a text file in C
Problem: Abundant Numbers
Abundant numbers are positive integers (greater than 0), that are less than the sum of
their proper divisors. A proper divisor is a positive integer into which that number can be
divided with no remainder. A proper divisor must also be less than the number itself.
For example, 6 is a proper divisor of 12, but 12 is not a proper divisor of 12. The proper
divisors of 12 are 1,2, 3, 4 and 6. Their sum is 16 - (1+2+3+4+6), which is greater than
12. Therefore, 12 is an example of an abundant number. As this example shows, one way
to find out all the proper divisors of a number is to try out each integer (starting at 1) until
you reach the number divided by 2.
Write a program that reads in a list of numbers from an input text file called input.txt.
For each number read, your program should determine and print out whether or not that
number is abundant. The format for the input file is specified in the section: Input
Specification.
Input Specification
1. The first line of the file contains a single integer n that is less than 100. This number
(n) indicates the number of test cases in the file.
2. The next n lines will each contain a single positive integer (less than 100). Your
program must test each of these numbers to determine whether it is abundant or not.
Output Specification
Output a line with one of the two the following formats for each test case:
Test case #t: X is abundant.
Test case #t: X is NOT abundant.
where t represents the number of the test case (starting with 1), and X represents the
number for that case.

Restrictions:
1. Your program should include a header and other comments.
2. You may assume that all of the numbers in the file are valid
3. When run, your program should output the text shown in the sample output,
although the numbers may be different.
4. The sample runs are just that - samples! They show how your program should
behave. Your program should work correctly, no matter what numbers are in the
input file even values different from those in the samples.
Submission:
Your assignment should be submitted via Webcourses by the deadline. No assignments
will be accepted via email. Your submission should be a single .c file called abundant.c.
Remember that your program will be graded using DevC++ , so be sure that your
submitted code runs correctly in this IDE. If you do not have DevC++ on your personal
machine, you may use a computer in any lab to test your code.

Grading Details
Your program will be graded using the following criteria:
1) Your correctness
2) Your programming style and use of white space. (Even if you have a plan and your
program works perfectly, if your programming style is poor or your use of white space
is poor you could get 10% or 15% deducted from your grade.)
3) If your program does not compile the highest possible grade that you can receive is
50%.

Sample Output
Below are 2 examples of how your code should behave. Note that these examples are not
exhaustive. You should also test your program with different data than is shown here
based on the specifications given.
Sample run 1
Sample Input (input.txt)
3
6
12
17
Sample Output (Corresponding to Sample Input File)
Test case #1: 6 is NOT abundant.
Test case #2: 12 is abundant.
Test case #3: 17 is NOT abundant.

Sample run 2
Sample Input (input.txt)
5
20
8
16
24
9
Sample Output (Corresponding to Sample Input File)
Test case #1: 20 is abundant.
Test case #2: 8 is NOT abundant.
Test case #3: 16 is NOT abundant.
Test case #4: 24 is abundant.
Test case #5: 9 is NOT abundant.

Potrebbero piacerti anche