1. 程式人生 > >Introduction to Information Technology/G 4478/8936

Introduction to Information Technology/G 4478/8936

eva change fashion argument nging intern ret dir sign


Programming Assignment
Introduction to Information Technology/G 4478/8936
Note 1: Only use IDLE (with Python 3.6 or above) to write this assignment! For the purpose of this
assignment, you are not allowed to use any other Python IDE and you are not allowed to use any other
version of the Python.
Note 2: Familiarise yourself with the Python Style Guide at the end of this document.

Note 3: All cases of plagiarism will be pursued! If in doubt, consult the Student Academic Integrity Policy
http://www.canberra.edu.au/current-students/canberra-students/conduct
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, reading data from a text file on disk, and connecting to an SQL
database from within the program. 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 four
stages, with different requirements for undergraduate students in 4478 Introduction to Information
Technology and for postgraduate students in 8936 Introduction to Information Technology G.
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)
Stage 4: Input comes from an SQL database file. Generates a Database Report.
4478 IIT 8936 IIT G
Part A – Stage 1 (25 marks) Part A – Stages 1 and 2 (27 marks)
Part B – Stage 2 (10 marks) Part B – Stage 3 (13 marks)
Part C – Stage 3 (15 marks) Part C – Stage 4 (10 marks)
Bonus* – Stage 4 (up to 10 marks)

