ECE Application Programming

Slides:



Advertisements
Similar presentations
ECE Application Programming
Advertisements

I wonder who has more money…. 1 dollar, 3 nickels, 5 dimes 6 dimes, 3 pennies, 5 quarters 8 pennies, 6 nickels, 3 dimes 2 half dollars, 5 pennies, 8 nickels.
Penny Nickel Dime Penny Nickel Dime Quarter Half Dollar.
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Counting Coins. The Basics Quarter 25 cents Dime 10 cents.
Name the United States Coins Count the Pennies 10 ¢
While loops while ( ) { } while ( ) ;
ECE Application Programming
What is your strategy for counting money?
ECE Application Programming
ECE Application Programming
ECE Application Programming
ECE Application Programming
ECE Application Programming
ECE Application Programming
ECE Application Programming
ECE Application Programming
ECE Application Programming
k-2 Lesson d: kids as coins Coin Signs
Money Concept Assessment Bank
ECE Application Programming
Name the United States Coins
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.3170 Microprocessor Systems Design I
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
Instructor: Dr. Michael Geiger Spring 2019 Lecture 29: Linked queues
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
Money Math Review.
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
Instructor: Dr. Michael Geiger Spring 2019 Lecture 34: Exam 3 Preview
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.3170 Microprocessor Systems Design I
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
Presentation transcript:

16.216 ECE Application Programming Instructor: Dr. Michael Geiger Fall 2011 Lecture 24: Finishing PE4: Functions

ECE Application Programming: Lecture 24 Lecture outline Announcements/reminders Removing project; programs now worth 60% Exam 2: Wednesday 11/9 Allowed 1 double-sided sheet of notes Practice problems to be posted over weekend Prog. 6 to be posted this weekend; due Mon, 11/14 Prog. 5 grading done today; regrades due Mon, 11/7 No late penalties; will post solution 11/7 Today: Finishing PE4 (functions) Identify where function(s) can be used Write code Test using debugger 9/14/2018 ECE Application Programming: Lecture 24

ECE Application Programming: Lecture 24 PE4: Change problem Given any amount of change under $2.00, determine and print out the minimum number of coins required to make that amount of change. Available coins are Halves (half dollars), Quarters, Dimes, Nickels, and Pennies. 9/14/2018 ECE Application Programming: Lecture 24

ECE Application Programming: Lecture 24 Flowcharting - Sample Start scanf amount nHalves = 0 Given some amount of money, amount, how many half dollars would be returned? myAmt = amount myAmt < 0.50 myAmt = myAmt - 0.50 nHalves = nHalves + 1 printf nHalves Finish 9/14/2018 ECE Application Programming: Lecture 24

Expand to all coins - page 1 Start nH = 0 scanf amount myAmt < 0.50 myAmt = amount A myAmt = myAmt - 0.50 nH = nH+ 1 B 9/14/2018 ECE Application Programming: Lecture 24

ECE Application Programming: Lecture 24 B C nQ = 0 nN = 0 myAmt < 0.25 myAmt < 0.05 myAmt = myAmt - 0.25 myAmt = myAmt - 0.05 nQ = nQ + 1 nN = nN + 1 nD = 0 nP = 0 myAmt < 0.10 myAmt < 0.01 myAmt = myAmt - 0.10 myAmt = myAmt - 0.01 nD = nD + 1 nP = nP + 1 9/14/2018 ECE Application Programming: Lecture 24 C D

ECE Application Programming: Lecture 24 D printf nH,nQ,nD,nN,nP Finish 9/14/2018 ECE Application Programming: Lecture 24

ECE Application Programming: Lecture 24 When to use functions Find a particular step or series of steps being repeated in your code If code is exactly the same, you need no arguments If one or more values change, but the actual calculations that need them are the same, those values can be parameters of your function (arguments) Reassess change example Steps for creating change are extremely similar What changes each time? How should we use those values in a function? Inputs, outputs, variables … ? 9/14/2018 ECE Application Programming: Lecture 24

ECE Application Programming: Lecture 24 B General case: nC=number coins Output vC=value of coin Input myAmt=amt left Input/Output nQ = 0; vQ=0.25 myAmt < vQ myAmt = myAmt - vQ nQ = nQ + 1 function: change nC = 0; vC=input nD = 0; vD=0.10 myAmt < vC myAmt < vD myAmt = myAmt - vC myAmt = myAmt - vD nC = nC + 1 nD = nD + 1 return 9/14/2018 ECE Application Programming: Lecture 24 C

(addr nC, val vC, addr Amt) change(&nQ,0.25,&myAmt) Start General case: nC=number coins Output vC=value of coin Input myAmt=amt left Input/Output scanf amount myAmt = amount change(&nH,0.5,&myAmt) function:change (addr nC, val vC, addr Amt) change(&nQ,0.25,&myAmt) change(&nD,0.1,&myAmt) *nC = 0; vC=input *myAmt < vC change(&nN,0.05,&myAmt) change(&nP,0.01,&myAmt) *myAmt = *myAmt - vC printf nH,nQ,nD,nN,nP *nC = *nC + 1 return 9/14/2018 ECE Application Programming: Lecture 24 Finish

ECE Application Programming: Lecture 24 Next time Exam 1 Preview 9/14/2018 ECE Application Programming: Lecture 24