Lab Assignment #2

                                  CSE 1320

                                Spring 2006

 

Instructor : Carter Tiernan

 

ASSIGNED: Thursday, February 16, 2006

DUE     : Thursday, March 9, 2006

CONCEPTS           Structs

                                Arrays of structs

                                Sorting

                                Recursion

                                File input

                                Modification and reuse of code

POINTS  : 100

WEIGHT  : 10%

 

 

The research and development group of our music store, Roberts Music Corporation, have been given the task of expanding the software infrastructure to support current and additional product line information in such a way as to be able to find areas that can be used to maximize profits.  From the previous work you did with the R&D group, you will be modifying and reusing some code you have already written.  You will also be writing additional modules to perform new functions.  Furthermore you will be reading in the data from a file and storing the data into different data structures than were previously used.

 

As before, your software must conform to existing guidelines for development.  Your overall tasks for this program will be to read in inventory data for a number of items in the store from a file, store this data into an array of structs, calculate some information about each item and save that data, the sort and print the data based on a number of different factors. 

 

The data to be stored for one inventory item consists of a number of pieces of information.  This data for each unique inventory item must be stored in one struct which has a field for each piece of information listed below. 

 

Fields of data for an inventory item:

Inventory item number   (a number of 8 digits)

Inventory item name  (a string of not more than 80 characters stored with a dynamically allocated char pointer)

Inventory item quantity   (must be a whole number)

Inventory item date received (in DDMMYYYY format)

Inventory item manufacturer’s cost for one item  (should be displayed in dollars and cents)

Inventory item size category   (category FLAT is sheet music and books, category MEDIA is CDs, tapes and items like packets of guitar strings, category SMALL is items less than 12” on a side, category MID is items less than 24” in all dimensions, and category LARGE is items larger than this which includes most instruments and amplifiers, etc.;  the category values (FLAT, MEDIA, …)should be declared with an enumerated type)

Inventory item profit percentage goal  (this is a real value representing the profit desired on the item - .15 is 15% profit, 2.0 is 200% profit – i.e. the markup)

Inventory item average shelf time in weeks (average amount of time an item of this type sits in the store before being purchased)

 

Inventory item retail price  (calculated from manufacturer’s cost and expected profit using equation given below)

Inventory item depreciated profit percentage (a value calculated based on shelf time, size and expected profit using the algorithm given below)

Inventory item expected selling price   (calculated from manufacturer’s cost and actual profit using equation given below)

 

 

For each item, the inventory item number, name, quantity, date received, manu. cost, category, profit goal,  and avg. shelf time will be read in from a file with one piece of data per line.  There will be no more than 10 inventory items during the phase of development but the maximum number of inventory items should be represented by a constant that can be easily changed.  Your program should have a function to read all of the inventory information into an array of structs, one struct per inventory item. 

 

Once all the data has been read in from the file, your program should echo the data to the screen with an output function.  You may modify your previous output function to perform this task if desired.

 

Next your program should calculate and store the retail price for each item by multiplying the item’s manufacturer’s cost times the profit percentage goal and adding this result to the original manufacturer’s cost to get the retail price.  After all the retail prices have been calculated, your program should echo at least the item name, item number manufacturer’s cost, profit goal and retail price to the screen with an output function.

 

After finding the retail price your program should call a recursive function to calculate and store the depreciated profit percentage.  The depreciated profit percentage is calculated to indicate that the overall profit is less the longer the item has to be in the store and that larger items will yield less profit over a shorter period.  The algorithm uses the average shelf time in weeks, the profit percentage goal and a deduction percent based on size as follows:

 

For items of size FLAT, MEDIA and SMALL, the deduction percent is 2%.

For items of size MID, the deduction percent is 5%.

For items of size LARGE, the deduction percent is 10%.

 

For all items the depreciated profit percentage is calculated recursively as follows:

 

For average shelf time in weeks < 2, the depreciated profit percentage is the same as the profit percentage goal.

For average shelf time in weeks == 2, the

Week 2 depreciated profit percentage equals (profit percentage goal times (1 – ( 2 * deduction percent)))

For average shelf time in weeks = n and n > 2, the