代做4478/8936作業、Python程序語言作業調試、Python課程作業代寫、代做Information Technology/G作業
*Stage 4 is a bonus stage for undergraduate students to give them a stretch target. It allows you to pick
up extra marks to make up for marks lost elsewhere in the assignment but note that you cannot achieve
more than 50/50 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:
Page 2 of 10
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.
For this stage, your program should know about the three types of food above.
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:
Choose what type of chook food they want to buy.
Displays costs of the selected food and total of number of 10Kg or 50 Kgs bags if user requires.
The program also gives the user the option of entering in a weight of chook food in 10kg
increments and asking 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.
Students may use a nested list to store the chook food type in their program.
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, you may 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 a
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.
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 bag when a chook food is selected TEST
7. Add the code to calculate the cost of 50 Kg bag when a chook food is selected TEST
8. Add the code to calculate the cheapest way to buy the chook food for the weight entered TEST
9. Finally, add print statements to print the output to the user.
10. Test your implementation with the test cases mentioned below (and additionally your own).
For steps 6, 7 & 8 work out your tests before you do any coding
Test cases:
Test 1
Chook Food Selected Pellets
Selected Weight 10
number of bags 5
Total Cost $ 113.75
Page 4 of 10
Test 2
Chook Food Selected Mash
Selected Weight 50
number of bags 7
Total Cost $ 630.00
Stage 2:
In stage1, the user input and output is 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.
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.
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.
Page 5 of 10
Does the program work correctly?
Please refer to the Programming Assignment Marking Rubric for details on marks.
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/IIT G 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.
Mash,25.50,108.25
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 add code to your program that reads the chook food data from the text file, 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. List of
different chook food types should be displayed using listbox widget to the user. You should also use the
advanced Python GUI components to create graph to compare prices of different chook food type by
different weight(10kg or 50kg)
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.
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.
A graph to compare prices of different chook food type by different weight (10kg or 50kg) has
been created correctly.
Stage 4: bonus for 4478 and required for 8936
Here, the input will now come from an SQL database contained in the MS Access file chookfood.mdb.
This file is available on the IIT / IIT G site on Canvas. There is only one table in the database tblChookFood
Page 6 of 10
tblChookFood contains fields FoodType, Producer, BagSize, BagPrice and Stock. A typical record would be
<Mash, FMS, 10, $25.50, 65>.
Write a Python program using a GUI (Note: extending your GUI program from stage 3 is acceptable, but
you could also write a separate Python file for Stage 4, either way is ok)
Let the user select the name of a chook food type (e.g. from a list) and display the price of the
chook food for 10Kg, 50 Kg & 100kg if applicable bag and the available stock.
Create a database best buy report consisting of all chook food types and the best buy is the lowest
price per Kg. You report should include Food Type, Producer, BagSize, BagPrice, Stock and
price/Kg”. The report should be in ascending alphabetical order of Food Type. It should be written
to a file “database_report.txt”. Make sure that your columns are properly aligned. Text
columns should be left aligned, number columns right aligned and rounded to 2 decimal places.
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 …)
Correct connection to the database.
Correct identification of all the different food type and their related data.
Make sure that the lines in the database reports are split into pages and the columns are lined up
and correctly formatted.
Program is written using well-defined functions.
Page 7 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) indicate 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 8 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
chkbSuger
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 phrases
Example:
if (empty(list))
or
if (isEmpty(list))
rather than
if (checkIfEmpty(list))
Comments
Comments should explain as clearly as possible what is happening. They should summarise what the
code does rather than translate line by line. Do not over-comment.
Page 9 of 10
In Python, use ##Comment for a one-line comment.
Comments are used in three different ways in a program:
Heading comments
Block comments
End-of-line comments.
Heading comments: These are generally used as a prologue at the beginning of each program and
function. They act as an introduction, also describe any assumptions and limitations. They should show
the names of any files, give a short description of the purpose of the program, and must include
information about the author and dates written/modified.
Block comments: In general, you should not need to comment blocks of code. When necessary, these are
used to describe a small section of following code. They should be indented with the program structure
to which they refer. In this way the program structure will not be lost.
End-of-line comments: These need to be quite short. They are generally used with parameters to
functions (to explain the purpose and mode of the parameter), and/or with variable declarations (to
explain the purpose of the variable), and are not meant to be used for code.
Comment data, not code: Comments about the data – what it is and how it is structured - are much more
valuable than comments about the code.
Prologue
Each of your programs should have a prologue. This is a set of “header comments” at the top of editor
window. It should include
who wrote it // Author: Damith Herath
when it was written // Date created: 21 Feb 2019
when it was last changed // Date last changed: 21 Mar 2019
what it does // This program does...
what files it reads / writes // Input: sample.txt, Output: none
Named Constants
Program sometimes employs a special constant used several times in program. By convention Python
programmers create a global variable and name is written in uppercase letters with words separated by
underscore. For instance, SPEEDING_FINE, INTEREST_RATE
The special naming convention reminds the programmer that no reassignments to the variable
should be made during the execution of the program. Since Python allows reassignments to any
variable, hence the programmer is responsible for not changing the value of the variable.
This makes your program easier to maintain. If the speeding fine or interest rate changes, the change
only has to be made in the one place.
Functions
Using functions is one of the simplest and most effective ways of dealing with complexity in a program.
Page 10 of 10
When you write your own function to perform a calculation, it
should not refer to any GUI controls.
Do not mix IO and calculations in a function.
Function that does not return a value
encapsulates a task
name should be a npun. Example: sum()
should only do 1 task.
Function that returns a value
o encapsulates a query
o return type is int, boolean, double…;
o if return type is boolean, name should be an adjective, otherwise name should be a verb.
Examples: isEmpty(list), SquareRoot(number)
o should answer only 1 query.
Comments for each function should include (to be placed on the line before the function starts)
name above rules apply
purpose what it evaluates or what it does
assumptions any assumptions made, particularly on the arguments
Duplicated Code
View any duplicated code with suspicion. Look for a way of factoring the duplicated code into a function.
Built-in functions
Unless you have a good reason, use built-in functions rather than writing (or not writing) your own. They
will be correct, flexible and familiar to a reader.
Types
Using types is an important way of making your intentions clear. Python does not allow you to be sloppy
with your types. In IIT / IIT G, you are expected to choose appropriate types. You are also expected to use
type conversions such as int (23.26)
Simplicity
Simplicity has long been recognised as one of the most important characteristics of programming. There
are many ways of simplifying programs. These include avoiding nested IF statements, nested loops and
complex conditions.

因為專業,所以值得信賴。如有需要,請加QQ99515681 或郵箱:[email protected]

微信:codinghelp

Introduction to Information Technology/G 4478/8936