Lab #3 Assignment

CSE 1320-003

Fall 2013

 

Design Document Due Date:              Thursday, Oct. 31, 2013 at 11:59am

Lab Due Date:                                     Thursday, Nov. 7, 2013 at 11:59am

(see instructions on website for how to turn this in - Ňlab submission infoÓ)

Grade value:    10% out of 100% for all grades (assuming there are 5 labs this semester)

                       

Objective:  The goal for this lab is to provide an opportunity for practice of C program development and the C programming topics covered in Chapters 1–4 and parts of later chapters in Foster and Foster as covered in class.  It is assumed that the student is familiar with the programming concepts but not the C syntax.   This lab will introduce students to Dr. TŐs approach to lab assignments and to reinforce and refresh previously learned material about C and programming.

 

Every lab assignment allows students to practice program development, debugging, and testing.   All of these skills are crucial to success in Dr. TŐs class.  The format of this assignment is similar to the assignments that will be required for the rest of the semester so a student who is unsure of their skills can use this assignment to refresh them and to ask the instructor or TA about any concepts they are unsure of.

 

Topics: 

            Algorithms

            Multi-dimensional Arrays

            Strings functions

            Control structures

Input and output,

Passing parameters

Sorting

            Searching

            Program design

            Modular programming structure

            Error checking

            Programming style

            Compiling code,

Executing code,

Debugging and testing.

 

Plan:  Dr. T gives an overall problem that students work on all semester.  Each lab assignment implements specific concepts.  Succeeding assignments will modify and extend previous assignments. 

 

 

 

Overview:  For the rest of the semester you will be trying to determine what it would cost to start and then run a small garden store.  You will be developing an estimate based on a number of factors including the size of the store, the kind of stock, the start up costs, staff costs, and other factors.  (If you really own a business, you will quickly realize that this is not going to be a very realistic example, even later in the semester, but the idea is for you to practice your programming skills.  ;)   You will also make various other calculations as required.  You are going to get information from the user and store that information in a certain way.  WeŐll call this the data-entry phase of the program.  Once all the input data is entered, your program will allow another user to perform various tasks on the data by choosing tasks from a menu.  WeŐll call this the menu-driven phase of the program.  The user can continue to choose tasks from the menu as long as desired and one of the menu choices must be to end the program.  The program ends correctly when the user chooses that option.

 

You are also required to design your program in advance before you begin writing code.  You will document your design and turn in the design document at least a week before the lab assignment is due.  The goal of the design document is to assist you in developing the actual program.

 

This assignment has an overview section, a large data description section, a task description section, an implementation requirements section, a grading scale, and a deductions section.  If there is additional info needed it will be in a miscellaneous section at the end of this lab assignment.  Read ALL of the assignment before you start trying to develop the program.   

 

Be sure to check the DEDUCTIONS section at the end of this assignment to avoid penalties.  You may NOT use global variables, the exit command, goto, break (except in a switch), continue, or linked lists. You should do input and output using printf, scanf and getline (you are allowed to use getchar and putchar if desired.)

 

Assumptions for the lab #3:

 

1)  Strings will have a maximum length of 100 chars and they may have blanks.  Use constants to define the max value.

2)  If your instructions tell the user to enter numbers, then you do not have to check that the input might be a letter instead of a number unless specifically instructed to do so for some particular input.  If the user does not follow your instructions to enter a number when required then any data type input error is the USERŐs fault and you will not be penalized in this lab.

3)  You will have a maximum number of 25 rooms (MAXROOMS) and 50 employees (also called staff) (MAXSTAFF) for Lab #3.  These values will change in later labs.

4)  For date checking in Lab #3, you may make the simplifying assumption that February has 30 days.  All other months should be used with their actual count of days.

 

Problem:  The data in your database will be the garden store information needed to create the estimate such as rental space rates, stock information, and so on.  As part of this assignment you will have to find real data about some items to use as test data for your program. When the user runs your program, they must first enter data.  The data they entering will be the garden store information that you have researched to use as your test data.  After (or while) getting all the input data from the user (and storing it in arrays) you must also check that all the input they give is valid, i.e. there will not be a negative number of work hours.  This will complete the data-entry phase of the program. Then you will allow the user to begin the menu-driven part of the program and do the following tasks:

 

1)   Using the data in the arrays,

      A)  Print all or part of the data in a table

      B)  Calculate

            i.    Total estimated first year costs

            ii.   Total estimated square footage of garden store

            iii.  Staff costs only with given values

           iv.  Stock with greatest total amount in the store

           v.   Stock which will give the greatest profit if all sold

      C)  List

            i.    All the types of stock that will be sold with their average prices and starting amounts

            ii.   Types of stock with average prices less than a given value

            iii.  Types of stock with amounts greater than some given value

      D) Determine scenarios:

            i.    Calculate total yearly expected profit on 100% sales (Scenario 1)

            ii.   Calculate total yearly expected profit on 80% sales (Scenario 2)

            iii.  Calculate total yearly expected profit using a formula (Scenario 3)

      E)  Search for

           i.    Largest garden section in the store

           ii    Largest concentration of stock for sale in any one section

           iii.  Given net profit by binary search

      F)  Sort

           i.    Garden section names

           ii.   Total gross and net profit for each section

           iii.  Garden section sizes

           iv.  Section numbers

2) End the program

 

Data Description:  For lab #3, you will be storing the input data in some single arrays, some multi-dimensional arrays, and some arrays of structs. 

 

The data elements and descriptions are given below.  Following this first list, the data elements are described by type.

 

a) Start up costs – a money amount composed of the cost of a business license, the total cost of the utility connection fees (both water and power), the cost of a business permit, and an amount to have as a start up fund.  This set of data will also include an opening date for the garden store.

 

