Lab Assignment # 1, CSE 1320 Sections 001 and 501, Fall 2004

 

Due Date:                  Section 501 – Sept. 21st, 5:30 pm

Section 001 – Sept. 22nd , 1:00 pm. 

(see instructions on website for how to turn this in)

 

Topic objectives:                                Arithmetic

                                Control structures

                                Functions

                                1 - dimensional arrays

                                Programming style

 

Books!  You loooo-ooove books!  In fact, you are thinking of starting your own used book store (“ Plus or Minus Perfect Books” or ‘±Perfect’ for short).  Before you decide to start this venture though you want to try to figure out some of the financial parameters of such a store and think about the stock you would sell in your store.  This program then will be the financial simulation for ±Perfect.

 

For your store, one thing you are trying to decide is if you will sell all types of books or if you will specialize in certain books.  As part of your planning process you will be estimating stock amounts for various categories of books.  Then for each category you will estimate an average book price and a category percentage which will represent what fraction of the original price will be your used-book selling price, i.e. 50% for half-price, 25% for one-quarter price, etc.  Given these numbers you will then try out different scenarios to see what looks like the best financial strategy for ±Perfect.  The following are the tasks you must do:

 

1)       First you must get from the user the number of books in stock in each category for your store.  Your store must have at least 10 different categories listed in alphabetical order  and they must include the six categories given below plus at least four more categories of your own. (Your categories can be alphabetically interspersed as appropriate, i.e. Animals as a new category should go first.)  The required categories are: 

a.       Cookbooks

b.      History

c.       Mystery

d.      Science fiction

e.       Self-help

f.        Sports

        You will prompt the user with the name of a category and ask how many books are estimated to be in that category.  Your program will then store the numbers given for each category.  Example:  How many sports books will ±Perfect  carry?    300

        Remember that your store may be specializing in certain types of books so some required categories may have zero amounts.  Store these amounts in an array of ten (or more if you have more than ten categories) integers where each element of the array corresponds to a category in the alphabetical list.  E.g. The first array element would correspond to cookbooks in the list above.

2)       Next you must go through the categories again and ask the user the average cost of a book from this category.  This should be an amount in dollars and cents.  Store these amounts in another array of ten (or more) floats corresponding to the categories.

3)       Finally you should go through the categories again and ask the user for a percentage to use as the selling point for books in this category.  The user must enter the number as an integer, that is, as a whole value out of 100, i.e. 65% is entered as 65 not as 0.65.  If the user enters a value less than 0 or greater than 100, the program should instead use the default percentage of 50% for the cost of books in that category.  Convert the input integer percent to the appropriate equivalent floating point decimal and store these amounts in another array of ten (or more) floats corresponding to the categories.

NOTE:  Tasks 1, 2, and 3 above are listed as three separate iterations through the category list but you can implement them as one pass through the category list getting all three pieces of data for each category if you wish.  You must still have one array for the amount of books in each category, one array for average book price in each category and one array for percentage selling point for each category.

4)       After input is done, print out the data for each category to the screen – the name of the category, the number of books, the average price and the selling percentage.

5)       Once you have all the data collected from the user, you must perform the following calculations and output the results:

a.       For each category, multiply the average price times the selling percentage to get the selling price and print this value with a label.

b.      Then for each category, multiply the amount of books in that category times the selling price to get the gross receipts and print this value with a label.

c.       Then for the whole bookstore, print the total number of books and the total gross receipts and then calculate the average selling price per book for the store overall and print this.

After this is done, your program must ask the user if they wish to run the financial simulation again and if so, go back to the beginning and request the user to enter new values for all data.  If the user is finished, print a concluding message and then end the program.

 

Implementation requirements:

The program should use the following data structures:

Integer array for category book amounts

Floating point array for category book average price

Integer variable(s) for percentage value input

Floating point array for category book selling percentage

 

The program should use the following control structures:

Function calls to perform the tasks

A while or for loop to perform calculations and output for each category

If, if-else, or nested ifs to check the magnitude of the percentage input

 

The program should be implemented as a set of functions with at least one function for getting input from the user, one for printing the category data, and one for performing calculations.  You may use more functions than this but you must use at least this many. 

 

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.  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 two different times with one repeat within a single execution 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.

 

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

 

Sample input values for data set 1:    <Your 1, 2, 3, 4  are the categories you added>

Cookbooks:          Amount is 250,         average price is 14.99, and         selling percentage is 50%

History:          Amount is 100,         average price is 21.49, and         selling percentage is 25%

Mystery:         Amount is 2500,         average price is 5.99, and         selling percentage is 60%

Sci-fi:             Amount is 5050,         average price is 5.00, and         selling percentage is 50%

Self-help:          Amount is 200,         average price is 19.99, and         selling percentage is 30%

Sports:         Amount is 1000,         average price is 10.50, and         selling percentage is 80%

Your 1:         Amount is 10,         average price is 1.50, and         selling percentage is 100%

Your 2:         Amount is 0,         average price is 100.00, and         selling percentage is 95%

Your 3:         Amount is 200,         average price is 12.00, and         selling percentage is 102%

Your 4:         Amount is 45,         average price is 30.00, and         selling percentage is 0%

 

Grading scale:

Code:     (66%)

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

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

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

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

Correct use of required control structures (10 points)

Correct function structure as required (10 points)

Proper implementation of input error checking (8 points)

Output:          (34%)

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

                Each task performs mathematically correctly (4 points per task a., b, c.)

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

                Output contains all the sample data and two additional data sets  (12 points)

Deductions:

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

                Late submission of softcopy to appropriate TA 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.