Lab Assignment #1

                                  CSE 1320

                                Spring 2006

 

Instructor : Carter Tiernan

 

ASSIGNED: Thursday, January 26, 2006

DUE     : Thursday, February 9, 2006

CONCEPTS: arrays and pointers, parameter passing by reference, linear search

POINTS  : 100

WEIGHT  : 10%

 

Our music store, The Roberts Music Corporation, has hired you as part of its research and development group.  Your responsibilities will be to focus on issues associated with broadening the company's product lines, expanding it's personnel department, and larger advertising campaigns in an effort to increase the bottom line of the company's profit statement.

 

Your initial responsibilities will focus on developing software necessary to support the expanded infrastructure.  The overall project description is to build a program that develops some routines that will be used for the expanded databases.  The functions you’ll be writing will read in data from the user, echo the data to the screen, average and sum values in an array to be used eventually to capture inventory information, look for duplication of data within an array to determine correctness of estimated expenses, and look for duplication of data between two arrays to insure correctness of inventory receipts. 

 

Since you are part of an established R&D department, your software must conform to existing guidelines for development.  These guidelines will be given later in this document.  The structure of the program is to be as follows.  The main routine will declare the arrays to be used to store data and will call the other functions to perform their tasks in the order given below.  The program will use two arrays of type double containing 19 elements each.  These arrays will be passed to each function in turn.  Since, by default, arrays are passed by reference, main() will see any changes to the elements in the arrays made by the called functions.  The tasks called by the main routine should be called in the following order:

 

Step 1: Declare arrays and initialize all array elements to 0.0

Step 2: Read the data in from the user for the first 12 values of both arrays,

Step 3: Echo the array data from both arrays back to the screen,

Step 4: Find the sum and the average of the numbers in the first array and store those values,

Step 5: Find the sum and the average of the numbers in the second array and store those values,

Step 6: Look for duplicated data in the first array and record any duplicates,

Step 7: Look for duplicated data in the second array and record any duplicates,

Step 8: Look for duplicated data between the two arrays and record any duplicates,

Step 9: Print the final array contents of both arrays to the screen.

 

Step 2 will call a function that first prompts the user for 12 values of type double, to be entered one value per line. and then reads in those twelve values from the keyboard buffer and stores them in the first array, beginning at index zero and ending at index eleven.  Once data has been read in for the first array, the function should do the same thing to get 12 more values and store these in the same fashion in the second array.  The arrays will be passed in from the main routine to this function and the function’s formal parameters should accept them in array notation.  All manipulation in the function should also be done with array notation.

 

Once the data is read into the arrays, then in Step 3 this data should be printed to the screen for the user’s inspection.  Step 3 should call a function that accepts the arrays in pointer notation.  The function should manipulate the arrays in pointer notation throughout.  The function should produce a table of values that contains, on each line, the array index value followed by the contents of the index in the first array and then the contents of that index in the second array.  Print all the elements of the arrays, even if nothing has been stored there yet.  Don’t forget to put a header line at the top of the table.  A partial example would be:

 

Index          Array 1 value       Array 2 value

0                  76.3                    92.1

1                  4.0                    22.2

 

When the data has been printed, then the main routine will call a set of functions to perform various actions on the array data.  Step 4 and Step 5 will be performed by a function that will sum all the 12 original values in the array and then store this sum in the array at index 12.  This function will then calculate the average of the original 12 values and store this average value in location 13.  This function must use only array notation throughout including the input parameters.

 

Step 6 and Step 7 will be performed by a function that will determine if there are any duplicate values in the array within the original 12 values (indices 0 .. 11 inclusive).  This function will search every element of the array in order (linear search).  If a value does appear more than once in the array then store a copy of that value at array location 14.  If a second pair of duplicates is found, store that value in array index 15.  There will not be more than two duplicate pairs. This function must use only pointer notation throughout including the input parameters.  If the comparison seems to work improperly NOTE:  Even if the value stored in the first element of the array is 1.051, comparing it with the hard coded number 1.051 using the comparison operator may not evaluate as true because of the way floating-point numbers are stored (precision may be different even when numbers look the same).  However, if needed, 1.051 can be represented as 1051 (by multiplying by 1000 and then typing casting the value to an integer), and comparison of equal integers usually does return true.

 

 

Step 8 will performed by a function that will compare the 12 original values in both arrays to look for duplicates.  If an original value in the first array also appears in the original values in the second array (indices 0 .. 11 inclusive) then store this value at array location 16 in BOTH arrays.  If a second duplicate is found, store that value at location 17 in both arrays.

 

Step 9 will output the arrays again using the same function as used in step 3 to print out all the values in both arrays.

 

 

Implementation requirements:

The program should use the following data structures:

Two one-dimensional double arrays for recording user data and calculation results

 

The program should use the following control structures:

Function calls to perform tasks

A while or for loop to perform input and input error checking

If, if-else, or nested ifs to do comparisons of values

 

The program should NOT use:

                structs

                multiple dimension arrays

        switch statements

        global variables

        goto

        exit

                any topic not covered in class before the lab DUE date unless approved by the instructor

 

The program should be implemented as a set of functions as defined above.  You may use more functions than this but you must use at least this many. 

 

This program must be written using two files.  The first file will contain all the declarations needed for the program.  This will consist of #include statements, constant and #define declarations, and all function prototypes.  The second file will contain the main function and all the function definitions.  Use a conditional compilation instruction at the beginning of each file as shown below:

 

#ifndef  FILEONE  //This command should be on the first line of the file

#define FILEONE  //Use a different variable in the second file

 

//  file contents: #includes, constant definitions and prototype defintions

 

#endif  //This command  should be the last line of the file.  It matches #ifndef.

 

The constants file should include both 19 (array size) and 0.0 (array initial value) defined as constants with either #define or const.

 

NOTE:  when naming the files, include the type and number of assignment in the file name and your omega ID, and use a .c extension (ex: lab1exz1234A.c).  Do not use a .h extension, as OMEGA will not separately compile a .h file, and separate compilation of each file is required

 

 

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 indicates that they are finished.

 

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 with three different sets of data for the array contents.  The first data set (data set 1) should use the values given below.  You must also create two additional data sets and run your program with them as well.  You may run it three times within a single execution or you may execute the program three different times so that you have a total of three different data sets. The sample data sets that you create must meet the guidelines given in the problem definition.

 

Sample input values for data set 1:

 

 

            STORE AT

            INDEX     ARRAY #1         ARRAY #2

            -----------------------------------

               0       4.396           1.114

               1       4.395           9.443

               2       1.114           8.726

               3       3.981           1.115

               4       4.394           4.397

               5       4.397           1.010

               6       4.396           1.100

               7       0.001           9.443

               8       0.010           0.000

               9       1.010           4.397

               10      0.100           0.020

               11      0.010           0.002

 

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.   See also the file linked to Dr. T’s website labeled “How to turn in a 1320 lab including script file.”

 

There should be no control characters at the end of each line of code in the script file as these will cause the printed copy of the script session to be double spaced.  If your script file prints double-spaced you can remove these control characters using the 'col' command with the "-b" switch, on OMEGA, as in the example:

 

              col -b < lab2scriptA.txt > lab2script.txt

 

SUMBIT by e-mail to the TA the source code and the script file and TURN IN in class on the due date a complete hardcopy script session of the code developed for this assignment, in the order shown below (refer to the example script session in the file on the website).  This script session must be produced on the student's own OMEGA account and must include all programmer-developed source code files.

 

Script session contents:

a directory listing of your directory on omega with the lab assignment in it

a 'cat' of File #1

a compilation of File #1, using 'gcc' 

another  directory listing of your directory on omega showing the addition of the compiled file

a 'cat' of File #2

a compilation of File #2, using 'gcc'

another  directory listing of your directory on omega showing the addition of the compiled file

the run of the program with three sets of data

 

The software must also follow the guidelines already set by the Roberts Music Corp. R&D group:  These guidelines are pertinent to the remaining assignments in this course and are part of the grading of the lab.  These guidelines are for the purpose of helping us write code that adheres to good software engineering principles and industry standards.  There are guidelines for style, for documentation and for modularity.  These guidelines will have different point values in different assignments but should be followed in all assignments.

 

Style

Use meaningful identifiers for variables, constants, function names, etc.

No hard-coded numbers may be used except as constants defined in the constants file

Consistent use of braces placement around blocks of code is required

No more than one instruction per line of code

Consistent and reasonable use of indentation must be used

No wrap-around lines of code

Line comments should be separated horizontally from code being described

Whitespace should be used to separate declarations from instructions in function

Horizontal whitespace should be used to separate operators from operands

If a switch statement is used, it should include a default case

Documentation

Function header for entire program contains all required information as stated above.

File header is given in each file and function headers are given for all functions

Comments/documentation are included in code

Output is single-spaced

Any specified documentation requirements for time-stamping and the like are met

Modularity

Functions perform one primary task each.

Main routine acts primarily as driver for the rest of the functions in the program

Files are used to segregate parts of program for separate compilation

 

Grading scale:

Code:      (72%)

 

Style  (10 points total)

Use of meaningful identifiers for variables, constants, function names, etc. (1)

No hard-coded numbers used except as constants defined in the constants file (1)

Consistent use of braces placement around blocks of code (1)

