Lab Assignment # 1, CSE 1320-501, Fall 2003

 

DUE DATE: Tuesday, 23 September 2003


Topic objectives:                              Control structures

                              Functions

                              1 - dimensional arrays

                              Programming style

 

Write a small program that will determine the following characteristics for a given integer input value.  The program must decide and print out the following information on separate lines for the input:

A)    Insure that the input value is a non-negative integer value not greater than 1,000,000.  If the number is not in this range, the program should print an error message and ask the user to enter a new value.

B)     Determine and print if the number is prime.   E.g. For an input of 11, the output for this determination would be similar to:  The input value 11 is prime.

C)    Determine and print if the number is odd or even.  E.g. For an input of 11, the output for this determination would be similar to:  The input value 11 is odd.

D)    Determine and print if the number is a multiple of 3, 5, 10 and/or 11.  E.g. For an input of 165, the output for this determination would be similar to:  The input value 165 is divisible by the factors 3, 5, 11.

E)     Determine and print if the number is a square or a cube of an integer value and if so, give the root.  E.g. For an input of 64, the output for this determination would be similar to:  The input value 64 is the square of 8.  (on the next line) The input value 64 is the cube of 4.

The program must let the user continue performing tasks up to ten times (excluding bad input attempts) or until the user indicates that he/she is finished working with the system if that is less than 10 times.   When the program is completed, the program should print out a list of all of the values tested by the user during the program run.

 

Implementation requirements:

The program should use the following data structures:

A float or double variable to accept the student’s input

An integer array to hold the 10 values (or less) that the user tested

 

The program should use the following control structures:

A while or for loop to read in the individual inputs

If, if-else, or nested ifs to choose the appropriate action

Function calls to perform the tasks

 

The program should be implemented as a set of functions with at least one function for each task above.  In the calling routine, the result of a previous function call can be used to determine whether to call another function, e.g. if the input is not 2 and is prime then it must be odd so it is not necessary to call the odd function to check it.

 

The program should perform the following actions in the given order:

Declare and initialize the variables

Print a welcome screen for the user that introduces the system

Get the needed input value from the keyboard

Print the appropriate outputs

Let the user enter additional values until the user has run the system 10 times or until the user indicates that they are finished, whichever comes first.

 

The program should have a program header which gives, at least, your name, the number of the lab assignment, your class and section, the assignment date, the due date, and a description of the program.  If multiple files are used, each file should contain a similar header. 

 

Each programmer-defined function, i.e. each function you write, should have a function header similar to those used in the examples in the textbook.  This header should include at least the function name, the purpose of the function, and its inputs and outputs.

 

This program must be run using the sample data that is given below AND must be run using your own sample data as well.  The sample data set that you create must meet the guidelines given in the problem definition.

 

The program output must be recorded in a script file from OMEGA using the gcc compiler.  If you do not know how to create a script file, it is your responsibility to ask the TA or OIT how to use this function.  

 

Sample input values:   25, 123, 666, 121, 987654, 0, -5, 5, 2, 125, 729


The program must be turned in TWO ways to receive credit. 1) A hardcopy is due to Dr. Tiernan no later than in class at 5:30pm 23 September 2003 (not 5:31pm) 2) An electronic copy must be e-mailed along with the script file of output to the TA, Raman Adaikkalavan, at raman@omega.uta.edu. Both the hardcopy and the electronic copy (softcopy) must be turned in on or before 5:30pm, Tuesday, 23 September 2003 in order to receive ANY credit.

 

Grading scale:

Code:    (66%)

Program header and function headers for all functions        (8 points)

Modularity (division of the problem into small tasks, each one assigned to its own function and called from main() or from another function when appropriate--do not code the entire program in main!)  (10 points)

Style (indentation, consistency, meaningful identifiers, lateral separation of code from line comments, etc.)  (10 points)

Correct manipulation of the 1-dimensional array  (10 points)

Correct use of required control structures (10 points)

Correct function structure as required (10 points)

Proper implementation of input error checking (8 points)

Output:          (34%)

               Each task performs mathematically correctly (3 points per task A, B, C, D, E)

               Output follows the form given above (2 points per task B, C, D, E)

               Output contains all the sample data and at least 5 more additional input values  (11 points)