b) Type and amount of flowers and plants to stock represented by a single LETTER with A meaning annuals, H meaning high water use perennials, X meaning xeriscape perennials, N meaning native shrub, T meaning native tree, and O meaning other plant.  The user shall give an integer (the count of types of stock available), then letters (representing each kind of available stock), then more integers representing amounts).  This information will be formatted as an integer of either 1, 2, 3, 4, 5, or 6 followed by that many letters of either A,H, X, N, T, or O then followed by that many numbers indicating amounts of each type of stock.  Your garden store must offer at least annuals and native shrubs at a minimum.  The number represents how many types of stock types are available and the letter code(s) indicate which kinds of stock they are. 

Ex: 4 X A N O 65 500 150 325

 

c) Stock type average cost per item – same number of values as previous info giving a list of cost of the average item of each kind of stock.  Ex: for example above, 35.50 2.00 22.00 7.25

 

d) Desired profit amount (markup) per stock type – same number of values as previous info giving a list of values that indicates a percentage of markup to be used on that stock type.  (Markup can be 0.)

 

e) Staff costs – there will be four types of staff members - manager, owner, horticulturist, and sales staff.  For each of these four staff types you must get the hours per month as fractional values, number of each type of staff (no partial people), and maximum and minimum hourly wage for each staff type as a money amount.  There will also be a maximum hourly wage amount that no employee will exceed and you will need to test input values against this maximum.  A total yearly staff cost will be calculated from this info.

 

f) Type of rooms in the store including outdoor garden section "rooms".  The garden store will have some indoor/interior rooms for plants as well as some outdoor garden section "rooms" for plants.  The types of rooms are Indoor sales room, Loading area, outdoor Sales room, Bathroom, Office.  The input is an integer of either 1, 2, 3, 4, or 5 followed by that many letters of either I, L, S, B, and/or O. Must have indoor sales room (I), loading area (L), and bathroom (B) at a minimum.  The number represents how many types of rooms are in the store and the letter code(s) indicate which kind of room they are.  Ex: 4 S I B L

 

g) Amount of rooms of each type – same number of values as previous info giving a list of numbers representing how many rooms there are of each type. Must have a minimum of two indoor sales rooms, one loading area, and one bathroom.  Ex: for example above, 3 1 2 3

 

h) Size of each room – this is a set of pairs of values, one pair for each room counted in the amount of rooms above.  The values represent length and width of the room in fractional feet (ex: 3.5).  For the example just above there are 3+1+2+3=9 rooms, so there will be 18 values used to give the sizes. 

 

i) Square foot rental rates per year – two floating point money amounts that are the amounts that one square foot of indoor space and one square foot of outdoor space rents for.  Ex: 120.00 75.50 would represent $120.00 per indoor square foot per year and $75.50 per outdoor square foot per year.

 

j) Total yearly expense – This money value will be calculated by the program

 

k) Total yearly profit - This money value will be calculated by the program

 

l) First year profit or loss - This money value will be calculated by the program

 

m)  Garden section number – This will be assigned by the program but stored as a value in the garden section array to allow for sorting and re-sorting

 

o) Sales garden section name – a phrase less than 100 characters long that gives a name for each of the garden section rooms.  In lab #3 we are using strings for the name, i.e. "English Cottage Garden Section" is one phrase and can be used as a garden section room name.  After you read in this name string, you will need to append (concatenate) the garden section number to the end of the string.  See sample code on website for assistance.

 

p)  Square footage of each garden section – This amount will be calculated by the program and stored in the garden section array

 

