At the end of this lesson, you will be able to:
A1.3 use assignment statements correctly with both arithmetic and string expressions in computer programs;
B2.4 represent the structure and components of a program using industry-standard programming tools (e.g., structure chart, flow chart, UML [Unified Modeling Language], data flow diagram, pseudocode);
B4.1 describe the phases (i.e., problem definition, analysis, design, writing code, testing, implementation, maintenance), milestones (e.g., date of completion of program specification), and products (e.g., specification, flow chart, program, documentation, bug reports) of a software development life cycle;
understand how to create pseudocode
format a string to look like money
With a pencil and paper, answer the following questions:
Declare a variable in Python that holds whether or not the living room lights have been left on. Then do the same for C++.
Declare a constant in Python that represents the Nike slogan "Just do it". Then do the same for C++.
Create the top-down design and flowchart of a program that asks the user for the cost of an item. It then tells them the total cost with tax.
Write 1 test case for the above program.
Write the code for the program above in Python.
constants in Python & C++
in Python we create a separate file to hold the constants.
how to create a flowchart
flowchart vs top-down design
top-down design is compartmentalized into input, process & output
flowcharts describe the sequential flow of the program
from the online book Computer Based Problem Solving by Patrick Coxall, read:
read "Design your Coding Project: Storyboards and Pseudocode"
what is pseudocode?
a language that is in between English and code that helps programmers develop their code
what is a storyboard?
a graphic organizer that provides the programmer with a high level view of a what the program will look like
go over what Pseudocode is
write key words in CAPS to improve readability
indent as you would when coding
go over formatting a variable as currency in Python:
print ("The total cost is: ${:,.2f}". format (total_cost))
print ("The cost for a {0} inch pizza is: ${1:,.2f}".format(diameter, total_cost))
here is the problem:
the cost of making a pizza is:
labour cost is $2.00/ pizza, regardless of size
rent for the shop works out to $2.25 / pizza, regardless of size
materials are $1.50 / diameter inch of pizza
create a program that calculates the total cost (including HST) for a pizza with a given diameter.
GET lamp is not on
IF (lamp plugged in == no) THEN
plug in lamp
ELSE
IF (bulb burnt out == yes) THEN
replace bulb
ELSE
repair lamp
ENDIF
ENDIF
GET diameter
CALCULATE subtotal = 2.00 + 2.25 + 1.5*diameter
CALCULATE tax = HST * subtotal
CALCULATE total = subtotal + tax
DISPLAY total
in groups of 2, do the following on the board for today's daily assignment:
Top-Down Design
Flow Chart
Pseudocode
complete the Daily Assignment section in Hãpara Workspace for this day
if Hãpara is not working, make a copy of this document
move it to your IMH-ICS folder for this course
create the same above program in C++
check out "Rounding to Two Decimal Places in C++"
in C++ , to found to 2 decimal places:
#include <iomanip>
std::cout << std::fixed << std::setprecision(2) << std::setfill('0') << finalCost << "\n";