Week n depreciated profit percentage = (Week (n-1) depreciated profit percentage times (1 – (n * deduction percent)))

 

 

Once the program has found the depreciated profit percentage, it should call a function to calculate and store the expected selling price by multiplying the item’s manufacturer’s cost times the depreciated profit percentage and adding this result to the original manufacturer’s cost to get the expected selling price.  After all the expected selling prices have been calculated, your program should echo at least the item name, item number manufacturer’s cost, profit goal, retail price, depreciated profit percentage and expected selling price to the screen with an output function.

 

Once all the calculations are complete, the program should give the user a menu of choices for actions to perform including ending the program.  The user may continue to choose actions from this menu until they choose to end the program.  The user menu should have the following choices:

 

1)     Print all the inventory data

2)     Sort the array by inventory item name and print just the item names in the sorted order

3)     Sort the array by inventory item number and print just the item names and numbers in the sorted order

4)     Sort the array by fastest moving item (least shelf time) and print just the item names and shelf times in the sorted order

5)     Sort the array by largest profit (retail price minus manufacturer’s cost) and print just the item names, the costs and the retail prices in the sorted order

6)       Sort the array by largest depreciated profit percentage and print just the item names, the manufacturer’s costs, depreciated profit percentages, and the expected selling prices in the sorted order

7)       End the program

 

Because we are using structs, your program may use a different sorting function for each of the sorts listed above.  You must at least use a bubble sort for sorting by name and a merge sort for sorting by inventory number.  You may use any type of sorting algorithm for the other sort functions including bubble or merge.  You must write a single swap function that is used by all of the sorts to swap struct elements in the array of inventory item structs.

 

 

 

 

 

Implementation requirements:

The program should use the following data structures:

Struct data type to store all data elements for one inventory item

One array of 10 structs to hold data for inventory items

 

The program should use the following control structures:

Function calls to perform tasks

Loops as needed

Selection statements as needed to do comparisons of values

 

The program should NOT use:

        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 as many as specified. 

 

This program must be written using two files.  The first file will contain all the declarations needed for the program and an #include statement for the main file.  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 and an #include statement for the declarations file.  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 definitions

 

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

 

The constants file should include both 10 (array size) and 0.0 (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:

 

Step 0: Declare the data type for the inventory item struct

Step 1: Declare array of structs for inventory items and Print a welcome screen for the user that introduces the system

Step 2: Read the data in from a file for up to 10 inventory items

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

Step 4: Calculate the retail price

Step 5: Calculate the depreciated profit percentage

Step 6: Calculate the expected selling price

Step 7: Give user a menu of choices to print and sort array or end the program

 

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 file of values that will be given.  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.

 

A file will be given with the first sample data set for the inventory items.

 

 

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:      (83%)

Documentation, Style, Modularity (7 points)

Program header and function headers for all functions; Code documentation        

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

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!)  Follows the function structure requirements given

File requirements (3 points)

Constants file - #include all required system files

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

Constants file -Declare all struct data types (do NOT define struct variables here)

Constants file -Declare all function prototypes other than main

Main file - does NOT do any of the tasks assigned to Constants file.

Functionality  (73  points total) (functions perform specific tasks as defined)

Correct definitions of inventory item structs  (12 points total)

        Data for input number, name, quantity, cost, date received, size category, profit percentage goal , and shelf time (7 points)

        Data for calculation retail price, depreciated profit percentage, and selling price (3 points)

        Enumerated type member (2)

Correct definition of enumerated type (4 points)

Correct manipulation of the arrays of structs (8 points)

                Correct use of file input (8 points)

Correct implementation of recursive calculation of depreciated profit percentage values (10 points)

Correct calculation of retail price and selling price (6 points)

Proper implementation of input error checking for quantities and costs (3 points)

Bubble sort for names is correctly implemented (5 pts)

Merge sort for numbers is correctly implemented (7 pts)

All other sorts correctly implemented (10 pts)

Output:    (17%)

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

User clearly understands program options throughout program execution (3 points)

Output is accurate (5)

Sorted output is correctly printed (3 points)

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

 

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 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.

Submission requirements   (deductions if missing)

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)

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

                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

 

 

HINT:  After reading the assignment and before writing any code, most programmers 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!