r)  Profits per garden section – For each garden section room in the store that has stock, this array will hold the gross profit and net profit for the garden section room.  These values are calculated by the program based on the data input for each garden section room, the stock types and amounts in each garden section room, the AVGPRICE for each stock item (which is the item's cost to the store), and the MARKUP amount for each stock item.

 

The specific detailed format for each piece of data is listed below. 

 

General data storage requirements for lab #3: 

Overall you are required to use some multi-dimensional arrays (data content and sizes will be specified for each one) and at least two one-dimensional arrays of structs.  You may also use additional one-dimensional and multi-dimensional arrays to hold the remaining data as needed.   [OK, this isn't as confusing as it seems.  J]

 

For Lab #3 we are changing the data representation of our program.  We will be creating structs to contain data for different components in our program and then we will store these structs inside arrays.

 

As an example, let's look at the room data for a garden store.  You will have store information about what kind of room it is (room type), how many rooms there are of this type, and then for each room of that type you need its length and width.  We will use a one-dimensional array of structs to store data about the rooms.  Each struct will be one room.  Each member of the struct will represent different data about that room in that struct.  Since we will also be naming the garden sections in the rooms, then there will also be a string array, the name of each room/ section, in each struct.  

 

You will have a maximum number of 25 rooms (MAXROOMS) and 50 employees (also called staff) (MAXSTAFF) for Lab #3. 

 

This information then dictates the sizes of the various types of arrays you will need.  Your previous arrays have all held a single type of data.  The arrays for this lab will also hold a single type of data and for some arrays that data type will be a struct type that we have created.  In cases where you have multiple arrays referring to the same data, then the same row always refers to the data in the corresponding array.  For the multi-dimensional float and integer arrays, the number of columns is determined by how many pieces of data have to be stored.  The number of rows is the same as the maximum number of stock types or rooms or employees that can be stored. These arrays are specified in detail below.  We will also modify the data storage for some of the data we already have.

 

The first array will hold information about the stock, stockinfo.  This will be a floating point array of 6 rows and 3 columns.  Each row will represent one of the 6 types of stock that might be in the store.  You should declare the following constants to use with this array: ANNUAL = 0, WATER_PERRENIAL = 1, XERIC_PERRENIAL = 2, NATIVE_SHRUB = 3, NATIVE_TREE = 4, OTHER = 5.  The three columns in the array will represent AMOUNT = 0, AVGPRICE = 1, and MARKUP = 2.  The AMOUNT column will be used to represent whether a particular kind of stock is available at that store or not by holding the amount of that stock in the store.  So if the store sells xeric perennials, then stockinfo[XERIC_PERRENIAL][AMOUNT] will be store the amount 65 which represents the amount of xeriscape perennials (from the earlier example).  If native trees are not sold at this store, then stockinfo[NATIVE_TREE][AVAILABLE] will be set to 0.0 to represent 0 items in stock.  If the AMOUNT column is greater than 0 (or true), then values should be stored in the AVGPRICE and MARKUP columns.  If the AMOUNT column is 0 (or false), the AVGPRICE and MARKUP columns should have the value 0.0.  {HINT: If you initialize your array to 0, then you will have the correct values in the columns you donŐt need.}  For Lab #3 you may continue to use the stock arrays as you did in lab #2 or you may move the stock data into a struct and have one array of stock structs.

 

The second array will hold amount information about the numbers of types of staff members.  The array will be a one-dimensional integer arrays.  Declare constants to use for the indices, ex. MANAGER = 0, OWNER = 1, etc. for the four staff types.  Inside the array, store the amount (number of) items associated with that type.  These amounts are requested from the user.  For example, if the user says there are two managers then the value for stafftype[MANAGER] should be set to 2.  Be sure to declare your constants correctly for the array you are using.  Error check the values that are stored in the array so that the user does not exceed the maximum number of staff members.

 

The third array will hold amount information about the numbers of each room type.  The array will be a one-dimensional integer array.  Declare constants to use for the indices, ex. INDOOR = 0, LOADING = 1, etc. for the five room types.  Inside the arrays, store the amount (number of) items associated with that type.  These amounts are requested from the user.  For example, if the user says there are three outdoor sales rooms then the value for roomtype[OUTDOOR] should be set to 3.  Be sure to declare your constants correctly for the array you are using.  Error check the values that are stored in the array so that the user does not exceed the maximum number of rooms.

 

The next array will be a floating point array of staff data called staffdata.  This array has four rows and four columns.  The rows will be indexed by the constants for the staff types, MANAGER, etc., while the columns will be indexed by AVAILABLE (as used before), MINHRWAGES = 1, MOHOURS=2, MAXHRWAGES = 3.  This array will hold the minimum and maximum hourly wages for each of the four job types and the average number of hours worked a month for each job type.  This will be used with the data in the amount array to determine the total yearly staff cost.

 

The next array will be an array of room structs that will contain all the data that was previously in the roomsize array and the sectionname array.  It will also include new data for each room including the room area in square footage, how much stock of each type is in each room, the gross profit from that room assuming 100% sales, the net profit from that room and a room number as a value also. 

 

So the room struct type you create needs to have a room type, a room number, a room/section name, a length and a width, an area (that is calculated from length and width), the amount of each type of stock (so this is 6 amounts) in the room, a gross profit value, and a net profit value.

 

á      The room type will use the constants already declared, like LOADING. 

 

á      The room number would be a copy of the original counter which will be the room number as counted from 0 to roomtype[index]-1.  You are storing this number so that you will be able to sort and then re-sort the array.

 

á      The string array inside the struct will have 100 columns.  Both indoor sales rooms and outdoor sales rooms can have names.  Make sure to declare all your constants (such as max string length) before you try to use.

 

á      The values for length and width stored in this struct should be measurements in fractional feet of the length and width of the current room.  Therefore if the 2nd office is 8Ő6Ó by 9Ő4Ó, then the width should be 8.5 and the length should be 9.33.   The area of the room should be calculated automatically be the program and stored in the area member of the struct for that room.

 

á      There will be 6 stock amounts to correspond to the six types of stock that could be in the room.

 

á      The gross profit is all the money paid for stock by customers, and the net profit is the gross profit minus the actual cost (the AVGPRICE) for each stock item.  All of the profit data comes from information the user enters in other places.  After the user has entered all the input data, your program must calculate these profits and costs and fill the structs in the array with data.   I would recommend writing a function to find stock types, amounts and costs for each room, calculate the profits, and store it all in this array.  The gross profit for a room is calculated as:

               stock1_amount * (stock1_avgprice * (1+stock1_markup)) + É

            + stock6_amount * (stock6_avgprice * (1+stock6_markup)) = gross_profit;

Then net profit is :

               stocktype1_amount * stocktype1_avgprice

+ stock2_amount * stock2_avgprice + É

+ stock6_amount * stock6_avgprice = actual_cost;

 

            gross_profit – actual_cost = net_profit

 

In addition to the arrays described above you may use more arrays if desired or you may add columns to the arrays already described in order to represent the remaining data.

 

In Lab #3 you will also define a struct type to use for storing the start up cost information and a struct type to hold date information.

 

Detailed descriptions of each data value.  The data values below must be stored as described.  You may also store additional values into these arrays if desired.  In the descriptions below number usually represents the current room number that is being used. 

 

It is NOT necessary to have the user enter the data in exactly the order listed.  You may get data from the user in whatever order makes sense.  However, you must implement the data input method described later in the document for "line of data method" and you may choose to also implement file input if desired.

 

Start up costs:

Declare a struct type that can contain all of the start up information including opening day.  Store all the start up information in a variable of this struct type.

 

Business license cost – floating point money amount.  Must be 0 or positive cost. This should be error checked and then stored as a floating variable in a struct.

 

Total cost of the utility connection fees - floating point money amount.  Must be 0 or positive cost. This should be error checked and then stored as a floating variable in a struct.

 

Cost of a business permit - floating point money amount.  Must be 0 or positive cost. This should be error checked and then stored as a floating variable in a struct.

 

Start up fund amount -  floating point money amount.  Must be 0 or positive cost. This should be error checked and then stored as a floating variable in a struct.

 

Opening day – three integers that give the target opening date for the store.  These values should be error checked and then stored in a date struct.

 

Stock data:

 

Number of types of stock – a single integer from 1 to 6 which indicates how many different kinds of stock there are in this store.

 

Stock type – a single character or a group of characters representing the kind of stock that will be sold.  The total number of these characters will be the same as number of types of stock.  Each character must match one of the valid stock type codes and the codes that are used must be entered in the same fixed order as the list of stock types.  For each valid code, a one (1) should initially be stored in the array stockinfo[type][AMOUNT] where type is the constant stock type value that matches the entered code.  Ex.  If user enters N as one of the characters, then 1 should be stored in stockinfo[NATIVE_SHRUB][AMOUNT].

 

Stock amount - an amount that is the number of items available of the current type.  This value is stored in the floating point multi-dimensional stockinfo array at the [type][AMOUNT] where type is the constant stock type value that matches the current type and where the value of AMOUNT was 1 from the previous step.

 

Stock type average cost per item - a floating point money amount that is the average cost for one item of the current type.  This value is stored in the floating point multi-dimensional stockinfo array at the [type][AVGPRICE] where type is the constant stock type value that matches the current type.

 

Desired profit amount (markup) per stock type - a floating point number between 0 and 3 inclusive.  This limits the profit to 300% of the cost, i.e. if the average cost of this stock item is $5.99 then the item can be priced not more $23.96 which pays the cost of the item and then returns 300% profit.  This value is stored in stockinfo array at the [type][MARKUP] where type is the constant stock type value that matches the current type.

 

Staff data:

 

Staff type and amount - a single character or a group of characters representing the kind of staff members that work at the store.  They must match one of the valid staff type codes.  For each valid code, the user should be asked for an amount of staff members of that type.  This value should be stored in the array for staff data at stafftype[type] where type is the constant staff type value that matches the entered code.  Ex.  If user enters M as one of the characters, then the user should be asked for how many managers there are and this value should be stored in the staff array at stafftype[MANAGER].

 

Minimum and maximum staff hourly wages - two floating point money amounts that are the maximum and minimum hourly wages paid to any staff member of the current type.  These values are stored in the floating point multi-dimensional staff array at staffdata[type][MINHRWAGES] and staffdata[type][MAXHRWAGES] where type is the constant staff type value that matches the current type.

 

Staff hours per month - a floating point amount that is the average number of hours that a staff member of the current type works in a month.  This value is stored in the floating point multi-dimensional staff array at the staffdata[type][MOHOURS] where type is the constant staff type value that matches the current type.

 

Staff maximum hourly wage - a floating point money amount that is the maximum hourly wage paid to any type of employee.  Note that the owner is not an employee. 

 

Room data:

 

Room type and amount - a single character or a group of characters representing the kind of rooms there are at the store.  They must match one of the valid room type codes.  For each valid code, the user should be asked for an amount of rooms of that type.  This value should be stored in the array for room data at roomtype[type] where type is the constant room type value that matches the entered code.  Ex.  If user enters L as one of the characters, then the user should be asked for how many loading areas there are and this value should be stored in the room array at roomtype[LOADING].  Ex.  4 S I B L 3 1 2 3

 

Square foot rental rates per year – two floating point values that will be used with the roomsize to work out the yearly rental cost for the indoor store space and the outdoor store space to determine the whole store rent cost.  Ex. 120.00 75.50

 

After getting the room types, amounts and indoor and outdoor rental rates, you will use one room struct for each room of data to be stored.  The room structs should be stored in a one dimensional array.  [You may store the structs in a two dimensional array if desired but make sure you know how to search your two dimensional array if you use it.]  A single struct will hold all the data for a single room.  If you have all your structs in a one dimensional array called rooms then you might use rooms[i].width to store the width and rooms[i].xeric_perennials to store the amount of xeric perennial flowers in the same room [i].

 

Room length and width – this is a pair of floating point values for each room in the store representing length and width of the room in fractional feet (ex: 3'6" = 3.5').   You must have the user enter feet and inches  and then convert this value to fractional feet.  Regardless of how the user enters the data, the data MUST be stored as a floating point number representing a fractional measurement.  This same process will be needed for each type of room that is in the store and for all the rooms of that type.  For example, if there are 2 baths, 3 indoor sales rooms and 1 loading area, then there are 6 different rooms to get length and width for.   Since the possible number of rooms is large (ROOMMAX is 25), this data entry could take a long time.  [HINT: start with a small number of rooms and then after testing it, increase the numbers for your final test runs to script.]  Once you have gotten the length and width for a room, you should calculate the area and also store that in the correct struct member.

 

Room stock content – this is an integer value giving the amount of a given stock type in a single room/section of the store.  This data is stored in the room struct.   For all the types of items sold in the garden store, some items of each of those types might be in any section or room.  Therefore for each room, you will need to ask the user how much stock of each type is in that particular room and store the answer.  Ex:  If the garden store sells ANNUALs and NATIVE_SHRUB, then each room might have some stock of that type in it. You would need to ask the user, room by room (just like for length and width), how many items of each type are in that room (of the types that are sold.)  The result is that if the 3rd indoor sales room has 125 native shrubs in it, then you will get and store 125 in the native_shrub member of the room struct that represents the current room such as rooms[k].native_shrubs = 125.

 

Room number – this is an integer counter value that is stored in the struct for the rooms of the current type.  When you are getting the data from the user, you will be asking them about the data for INDOOR room 3, for example.  In addition to getting the length, width, and stock data for the room, make sure you also store the number of the room in the array, in this case 3.  This will later allow you to sort the array by amount of ANNUAL stock, for example, and then be able to re-sort back to room number order.

 

Sales room namea string will less than 100 characters that gives a name for each indoor and outdoor sales room that has one.  The string will be read in with the getline command into a temporary string.  The length of the string should be checked using the strlen command.  If the string is less that 1000 chars in length then it should be copied to the name member of the current struct.   Ex:  The name of indoor sales room 5 which is the hardy shrub room might be the string "Hardy Shrub" and it would be stored in rooms[5].name which is the string array.  [HINT: make sure you know how to read a string in, check its length, and then copy it in order to make this work.]

 

Gross profit and net profit per room– Is calculated from other data that has been input.

 

Total yearly expense for the store – This money value will be calculated by the program as the business costs plus a year's rent plus the cost of all of the initial stock.

 

 

You are allowed to make assumptions about rooms with no stock (like BATHROOM or OFFICE) but make sure to write comments about this assumption in your code and to fill in the struct member or array element appropriately, with 0's, for those rooms.  If some of your rooms do not have any stock, then you do not need to ask the user about stock in those room types but you do need to make sure there are 0's in those values in the array.  You may also choose to ask about the size and the stock for one room all at the same time.  This means that you could ask the user about indoor sales room 3 and get length, width, amount of annuals, amount of xeric perennials, and other stock, then ask for the room name.  You would already know and have stored the information that the room was type INDOOR and had room number 3 and you would calculate the area, gross profit, and net profit to store those values.  After getting all the data for INDOOR sales room 3, then you could go on to ask about sales room 4.

 

Data entry phase

 

Input Implementation:  For Lab #3 the user must enter at least 3 rooms (see earlier requirements) and no more than 25 rooms.  The user must enter at least 3 staff members and no more than 50.  The user must have at least two kinds of products (stock) in their garden store as previously defined.  As this data is entered by the user, the program should check to make sure these counts are appropriate. [Note for development: start with smaller numbers then increase to the required minimum when program is working well.] If the userŐs number exceeds the max, the program should inform the user of the maximum number of inputs allowed and have them reenter the count.

 

Once you get to input for the rooms, your program must loop for each room to read and store input for the length and width.  You may collect all the room information in this same loop or you may loop through the rooms more times in order to get stock amounts and other data.

 

Make sure your program begins with a brief intro to the user so that they know what the program is for.

 

For Lab #3, you must implement the following method of input.  The method will allow the user to input all needed pieces of data about one element on one line.  The form of the input is described below.  If desired, your program may allow the user to enter data from a file.  The format of the data in the file must be the same format as the data when entered on one line from the keyboard.  For Lab #3, if you choose to do file input, you must name your input file "CFall13Lab3input.txt".

 

If your program implements both line of data input method and file input method then the program must ask the user how they want to input the data.  Once the user has chosen the method of input or if only line of data input method is implemented, then all the input will be done that way for the current run of the program. 

 

 

Line of data input method:

 

[Data definitions were given in Lab #2 in the Individual data input method description.  Continue to use these data definitions unless new definitions are specifically given in this assignment.]

 

The line of data input method is to have the necessary data entered by the user on just a few lines with multiple pieces of information per line.  The input would be all the pieces of data listed above.  You must tell the user exactly how to enter the line of data.  For Lab #3, use the line of data method with inputs in exactly the order specified below.

 

The data for the garden store will be entered by the user as values on two (or more) lines as follows {there must be one space only between the values}.  Here's an example:

 

prompt>500.00 250.00 69.99 50.00 15000.00 9 1 2014 4 X A N O 65 500 150 325 35.50 2.00 22.00 7.25 .75 .90 1.00 .90 3 M H S 2 1 5 17.50 10.00 25.00 15.00 14.10 7.95 120 48.8 76.4 27.50 4 S I B L 3 3 2 3 120.00 75.50

0 0 20 25 40.0 60.0 Hardy_Shrubs

0 0 100 10 20.0 20.0 Native_Shrubs

0 0 0 65 20.0 20.0 Hardy_Trees

0 400 0 75 55.5 20.0 Annuals

65 0 0 10 10.0 19.3 Perennials

0 0 0 140 45.5 35.3 Flowers

10.5 10.0

9.5 10.0

15.0 10.0

10.0 5.0

20.0 10.0

 

which represents a business license cost of $500.00, a power utility connection cost of $250, a water utility connection fee of $69.99, a business permit cost of $50, and a start up fund of $15,000.  The opening day will be 9-1-2014 (September 1, 2014).

 

 The store will have four types of stock – xeric perennials, annuals, native shrubs and other with the amounts – 65 xeric perennials, 500 annuals, 150 native shrubs and 325 other plants.  The average costs of these stock types is $35.50 for xeric perennials, $2.00 for annuals, $22.00 for native shrubs and $7.25 for other plants.  The markup is 75% for xeric perennials, 90% for annuals, 100% for native shrubs, and 90% for other plants.  There are three kinds of staff members – managers, horticulturists and sales staff.  There are two managers, 1 horticulturist, and 5 sales staff.  Managers make $17.50 max per hour, $10.00 min per hour, and average 120 hours per month.  The horticulturist makes $25.00 max and $15.00 min per hour and averages 48.8 hours per month. Sales staff make $14.10 max and $7.95 min per hour and average 76.4 hours per month.  The maximum hourly wage for any employee is $27.50.  There are 4 types of rooms in the store and the following amounts – outdoor sales (3), indoor sales (3), bathrooms (2), and loading areas (3).  The rental rate per indoor square foot per year is $120.00.  The rental rate per outdoor square foot per year is $75.50. [For this assignment, I assume that bathrooms and loading areas do not contain stock items.] All the preceding data is typed with single spaces between them all on one line.  (As long as you only type in single spaces, it will not matter if the line wraps on the screen when you look at it like above.  It will still be one line to C.)

 

The remaining data is one line for each room.  The order of the lines matches the order of the rooms given so 3 outdoor sales rooms, 3 indoor sales room, 2 bathrooms, and 3 loading areas is 11 lines.  For sales rooms there are stock amounts in the same order as the stock types were input, then length, width, and  room name.  In the example above, the first outdoor sales room has 0 xeric perennials, 0 annuals, 20 native shrubs and 25 other plants and is 40' by 60',  and is named "Hardy_Shrubs".  The second outdoor sales room has 0 xeric perennials, 0 annuals, 100 native shrubs and 10 other plants, is 20' x 20' and is called "Native_Shrubs."  Likewise for the third outdoor sales room called "Hardy_Trees".  The stock amounts and length and widths are given for the fourth and fifth rooms - indoor sales rooms, "Annuals" and "Perennials". The sixth room is the 45.5' x 35.3' indoor sales room names "Flowers".  The 7th room is the first bathroom of size 10.5' by 10' and the second bath is 9.5' x 10'.  Three loading areas are 15' x 10', 10' x 5' and 20' x 10' in size.

 

To use the line input data, your program will read the first number and store it in the correct location for the business license data, then read and store the next number into its corresponding location, then read  the third number, and so on.  Your program should try read all the numbers, chars, and the strings that are on a single line within a single input command as much as possible, i.e. do not have a scanf statement for every single value.  Your program should read in one line for the first set of garden store data and then as many lines of input for rooms specified by the counts given up to the maximum of twenty-five more lines of input. 

 

If you choose to use file input for Lab #3, you must get the needed information outside of class.  You may ask Dr. T during office hours, work with the TA, or look at online help.  Make sure your approach will work with gcc on omega.

 

Input verification:

When the user has entered all the store and room data, print out all the input data in an easily readable form, ex. use a table with headings, or columns with headings or rows with labels.  It is strongly suggested that this printing be written as a separate function that can be called at any time in the program to print the current contents of the arrays and variables.  It is also suggested that a small function be written which will print the name of a sales room given the type of room (INDOOR or OUTDOOR) and room number (Ex. outdoor sales room 1, 2, or 3) as input.  The function could have a switch or a bunch of if statements in it.  You may wish to write small output functions for printing staff data, stock data, start up data and room data if desired.  These could be combined to print the data required for input verification.

 

Task Description: (Menu-driven phase)

 

Once all the data is read into the arrays your program should give the user a main menu with the following choices.   This menu is just a listing of the choices NOT a new window or any other sort of graphics based menu.  The user should select a choice by entering a letter of number at a prompt at the bottom of the menu.  The menu choices are: (use any number scheme you wish)

 

1)   Using the input and calculated data,

A)  Print all the data about the store including total expenses, gross profits, and net profits for a year

B)  Print all the data about business costs including opening day

