Extra Credit Pre-Lab Assignment
, CSE 1320 Spring 2006
Due Date: See section website for due date
(see instructions on website for how to turn this in)
Topic objectives: Arithmetic
Control structures
Functions
1 - dimensional arrays
Data types
Modular programming structure
Error checking
Programming style
The goal for this lab is to provide an opportunity for practice of the topics covered in Chapters 1 -3 in Foster and Foster. These chapters will not be covered in detail in the 1320 class and it is assumed that the student is familiar with and can use all the concepts in those chapters. This assignment is designed to practice those concepts by creating a program. 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. 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, structs, multiple dimension arrays, strings, linked lists, or switch statements.
Almost everybody enjoys music! Some play it, some write it, and some listen to it. Since you are a music lover yourself, you are considering opening a music store. Your store will carry musical instruments, sheet music, recorded music (CDs, etc.) and associated items such as guitar strings and earphones.
To start your planning process you want to calculate some initial inventory costs. Since this is just a tool to do some rough costs, then your program will not be very sophisticated. The program will accept inventory information from the user and then calculate some information from that input and output it to the user.
Your program will first get input from the user using a function to read the input data. The user should be asked how many inventory items they will enter and the program will check that their number is less than or equal to ten (10). If the user’s number exceeds 10, the program should inform the user that 10 is the maximum number of inputs allowed. The program should then accept the number of items (one line of data for each item) that the user specified or ten (10) items if the user’s number was larger than ten.
For each inventory item the user should be asked to enter three numbers. Your program will read in the 3 numbers for each inventory item and store each number in a separate array. The three arrays should be large enough to hold 10 items each and their type should be defined appropriately to the type of number being read in. The 3 numbers will be an inventory item number, a cost per item, and a quantity of that item. The data for a single item will be entered by the user on one line as follows {there may be one or more spaces between the numbers}:
> 110923 329.49 5
where 110923 represents the item’s inventory number, 329.49 is the cost of a single one of these items, and 5 is the quantity the user will have of the item. Your program will read the first number and store it in the inventory item number array at some location i, then read and store the second number into the corresponding location i, in the cost array, and then read and store the third number into location i in the quantity array. Your program should read all three numbers within a single input command. Your program should read in as many lines of input for inventory items as were originally specified up to the maximum of ten lines of input (items). When all the data is entered, print a list for the user giving the inventory number, cost, quantity and total cost (cost * quantity) for each inventory item with one item per line.
Once the data has been read in and printed out to the screen in a list, your program should give the user a choice of four options: find the highest priced item, find the item with the largest quantity, calculate the total cost for all items, or end the program. Allow the user to execute one of these choices and then return to the menu to choose another action until the user chooses to end the program.
Three of these four options should be implemented as separate functions that are called from the menu function. The two find functions should simply look through all the items in the appropriate array, find the highest price or largest quantity and then print the item’s inventory number, and cost or quantity out to the user. The total cost function should multiply the cost times the quantity for each item and then sum all these products to get the total cost. This cost should be output to the user. If the user is finished, print a concluding message and then end the program.
Implementation
requirements:
The program should use the following data structures:
One dimensional integer arrays for recording inventory numbers and quantities
One dimensional floating point array for recording corresponding price of ONE item
The program should use the following control structures:
Function calls to perform tasks
A while or for loop to read the input data
If, if-else, or nested ifs to error check the first number and implement the menu options
The program should NOT use:
structs
multiple dimension arrays
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 with
a main routine and at least
one function for getting input from the user, one for a find function, and one
for calculating total cost. 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. See your instructor’s website for SPECIFIC instructions about the program 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 music store inventory. The first data set (data set 1) should use the values given below. You must also create two additional data sets and run your program with them as well. You may run it three times within a single execution or you may execute the program three different times so that you have a total of three different data sets. The sample data sets that you create must meet the guidelines given in the problem definition.
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.
Item number Cost Quantity //Comment describing item
987000 950.00 10 //Fender guitars
110923 329.49 5 //Mini mixer board
888564 17.99 12 //Nellie McKay CD
888533 15.99 2 //Tom Lehrer Greatest Hits
888200 17.99 25 //Various artists – Katrina
888175 9.99 3 //Vivaldi - Four Seasons
110277 1299.99 2 //Bose column speaker
987324 25.49 1 //Hoehner harmonica
322900 24.95 2 //Score of CATS for guitar
322034 4.98 3 //Beginner piano score
Grading scale:
Code: (61%)
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!) (16 points)
Style (indentation, consistency, meaningful
identifiers, lateral separation of code from line comments, etc.) (8 points)
Correct manipulation of the 1-dimensional
arrays (9 points)
Correct use of required control structures (6
points)
Correct function structure as required (6 points)
Proper implementation of input error checking (8
points)
Output: (39%)
User clearly understands what is being requested for input (5 points)
Calculation task performs mathematically correctly (4 points)
Search (find) tasks perform correctly (6 points)
List of inputs correctly printed (4 points)
Output gives clear information to explain the values to the user (8 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)
Use of the exit
command will result in an overall grade of 0
(zero)
Use
of structs, multiple dimension arrays, strings, linked lists, and/or switch
statements will result in 50 (fifty) point deduction per use
Late submission of softcopy to appropriate TA will result
in an overall grade of 0 (zero) without
prior instructor approval
Use of C language elements not yet discussed in class by
the lab due date will result in potential deduction of points – discuss with
instructor before using.