需要的qq1703105484
This assignment will test a student’s knowledge of, and skills in writing application software for a task, understanding the business rules of a particular problem, coding these in a computer program, developing a graphical user interface, and reading data from a text file on disk. As such, the assignment requires you to integrate and synthesise what you have learnt so far in this unit, in order to design and create a correct working solution. The context of this programming assignment is the Chook Food Company. For this assignment, students will use the Python programming language (version 3.x) and development will be on the IDLE platform as practised in the computer lab classes. This assignment consists of three stages. • Stage 1: A simple Python program using an interactive text-based menu (no GUI) • Stage 2: The same (stage 1) but wrapped in a GUI • Stage 3: Input comes from a text file – read only once, then information stored in a suitable data structure. (Advanced GUI) 4478 IIT Part A – Stage 1 (25 marks) Part B – Stage 2 (10 marks) Part C – Stage 3 (15 marks) Chook Food Company App Each type of chook food comes in 10 Kg bags and 50 Kg bags. Each chook food has a name, the cost of a 10 Kg bag and the cost of a 50 Kg bag. Stage 1: Pellets cost $22.75 for a 10 Kg bag and $100 for a 50 Kg bag. Mash costs $20.50 for a 10 Kg bag and $90 for a 50 Kg bag. Enhanced food costs $25.50 for a 10 Kg bag and $125.50 for a 50 Kg bag. These details can be hardcoded in your program (you may use a nested list to store these values). For this stage, your program should know about the three types of food above. Page 2 of 10 In Stage 1, you will be developing a Python program without a GUI. Input and output are via the Python shell. Write a Python program that displays a text based interactive menu to allow the users to: • Request displaying costs of the chook food for 10Kg or 50 Kg bags. • Perform chook food shopping as follows: 1- Allow the user to select the type of food they want to purchase from the menu. 2- Allow the user to select the price calculation method according to: 2.1 The Kilograms option, the user enters only the number of 10 kilograms increments, after that the price is calculated by using the cheapest way to buy exactly that weight of the chook food selected. The answer will be the number of 10 Kg bags or the number of 50 Kg bags and the total cost (see the sample test document). 2.2 The Bags options, the user needs to enter the number of 10kg bags and the number of 50kg bags and the price will be calculated according to these two choices (see the sample test document) Notes: • You should use functions for each task in the program, for example a printMenu function to print a menu and calculcateCost to calculate the cost of chook food etc. • Your program should have a main() function to appropriately direct the program. What the tutors will be looking for The tutor’s instructions include • Constants vs literals. Using constants is important for the ease of maintenance. Not using constants will result in lower marks. For example, consider constants for the price of chook food for 10Kg bag and 50 Kg bag. • Program code layout. Separate blocks of code by a blank line. Use comments. • Program is written using well-defined functions including a main() function to direct the program. • A comment is not an essay. Comments are important for the maintenance of a program and should contain enough details but keep them concise. Do not comment every single line. • The program must have a prologue. Check style against the Python style guide attached below. • Good names for your variables and constants. Check style against the Python style guide attached below. • Does the program work correctly? Please refer to the Programming Assignment Marking Rubric for details on marks. Step-by-Step Guide for Stage 1 1. Think about your strategy for how you will display the options for user to choose from, how you will calculate the total cost of chook food and how you would calculate the cheapest way to buy the chook food with given weight. Think about writing simple functions for the repetitive calculations. 2. Create a new Python file and call it ProgAsgStage1 Page 3 of 10 3. In the Stage1 class (file ProgAsgStage1.py), you may put all code for the user interaction and the calculation into the main method. (You might still need to define global variables and constants outside the main method at the top of the editor window). You might like to use nested lists to hold the chook food type and price for 10kg bag and 50 kg bag. 4. You will need to write a function to print a menu to the user, below a sample code as an example: 5. Now add the code that implements your strategy to display the different type of chook food TEST 6. Add the code to calculate the cost of 10 Kg bags and 50kg bags when a chook food is selected TEST 7. Add the code to calculate the cheapest way to buy the chook food for the weight entered TEST 8. Finally, add print statements to print the output to the user. 9. Test your implementation with the test cases, use the document (sampleTest -stage 1) as a guide. Please note, you need to do your own test with values different from the test cases in the document (Check the submission section in the last page). Page 4 of 10 Stage 2: In stage1, the user input and output are not very satisfactory from the human computer interaction and usability point of view, your task in this stage is to design and implement a Graphical User interface (GUI) using buttons and labels for the chook food company that provides an easy to use interface. The tasks are like stage 1, except you need to use GUI to interact with user. This GUI application must allow a user to input the various data elements. To this end, the user can • input the data using an entry widget • click on a Calculate button that starts the calculation of the chook food cost, and • an Exit or Quit button to properly close the program. Use the same code for the calculations from Stage 1. Reusing code is an important part of software development. You have a great degree of freedom in what GUI elements you choose and how you would like to design the layout of your GUI. What matters is the functionality of the design and that the user can input the required data in a sensible fashion. What the tutors will be looking for The tutor’s instructions include • Constants vs literals. Using constants is important for the ease of maintenance. Not using constants will result in lower marks. For example, in addition to Stage 1, consider constants for the default width and height of the labels, buttons and entry widgets to easily achieve a uniform look. • GUI Design. Is it simple to use and easy to understand? Are all required components there? Grid layout is used to place widgets. • Program is written using well-defined functions including a main() function to direct the program. • Program code layout. Separate blocks of code by a blank line. Use comments. • Separate GUI functionality from calculations. Students should use a separate method for the calculations. It is good practice and follows good programming style to separate GUI code from other code. • A comment is not an essay. Comments are important for the maintenance of a program and should contain enough details but keep them concise. Don’t comment every single line. • The program must have a prologue. Check style against the Python style guide attached below. • Good names for your variables and constants. Check style against the Python style guide attached below. • Does the program work correctly? Please refer to the Programming Assignment Marking Rubric for details on marks. Page 5 of 10 Stage 3: Complete the stage 1 & stage2 plus: The program will determine the list of chook food at run time. Do this by reading this data from the file chookfood.txt and data will be stored in a nested list. chookfood.txt is available on IIT Canvas site. The file chookfood.txt contains the chook food data for several chook food type. Each line consists of chook food type as the first element, followed by comma and the price of 10Kg bag and price of 50Kg bag. For example: Mash, 20.50,90.00 You will need to copy chookfood.txt into the same directory as your Python files. When marking, the details in the file may change, but the structure will not. Your task will be to: 1- Add code to your program that reads the chook food data from a text file. 2- Put these into appropriate storage in memory (I suggest you use a nested list) and display the details to user when requested. Please note that text file contains more food types than given in stage 1 and 2. 3- A List of different chook food types should be displayed using listbox widget to the user. 4- When the user clicks any food from the list, the price of that food must be displayed for 10kg and 50kg. 5- You should also use the advanced Python GUI components to create a graph to compare prices of different chook food type by different weights (10kg or 50kg) for all foods. Notes: • Food type should be displayed in the ascending order of type to the user. • The text file should only be read once. You probably want to do that at the start of the program. Consider how you would do that. • Write a Function called readFile to read the data from the text file What the tutors will be looking for The tutor’s instructions include (apart from the usual such as good variable names, prologue / comments, code layout, …) • Use of constants. Think about where you could use constants here. • The text file should only be read once. You probably want to do that at the start of the program. Consider how you would do that. • Program is written using well-defined functions including a main() function to direct the program. • Correct display of chook food information based on the details in the text file. • There are various ways you can store the data when reading the file. You could use a nested list. Page 6 of 10 Python Style Guide General Your programs should be • Simple • Easy to read and understand • Well structured • Easy to maintain Simple programs are just that. Avoid convoluted logic, nested if-statements and loops, duplicating execution (such as reading files multiple times), repeated code, being “clever”. Programs can be made easier to read by following the “Layout” and “Comments” guidelines below. Well-structured code uses functions to help tame complexity. If programs are simple, easy to understand and well-structured they will be easy to maintain. Easily maintained programs will also use constants rather than literals and use built-in functions and types. Layout The IDLE text editor does a good job of automatically laying out your program and it also helps with the indentation of the code inside an/a if-statements, loops and functions. It is very important in Python that you indent your code correctly. White space Use white space freely: • A blank line after declarations • 2 blank lines before each function declaration Names Well-chosen names are one of the most important ways of making programs readable. The name chosen should describe the purpose of the identifier. It should be neither too short nor too long. As a guide, you should rarely need to concatenate more than 3 words. Letter case Constants use ALL_CAPITALS separated by underscore if needed e.g. PI, MAX_STARS Variables use firstWordLowerCaseWithInternalWordsCapitalised e.g. cost, numStars It is a good idea to use the so-called Hungarian notation where the first letter (or two) indicates what type the variable has: • i for int, e.g. iNum • f for float, e.g. fFloatingPointNum • s for String, e.g. sName • bo for Boolean, e.g. boCar Functions use firstWordLowerCaseWithInternalWordsCapitalised e.g. cost(), numStars() Page 7 of 10 Types of names 1. Names of GUI widgets should have a prefix indicating the type of control (Python TK Interface). The prefix should be lower case with the remainder of the name starting with upper case. Control prefix example Entry Widget Label Widget List box Widget Scrollbar Widget Button Widget Radiobutton Widget Checkbutton Widget ent lbl lst scroll btn rb chkb entQuantity lblResult lstStudents yscroll for vertical scroll bar btnQuit rbColour chkbSugar 2. Names of functions that does not return a value should be nouns or noun-phrases Example: newSum = sum(alpha, beta, gamma) or newSum = sumOfStudents(alpha, beta, gamma) rather than newSum = computeSum(alpha, beta, gamma) 3. Names of functions that returns a value should be imperative verbs Example: calculateCost(quantity, price) rather than results(newSum, alpha, beta, gamma) 4. Names of Boolean functions should be adjectives or adjectival ph