C)  Print all data for stock

D)  Print all data for staff

E)  Print all data for rooms

 

F)  Calculate estimated total square footage of garden store and indicate how much of total square footage is outdoor space as a percentage of total space.

G)  Calculate staff costs only for one year using the given input values.

H)  Calculate total estimated first year costs

 

 Ha)  Calculate which type of stock has greatest total amount in the store

 Hb)  Calculate which type of stock will give the greatest profit if all sold

 

I)   List all types of stock with average prices less than a given value

J)   List all rooms with square footage larger than a given amount

 

K)  Determine profit scenario 1 (see description below)

L)  Determine profit scenario 2 (see description below)

M) Determine profit scenario 3 (see description below)

 

N)   Search for largest garden section in the store by area using linear search

O)   Search for largest concentration of stock for sale in any one section

P)    Search for given net profit by binary search

 

Q)   Sort by the garden section names

R)   Sort by total gross or net profit for each section

S)    Sort the garden rooms/sections by sizes of area

T)   Sort by garden room type and room/section numbers (Extra credit up to 5 points)

 

U)  End the program

 

The print functions  A – E let the user select to print one set of store data or all the data.  These functions should call the function(s) that were discussed in the input verification section above.

 

The calculate-square-footage function F has the following steps:

            For every type of room,