No more than one instruction per line of code (1)

Consistent and reasonable use of indentation (2)

No wrap-around lines of code (1)

Line comments are separated horizontally from code being described (1)

Use of whitespace to separate declarations from instructions in function (1)

Use of horizontal whitespace to separate operators from operands (1)

Documentation (3 points total)

Function header for entire program contains all required information as stated above. (1)

File header in each file and function headers for all functions (1)

Comments/documentation included in code (1)

Modularity  (63  points total) (files and functions perform specific tasks as defined)

File #1 (the constants file) requirements (10 points)

#include all required system files (2)

Define and initialize all required constants, in alphabetical order by constant name, using either of the forms as given - #define or const (4)

Declare all function prototypes other than main(4)

File #2 (the functions file) requirements. (2 points)

File 2 does NOT do any of the tasks assigned to File #1. (2)

Main function (also called the driver function) requirements  (10 points)

Declare the main data structures that will be used to store the numbers (3)

Correct manipulation of the 1-dimensional arrays  (3 points)

Call all required functions in the order specified above passing the appropriate parameters (4)

Input function requirements  (9 points total)

Use array notation for formal arguments of this function and in the code of the function. (1)

Prompt the user for values of type double, to be entered one value per line. (4)

Read in the two sets of twelve values each from the keyboard buffer and store them in the appropriate arrays, beginning at index zero and ending at index eleven  (4)

Proper implementation of input error checking as appropriate ()

Output function requirements   (5 points total)

Use pointer notation for its formal arguments and in the code of the function.  (1)

Print table of output of both arrays as specified above (4)

Sum and average function requirements   (11 points total)

Use array notation for its formal arguments and in the code of the function. (1)

Sum the values stored in the array being passed to it  (2)

Store sum in the same array at index 12  (2)

Find the floating-point average of the values in the array at indices 0 .. 11 inclusive  (4)

Store that average in the same array at index 13  (2)

Find duplicates within array function requirements   (8 points total)

Use pointer notation for its formal arguments and in the code of the function.  (1)

Determine if there are any duplicate values in the array in indices 0 .. 11 inclusive  (3)

If a number appears more than once, then store that floating-point number in the same array at index 14.  (2)

Check for a second duplicate and store that second number if found at index 15.  (2)

Find duplicates between arrays function requirements   (8 points total)

Use array notation for its formal arguments and in the code of the function. (1)

Determine if there is any value in the first array which is also in the second array. (3)

Store any duplicated value in both arrays at index 16 (2)

Check for a second duplicate and store that second number if found at index 17 in both arrays (2)

 

Output:    (24%)

User clearly understands what is being requested for input (specific and complete) (1 pt)

Output is accurate (5)

Output gives clear information to explain the values to the user (readability) (5 points)

Files  (3 points total)

No control characters at the end of each line of code in the script session, causing double spacing (1)

Files conditionally compiled (2)

Submission requirements   (10 points total)

a 'cat' of File #1 (1)

a compilation of File #1, using 'gcc'  (1)

a 'cat' of File #2  (1)

a compilation of File #2, using 'gcc'  (1)

required directory listings (2)

the run of the program with three sets of data  (4)

 

Deductions:

                A program which produces warnings or errors during compilation, linking or execution will result in an overall grade of 0 (zero)

                Use of global variables will result in an overall grade of 0 (zero)

                Use of the goto  command will result in an overall grade of 0 (zero)

                Use of the exit command will result in an overall grade of 0 (zero)

                Use of structs, multiple dimension arrays, and/or switch statements will result in 20 (twenty) point deduction per use

                Submissions lacking either source code or  script files from omega in hard or soft copy will result in a deduction of points.

                Late submission of softcopy to appropriate TA will result in an overall grade of 0 (zero) without prior instructor approval

                Use of C language elements not yet discussed in class by the lab due date will result in potential deduction of points – discuss with instructor before using.

 

 

 

 

 

HINT:  After reading the assignment and before writing any code, most pro-

        grammers will do the following:

       

        1.  choose the main data structures (which are already chosen for this

             assignment--see above)

            

        2.  divide the problem into small tasks, assigning each task to its own

             function (this is already done for this assignment--see above)

 

        3.  choose meaningful identifier names for:

       

       

            a.  file names

            b.  function names

            c.  constant names

            d.  for each function,

                (1)  a name for each formal argument

                (2)  a name for each local variable

 

HINT:  After printing the script session, check it against the points

        allocated for this assignment, and for missing code (code that

        runs off the right margin of the page), missing file(s), etc.  Each

        student is responsible for the appearance of his/her script session on

        paper.

 

       Also, check with the TAs and/or myself if you have any questions--that

        is what we are here for!