SI 204 Spring 2010 Programming Project 2 Number Analysis Executive Summary In an attempt to show off your new found computer programming skills you have decided to impress your roommate, an avid baseball fan, with a batting average analysis tool. Your program will load a file consisting of an entire leagues batting average and perform various functions with that data. Due Dates and Honor Steps 1 - 3 of this project will be due by the “close of business” on Thursday March 11, 2010. • Meeting this milestone is worth 10 points of your final grade. • You will receive 6 points for submitting your milestone late but prior to 1600 on 12 March 2010 (commencement of spring break). • You will receive 4 points for submitting your milestone late but prior to 0745 on 22 March 2010 (completion of spring break). • Code must be submitted electronically via blackboard and in writing: o Blackboard – submit your code under step 3. o Written – Turn in a copy of your code and screen shot showing the array being loaded. o Style/Comments are encouraged but not graded at this point. The project will be due by the “close of business” on Thursday March 25, 2010. See the course policy for details about due dates and late penalties. Again, this is a Programming Project, and it is very important that you understand and abide by the Department's policy concerning programming projects. Please view: http://www.cs.usna.edu/academics/ProgrammingPolicy.pdf Important Notes Up Front 1. You must submit your work on Blackboard as you go (after completing each step) -- not just the final product. 2. You must write and use a different function for each step, where that function does the bulk of the work. 3. Your program must use an array to store the data. For full credit, each function must fully process the contents of the array as appropriate (e.g., if there are 100 samples, deal with all 100, not 99!), and not access any invalid array indices (e.g., going beyond the end of the array). Details The project is divided up into several functions, worth varying number of points, not strictly based on difficulty. You are strongly encouraged to solve each function - including thorough testing. Your maximum grade will depend upon which functions you get working. All of your program’s functionality will be implemented via function calls, with your main() function serving primarily as central hub with some sort of selection structure calling the functions that implement the required functionality. The user should be able to continue selecting options until he chooses to quit. A sample input file is provided for you on the course website. It contains a list of batting averages for the entire National League in 1998. The first item in the data file consists of the number of entries in the file, in this case 436. Your program must be able to work with any file of this type – a file that contains the number of entries on the first line and then a list of doubles. Step 1: (10 pts.) Display menu Using a function, print a menu to the screen and return the user’s menu selection to main( ) function. The menu should include a selection option for all the features your program is capable of; as well as a quit option. Your function should continue to ask the user for their choice until a valid choice is entered. Step 2: (10 pts.) Load File • This function should: o Ask the user for the file name to be read in o Open the file. If this fails then print an error message and return to main. o Create an appropriately sized array to store the data o Read in and store the data in an array o Return the data array and the size of the array, to main( ) • From main report the number of elements in the array • You can assume that the first line in any data file contains the number of data points in the file • Your function should be capable of handling any number of data points Step 3: (10 pts.) Print the contents of the array to the screen or to a file. • main should: o Ask the user if they wish to print to the screen or to a file o If the output is going to a file input the name of the file from main o Pass the correct output control variable to the function (ie cout or a file output variable) • This function should: o Output all values currently loaded into the array to the users chosen destination (screen or file) o Note: the screen shot below shows the output going to the screen and shows only the last few entries of the file. Step 4: (7.5 pts.) Find the maximum value • This function should: o Search the entire array for a maximum value o Return the maximum value and the index number of where that value resides in the array to main( ) • From main report the maximum value and its index value. Step 5: (7.5 pts.) Find the minimum value • This function should: o Search the entire array for a minimum value o Return the minimum value and the index number of where that value resides in the array to main() • From main report the minimum value and its index value. Step 6: (10 pts.) Find the average value • This function should: o Find the average of all values contained within the array o Return the average value to main() • From main report the average value. Step 7: (20 pts.) Display Histogram • Note: Histograms are a way to display the frequency (ie how often) something occurs. In this case we will use a histogram to show how many players batting averages fall into a specific range. If the scale of your histogram is 10 your program should output a ‘*’ for every ten players whose batting average fall into a specific range. Thus the 4 stars shown on line 3 below indicate that at least 40 but not more than 49 players batted between .3 and .399 during the course of the season. • This function should: o Ask the user for a scale for the histogram (note: scale of 10 means 10:1 ratio) o Separate the data in the file into 10 bins where each bin corresponds to 100 points of batting average (.000-.099, .100 – .199, and so forth) o Display an appropriate number of ‘*’ based on the user provided scale o In the case where some data is present but not enough to meet the scale (ie only 1 person hit over .500 but the scale is 10) your program should output a ‘X’ to alert the user. Step 8: (15 pts.) Filter the Data • This function should: o Ask the user for a minimum batting average o Create a new array consisting only of those batting averages greater than the minimum • Main should Report how many data points are contained in the new array. • The user should then be able to perform all of the previous listed operations with this new filtered array. (As shown by the screen shot on the right with a new minimum batting average of .203) Step 9 Extra Credit: (Max 5 points) Report the Name • Copy and paste your program into a new file. • Modify it so that it correctly inputs the second input file (extracredit.txt) • Modify it so that it will display the name of the player with the maximum or minimum batting average vice the index of the array. Step 10 Extra Credit: (Max 5 points) Find the Median Value • This Function should: o Sort the array so it is in order from least to greatest o Return the median value to main • Main( ) should then report the median value to the user • Note: median is the “middle” value in an array with an odd number of cells or an average of the two middle values in an array with an even number of elements. If your sorted array has 11 total values the median value is found in the 6th entry of your array. Friendly Reminder: • You MUST submit a working solution for EACH of the above steps as you complete them. Submit just the project2.cpp file. It’s okay if you make some changes to a step after you submit it, but we want to see the progression of your steps. The individual steps will not be graded for style or functionality – as long as it looks reasonably like you submitted the steps, what counts will be the style and functionality of the final result (submit on Blackboard as such) Important grading points: • The default method of passing variables is pass by value you may only use pass by reference when necessary. • Remember to make your code generic enough to work in all cases. This is especially applicable on step 3! • Appropriate use of functions to implement this program is critical to receiving the maximum possible score. • If your program does not compile as submitted, you will receive a zero. • Your program must read input and write output in the exact format specified in this project description. • Your program’s source code must comply with the Required Style Guide in order to maximize the grade you receive on this project. • Your grade will also depend on the reasonable use of C++ code. Don’t use 50 lines of code where 5 would do. There will be both a paper and an electronic part to your submissions. The paper submission can be handed to your instructor or slid under their office door (but do not put your project in their mailbox). For the purposes of any late penalties, your project is not considered submitted until your instructor receives BOTH the electronic and paper portions of your submission. Any disagreement between your paper and electronic submissions will result in a grade reduction. Electronic submission: Unless otherwise specified by your instructor, your electronic submission should be made via Blackboard. As you complete each step you should submit your project2.cpp file. Submitting steps out of order is completely acceptable! Simply note the out of order submission in the comments at the top of your code with your name. i.e., “Submitting Step 6, step 5 has not yet been completed”. When completely finished, submit your project2.cpp file under the “Final submission” link on Blackboard. If you desire to submit a revised solution to any completed step notify your instructor via email so they can clear your previous submission. However, unless changes are dramatic this is not required for intermediate steps (see “Friendly Reminder” above) – the final submission is what is graded. Paper submission: Staple in this order: • Cover sheet, with signed honor statement • Printout of your code. Make sure the indentation is correct on the printout! See notes on printing on the course homepage • Screenshots for each function that works. Be sure to LABEL each one (e.g., “STEP 5”). TIPS: • Follow the Style Guide as you go! It’s easier to indent and comment as you write than at the end, and you’ll make it easier on yourself to write your program. And you’ll maximize your grade by following the guidelines. • Compile often so you don’t end up with a snake’s nest of errors all at once • Save backups of project2.cpp in case your sponsor’s dog eats your X drive. • Start early! Allow time for you to get new ideas and to see the instructor for help. • • Remember that this project is not to be discussed with anyone besides your instructor! Don’t defeat your learning AND jeopardize the honor of yourself or your friends by talking to them about it. Remember you may not use any online sources except the course website!