loop through each individual room's data to

get length and width

multiply L x W to get area of that room

sum the areas of all the rooms of this type

                        sum the areas for each type of indoor room (indoor sales, bathrooms, office) and

                        sum the areas for each type of outdoor space (outdoor sales, loading areas)

            Total store square footage is sum of indoor space and outdoor space.  Print this.

            Also calculate outdoor space as a percentage of total space and print this.

 

The calculate-staff-costs function G has the following steps:

            For each type of staff member in the store

                        Multiply number of staff

times hours per month

times average hourly wage (take average of max and min to get average)

       to get monthly staff cost

                        Sum the monthly staff cost for each type of staff to get total monthly staff cost

            Multiply this value times months of the year to get yearly staff cost

 

The calculate-first-year-costs function H has the following steps:

            Sum all the startup costs

            Find the yearly staff cost (this should use function G)

            Calculate the total stock cost (we'll assume this is the first month's stock) as:

                        For each type of stock in the store

                                    Multiply amount of items of stock type

                                    Times average cost for that kind of stock item

                        Sum these stock costs for total monthly stock cost

                        Multiply this value times months of the year to get yearly stock cost

            Calculate store rental cost as:

                        Total store square footage times outdoor percentage

                        Times outdoor square foot rental rate per year and

                        Total store square footage times indoor percentage

                        Times indoor square foot rental rate per year

