Table of Contents

Corning Community College

CSCS1320 C/C++ Programming

Project: CALCULATING N-ARY VALUES (cnv0)

Objective

To create a program that can calculate and determine the number of factor pairs of a given number, starting with values composed of exactly 2 sets of factor pairs.

GRABIT

To assist with consistency across all implementations, data files for use with this project are available on lab46 via the grabit tool. Be sure to obtain it and ensure your implementation properly works with the provided data.

lab46:~/src/SEMESTER/DESIG$ grabit DESIG PROJECT

Please study any provided code, comments, or supporting documents, and look up, experiment, and ask questions on aspects that you do not understand.

EDIT

You will want to go here to edit and fill in the various sections of the document:

CNV0

Background

Determining factor pairs

To determine factor pairs you can make an iterative loop, and check for how many times your input value is evenly divided by a number, ie. for 6 you would check:

6 % 1 = 0, 6 % 2 = 0, 6 % 3 = 0, 6 % 4 = 2, 6 % 5 = 1, 6 % 6 = 0

There are 4 zeros, so 6 has 4 factors.

Determining factor pairs takes a little bit more work than you would imagine, as you cannot simply divide by 2, because of square numbers, who have an odd number of factors.

Instead, you can ignore 1 as a factor, divide the amount of other factors by 2, then add 1 to your amount of factor pairs.

This process may look like:

int i;
for (i=2; i<=input; i++) {
    if ((input % i) == 0) {
    factorpairs++;
    }
}
factorpairs = (factorpairs / 2) + 1

Compiling

Loops

for() loops

A for loop is a loop that iterates based on a set of given parameters for example a for loop that starts at 0 and iterates 1000 times would look like:

int i;
for (i=0; i<=1000; i++) {
    whatever you want to happen;
} 

An example of a for loop that shows what iteration the loop is on, i.e Iteration: 0, Iteration: 1, etc. until it reaches Iteration: 9 and ends the loop:

int i;
for (i = 0; i < 10; i++) {
    printf("Iteration: %d\n", i);
}
while() loops

A while loop is a loop that continues to iterate as long as the input evaluates to true. a while loop that iterates until an input variable reaches some designated value may look like:

while (var != 100) {
    whatever you want it to do;
    }

If you arent careful with your condition a while loop will iterate endlessly, preventing your code from moving past the loop

unsigned int var = 0;
var = 20;
while (var == 20){
    do something that doesnt effect var;
    }
the rest of your code;

In this case, because var never changes from 20, the while loop will never end You can also achieve this endless iteration by typing

 while (true) {
    some code;
    }

Because the condition is always true it will never escape the loop

do-while loops

A do-while loop issues commands then checks the condition rather than checking the condition and then issuing the commands.

int i = 5;
do
{
    i--;
} while ( i > 0 )

An example of a do-while loop being used. This loop will check if the user has inputted the correct password. The loop will continue until number equals 1234:

int number;
do {
    printf("Enter the password: ");
    scanf("%d", &number);
} while (number != 1234);
 

Program

It is your task to write a program that, upon accepting various pieces of input from the user, computes the number of factor pairs of a given number, displaying its eligibility as a secondary number.

Specifications

Your program should:

Some additional points of consideration:

Process

In general, you will be looking to do something like the following:

DISPLAY PROMPT
READ NUMBER

SHOULD NUMBER BE LOWER THAN TWO:
    DISPLAY AN ERROR
    EXIT WITH A NON-ZERO STATUS

SO LONG AS FACTOR IS LESS THAN NUMBER:
    SHOULD THE FACTOR BE A LEGITIMATE FACTOR OF NUMBER:
        INCREMENT COUNT OF FACTOR PAIRS
        SHOULD THIS NUMBER HAVE A SQUARE FACTOR:
            INCREMENT COUNT OF FACTOR PAIRS

SHOULD THE NUMBER OF FACTOR PAIRS MATCH WHAT WE ARE LOOKING FOR:
    DISPLAY THAT NUMBER BEING PROCESSED IS OF THE NEEDED TYPE
OTHERWISE:
    DISPLAY THAT THE NUMBER BEING PROCESSED IS NOT THE NEEDED TYPE

Reference

Copied as part of the grabit, inside your cnv0/ subdirectory, will be a copy of my implementation (in executable form, by the name ref_cnv0), which abides by the project specifications. Please compare its output against that of your implementation. You can invoke the reference implementation by running the following:

yourpi:~/src/SEMESTER/DESIG/cnv0$ make check
Enter a number: 6
6 is a secondary number
yourpi:~/src/SEMESTER/DESIG/cnv0$ 

Verification

In addition, I have also placed a cnv0verify script in that same subdirectory, which will test your program against a range of values, to determine overall correctness. You can run the verify script using the Makefile, as follows:

yourpi:~/src/SEMESTER/DESIG/PROJECT$ make verify
[  1] you have: err, should be: err    [  2] you have:  no, should be:  no
[  3] you have:  no, should be:  no    [  4] you have: yes, should be: yes
[  5] you have:  no, should be:  no    [  6] you have: yes, should be: yes
[  7] you have:  no, should be:  no    [  8] you have: yes, should be: yes
[  9] you have: yes, should be: yes    [ 10] you have: yes, should be: yes
[ 11] you have:  no, should be:  no    [ 12] you have:  no, should be:  no
[ 13] you have:  no, should be:  no    [ 14] you have: yes, should be: yes
[ 15] you have: yes, should be: yes    [ 16] you have:  no, should be:  no
[ 17] you have:  no, should be:  no    [ 18] you have:  no, should be:  no
[ 19] you have:  no, should be:  no    [ 20] you have:  no, should be:  no
[ 21] you have: yes, should be: yes    [ 22] you have: yes, should be: yes
[ 23] you have:  no, should be:  no    [ 24] you have:  no, should be:  no
[ 25] you have: yes, should be: yes    [ 26] you have: yes, should be: yes
[ 27] you have: yes, should be: yes    [ 28] you have:  no, should be:  no
[ 29] you have:  no, should be:  no    [ 30] you have:  no, should be:  no
[ 31] you have:  no, should be:  no    [ 32] you have:  no, should be:  no
[ 33] you have: yes, should be: yes    [ 34] you have: yes, should be: yes
[ 35] you have: yes, should be: yes    [ 36] you have:  no, should be:  no
yourpi:~/src/SEMESTER/DESIG/PROJECT$ 

SUBMISSION

To successfully complete this project, the following criteria must be met:

Submit Tool Usage

To submit this program to me using the submit tool, run the following command at your lab46 prompt:

lab46:~/src/SEMESTER/DESIG/PROJECT$ make submit

And make sure you get no error messages.

You should get some sort of confirmation indicating successful submission if all went according to plan. If not, check for typos and or locational mismatches.

RUBRIC

I'll be evaluating the project based on the following criteria:

52:cnv0:final tally of results (52/52)
*:cnv0:resources obtained via grabit by Sunday before deadline [4/4]
*:cnv0:proper error checking and status reporting performed [6/6]
*:cnv0:correct variable types and name lengths used [6/6]
*:cnv0:proper output formatting per specifications [6/6]
*:cnv0:proper selection logic applied to perform comparisions [6/6]
*:cnv0:proper iteration logic applied to carry out process [6/6]
*:cnv0:runtime verify tests of submission succeed [6/6]
*:cnv0:no negative compiler messages for program [6/6]
*:cnv0:code is pushed to lab46 repository [6/6]

Pertaining to the collaborative authoring of project documentation

Additionally