Sum the indoor costs and outdoor costs for store rental cost

Sum the costs for startup, yearly staff, total stock, and store rental to get the first year cost

 

The calculate-greatest-stock-amount function Ha has the following steps:

            Sum up the amounts of the first stock type in all the rooms of the garden store

            Save this amount

            For all remaining stock types do the same calculation

            For all the total amounts,

                        Find the largest amount

                        Determine which type of stock this is

Indicate that this stock has the greatest total amount and print out the stock type and amount

 

The calculate-greatest-stock-profit function Hb has the following steps:

Choose gross profit or net profit to calculate:

            Use the same calculations as in function Ha to calculate total amounts of each stock type

                        For each type of stock in the store

                                    Multiply amount of total items of stock type

                                    Times average cost for that kind of stock item

                                    Times (1 plus the markup amount for that kind of stock item)

                                    To get gross profit for that type of stock

                        For all the total gross profit amounts,

                        If user is calculating gross profit:

                                    Find the largest amount

                                    Determine which type of stock this is

Indicate that this stock has the greatest total gross profit

and print out the stock type and amount

                        Else if user is calculating net profit:

                                    Using each gross profit amount

                                                Subtract actual cost (stock amount * average price) from gross profit

                                                To get net profit

                                    Find the largest net profit amount

                                    Determine which type of stock this is

Indicate that this stock has the greatest total net profit

and print out the stock type and amount

 

The list-all-stock-less-than-price function I should ask the user to enter an average price for any item of stock then go through every type of stock and print the complete information for all types that have an average price equal to or less than the userŐs entered price.

 

The list-all-rooms-greater function J should ask the user to enter the square footage of a room then go through every room and print the complete information for all rooms that have an square footage equal to or greater than the userŐs entered value.

 

The profit-scenario-1 function K has the following assumptions and steps:

Assumptions:

Given the monthly amounts of stock, assume that 100% of stock is sold every month.

Steps – Calculate the profit for one year with the above assumption (scenario 1)

            Calculate total stock sold of each type

            Use average price of each stock type

                        Times markup percentage to determine the amount of profit for the item type

            Calculate total monthly profit for each stock type using the above

assumption for how much of stock is sold

            Multiply this value times months of the year to get yearly profit for scenario 1

 

The profit-scenario-2 function L has the following assumptions and steps:

Assumptions:

Given the monthly amounts of stock, assume that 80% of stock is sold every month.

Steps – Calculate the profit for one year with the above assumption (scenario 2)

            Follow the same steps as for scenario 1

 

The profit-scenario-3 function M has the following assumptions and steps:

Assumptions:

Given the monthly amounts of stock, assume the following is sold every month:

            Lowest price stock type sells 100%

            Highest price stock sells 70%

            All other types of stock sell 85%

Steps – Calculate the profit for one year with the above assumption (scenario 3)

            Find the highest and lowest average prices for types of stock

Follow the same steps as for scenario 1

 

The largest-garden-section-room search function N has the following steps:

      Use linear search to search the area amounts of all rooms in the garden store to find the largest

      Print the information for the largest room including room type, number, name, length and width

 

The largest-stock-in-one-room search function O has the following steps:

      Use any search method discussed in class to

            search all the stock amounts in each room to find the largest

            Print the information for the largest stock concentration

                  including stock type and amount and room info

 

The search-for-given-net-profit search function P has the following steps:

      Use binary search method as discussed in class to

            search all the net profit amounts in each room to find a value equal to a given input value.

            If an exact match is found,

                  Print the information for the stock type and net profit

            If no exact match is found,

                  Indicate that the given value was not found.

 

The sort-by-name function Q has the following steps:

      Use any sort function discussed in class to

            Sort the section / rooms by name alphabetically

            For rooms with no name, put them at the end of the list in any order

      Print the sorted list

 

The sort-by-profit function R has the following steps:

Choose gross profit or net profit to sort on:

      For each room, calculate the gross or net profit for all types of stock

      Sum the profit for each stock type in the room and

      Save the profit value for the room

      Use any sort function discussed in class to

            Sort the section / rooms by profit amount from largest to smallest

            For rooms with no profit, put them at the end of the list in any order

      Print the sorted list

 

The sort-by-area function S has the following steps:

      Use any sort function discussed in class to

            Sort the section / rooms by area from largest to smallest

      Print the sorted list

 

The sort-by-type-and-number function T has the following steps:

      Use any sort function discussed in class to

            Sort the section / rooms by type first

                  Then within each room type,

                  Sort the rooms of that type by number

      Print the sorted list    (Extra credit up to 5 points)

 

When the user chooses "End the program" from the main menu, print a concluding message and then gracefully end the program.

 

 

***************************

 

 

You should design your program in advance before you begin writing code. In this lab and all other labs you will document your design and turn in the design document at least a week before the lab assignment is due.  The goal of the design document is to assist you in developing the actual program.

 

 Read ALL of the assignment before you start trying to develop the program.   

 

Be sure to check the DEDUCTIONS section at the end of this assignment to avoid penalties.  You may NOT use global variables, the exit command, goto, break (except in a switch), continue, variable strings (except as described), passing by reference (except arrays), pointers, or linked lists.

 

Develop your program in small steps.  Test and debug as you go.

 

 

Implementation Requirements:

 

For Lab #3 WRITE A DESIGN DOCUMENT FIRST.  The design must include

 

      a) all the functions you expect to write,

 

      b) brief (one line) descriptions of each function, and

 

      c) some indication of which function calls what other functions.

 

The design document may be written as lines of text or as diagrams (such as a diagram that start with the main function at the top and all others below it, a tree, UML, etc.) or as some combination of those, but it must include the information listed for a), b), and c) above.  Each function should accomplish one main purpose and each function at a lower level should have a more specific purpose than the function that calls it.  Be sure to include all the functions that are described in this lab assignment.  This design documentation will normally be turned in for the lab and a design will be required to be turned in for all labs after Lab 1.  See the website or this assignment for the DESIGN DOCUMENT due date.  It is usually ONE WEEK PRIOR to the lab due date.

 

A Lab #3 Design Document must be turned in in order for your Lab #3 assignment to be graded.

 

 

The program should use the following data structures:

            User defined struct types

            Multi-dimensional arrays, single-dimensional arrays, arrays of struct

            Global CONSTANTS for specific and/or maximum values given in this assignment. 

            Constants can be done with #define or with the const declaration.  Examples:

 

                        #define EVENTMAX 10

                        const int EVENTMAX = 10;

 

The program should use the following control structures:

            Function calls to perform tasks

            A selection structure to choose input style

            A while or for loop to read the input data

            If, if-else, nested ifs, or switches to error check and implement the menu options

 

The program should NOT use:

            global variables

goto

variable strings (except as described)

            exit

            break (except in a switch)

            continue

            pointers

passing by reference (except arrays)

linked lists

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

 

Programming practices:

Comment your code!  Use headers as described below, use line comments and use block comments.  Line and block comments should explain the meaning of the code.  As an example compare the following examples of code with comments:

 

Example 1:

/* Find A by multiplying L times W */

A = L * W;      // A is the product

 

Example 2:

/* Find the area of the rectangle by multiplying length times width of the sides */

A = L * W;  // A is area, L is length of one side, W is length of perpendicular side attached to L

 

While Example 1 has comments, the comments do not tell us anything extra about the code.  The code itself tell us that A is the product of L*W.  In Example 2, the comments are meaningful and explain the goal of the code and the meaning of the variables.  Make your comments like Example 2 not Example 1.

 

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.  This header should include at least the function name, the purpose of the function (which can be the one line brief description of this function from the design document), and its inputs and outputs.

 

The program should be implemented as a set of functions with a main routine and at least one function for menu operations, one for getting input (line input), one for printing, and one for each of the functions listed for the user choices.  This is the required minimum number of functions.   You may use many more functions than this but you must use at least this many. The purpose of functions is to divide the problem into small tasks, each one assigned to its own function and then to call the functions from main() or from another function when appropriate. Do not code the entire program in main!

 

The program should generally 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 values

            Print the appropriate outputs

            Let the user make additional choices until the user indicates that they are finished.

 

Output requirements:

 

The program must be run and the output recorded in a script file from OMEGA using the gcc compiler.

 

No Exceptions! If you do not know how to create a script file, it is your responsibility to ask the TA, look for help on the class website, or OIT how to use this function.

 

You must come up with information to use as test data for 3 kinds of stock, 2 kinds of staff, and 3 rooms as a minimum. See the Miscellaneous section below for other useful info.

 

 

Testing:

This program must be run with two different sets of test data for the input data.  This is what gets recorded in the script file.

 

You must create two different data sets and run your program with both of them.  I will give you a small amount of sample data at the end of this lab for you to use as a model.  You may run your program two times within a single execution or you may execute the program two different times so that you have a total of two different data sets. The sample data sets that you create must meet the guidelines given in the problem definition.  Your test runs should demonstrate all the choices that are available in your program.

 

NOTE ABOUT ERRORS:

 

Programs turned in for credit MUST compile and run WITHOUT any compilation errors or runtime errors using the gcc compiler on omega.  No other compiler may be used for the compilation for credit.  No other operating system may be used for the compilation and/or execution for credit.

 

Compilation errors occur while the program is being developed and they prevent the program from compiling correctly. Programs compile correctly when running

 

>gcc myprogram.c

 

gives no error or warning messages.

 

Programs may be turned in for credit when they are partially complete but all completed functions must run without any errors. A program completes without runtime errors if it ends only when the user selects for the program to end and it correctly prints the exit message. Partially complete programs that accept input and that run correctly for each implemented menu choice will receive partial credit.

 

Any other type of ending is a runtime error or a "crash". A program has a runtime error if it compiles and runs but then crashes in any situation, i.e. if there is any set of choices the user can make that will make the program crash. It is your responsibility to test all possible choices in your program to make sure that none of them cause a runtime error. The goal of creating input test data and running your program with it should be to test all of the various choices in your program to make sure all of them terminate correctly.

 

Labs which have errors in them and do not terminate normally will receive an overall grade of 0 (zero)

 

 

Grading Scale:

Code:   (62%)

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

            Comments (line comments and block comments)      (4 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!)  (4 points)

            Style (indentation, consistency, meaningful identifiers, lateral separation of

code from line comments, etc.)  (4 points)

            Correct manipulation of the struct type (6 pts)

            Correct manipulation of the array of structs (6 pts)

            Correct linear search algorithms using array of structs (3 pts)

            Correct binary search algorithms using array of structs (4 pts)

Correct bubble sort algorithms using array of structs (4 pts)

Correct sort algorithms (other than bubble sort) using array of structs (3 pts)

Correct gross profit calculation (4 pts)

Correct net profit calculation (4 pts)

            Correct function structure as required (4 points)

            Correct implementation of other algorithms as given (4 points)

            Proper implementation of line of data input and input error checking (4 points)

Output:             (38%)

            User clearly understands what is being requested for input (5 points)

            Find-all tasks perform correctly (4 points)

            Calculate and scenario tasks perform correctly (5 points)

            Search tasks perform correctly (5 points)

            Sort tasks perform correctly (5 points)

            Input verification shows valid values and list of inputs correctly saved and printed (4 points)

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

            Output contains all the given test data and one additional data set (5 points)

Grading Deductions:

            Use of global variables will result in an overall grade of 0 (zero) [-100 deduction]

            Use of the exit, break (outside a switch), continue command, pointers, linked lists, or

other non-allowed items will result in an overall grade of 0 (zero) [-100 deduction]

 

            Labs which cannot be compiled or do compile with warnings

will receive an overall grade of 0 (zero) [-100 deduction]

            Labs which have errors in them and do not terminate normally

will receive an overall grade of 0 (zero) [-100 deduction]

 

            Missing design document will result in an overall grade of 0 (zero) [-100 deduction]

            Late submission of softcopy of code and/or script file to appropriate TA

will result in an overall grade of 0 (zero)

UNLESS student has obtained prior instructor approval [-100 deduction]

            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.

 

 

 

Miscellaneous:

 

Dr. T's Sample input:

500.00 250.00 69.99 50.00 15000.00 9 1 2014 4 X A N O 65 500 150 325 35.50 2.00 22.00 7.25 .75 .90 1.00 .90 3 M H S 2 1 5 17.50 10.00 25.00 15.00 14.10 7.95 120 48.8 76.4 27.50 4 S I B L 3 3 2 3 120.00 75.50

0 0 20 25 40.0 60.0 Hardy_Shrubs

0 0 100 10 20.0 20.0 Native_Shrubs

0 0 0 65 20.0 20.0 Hardy_Trees

0 400 0 75 55.5 20.0 Annuals

65 0 0 10 10.0 19.3 Perennials

0 0 0 140 45.5 35.3 Flowers

10.5 10.0

9.5 10.0

15.0 10.0

10.0 5.0

20.0 10.0

 

 

Your test data should be drawn from real data, i.e. a real garden store.