Day3 PDF
Day3 PDF
Algorithms
Introduction
What is an algorithm?
Introduction
What is an algorithm? A step-b -step set o! e"plicit instructions !or sol#ing a problem.
Introduction
What is an algorithm? A step-b -step set o! e"plicit instructions !or sol#ing a problem. $. Wash %. &inse 3. &epeat
Introduction
What is an algorithm? A step-b -step set o! e"plicit instructions !or sol#ing a problem. $. Place 'e in loc'. $. Place the sil#er 'e in the top loc'.
(lo) Charts
,es
Change bulb
(lo) Charts
,es
Change bulb
(lo) Charts
,es
Plugged in?
(lo) Charts
,es
Plugged in?
(lo) Charts
,es
$. *urn on s)itch Plugged in? %. I! light is on/ 0uit. ,es 3. I! lamp is plugged in/ go to 5. 1. Plug in lamp. 2o to %. 5. Change bulb. 2o to %.
Change bulb
3a'ing a peanut butter and 4ell sand)ich: 5as ans)er: Put peanut butter and 4ell on bread.
3a'ing a peanut butter and 4ell sand)ich: Precondition: $. %. 3. ... Postcondition: Sand)ich is read to eat.
3a'ing a peanut butter and 4ell sand)ich: Precondition: We ha#e peanut butter/ 4ell / and t)o slices o! bread. $. %. 3. ... Postcondition: Sand)ich is read to eat.
3a'ing a peanut butter and 4ell sand)ich: Precondition: We ha#e peanut butter/ 4ell / and t)o slices o! bread. $. %. 2roup Pro4ect (ill in the steps )ith e"plicit instructions 3. ... Postcondition: Sand)ich is read to eat.
3a'ing a peanut butter and 4ell sand)ich: Precondition: We ha#e peanut butter/ 4ell / and t)o slices o! bread. $. Place slices o! bread on plate/ side b side. %. Spread peanut butter on one slice o! bread. 3. Spread 4ell on the other slice o! bread. 1. Pic' up one slice and turn it o#er. 5. Place slice being held on top o! other slice. Postcondition: Sand)ich is read to eat.
3a'ing a peanut butter and 4ell sand)ich: Precondition: We ha#e peanut butter/ 4ell / and What plate? t)o slices o! bread. $. Place slices o! bread on plate/ side b side. 6o)? %. Spread peanut butter on one slice o! bread. Which one? 3. Spread 4ell on the other slice o! bread. 1. Pic' up one slice and turn it o#er. 5. Place slice being held on top o! other slice. Postcondition: Sand)ich is read to eat.
Calculating 7od 3ass Inde": Precondition: 6eight is pro#ided in meters. Weight is pro#ided in 'ilograms. $. %. 3. ... Postcondition: 73I is calculated.
Calculating 7od 3ass Inde": Precondition: 6eight is pro#ided in meters. Weight is pro#ided in 'ilograms. $. S0uare the height. %. 3. ... Postcondition: 73I is calculated.
Calculating 7od 3ass Inde": Precondition: 6eight is pro#ided in meters. Weight is pro#ided in 'ilograms. $. S0uare the height. %. .i#ide the )eight b ... 3. ... Postcondition: 73I is calculated.
Calculating 7od 3ass Inde": Precondition: 6eight is pro#ided in meters. Weight is pro#ided in 'ilograms. $. S0uare the height. Call this height%. %. .i#ide the )eight b height%. Call this 73I. 3. ... Postcondition: 73I is calculated.
Calculating 7od 3ass Inde": Precondition: 6eight is pro#ided in meters. Weight is pro#ided in 'ilograms. $. S0uare the height. Call this height%. %. .i#ide the )eight b height%. Call this 73I. Postcondition: 73I is calculated.
Writing a Program
Writing a Program
Precondition: 6eight is pro#ided in meters. Weight is pro#ided in 'ilograms. $. S0uare the height. Call this height%. %. .i#ide the )eight b height%. Call this 73I. Postcondition: 73I is calculated.
double BMI() { }
Writing a Program
Precondition: 6eight is pro#ided in meters. Weight is pro#ided in 'ilograms. $. S0uare the height. Call this height%. %. .i#ide the )eight b height%. Call this 73I. Postcondition: 73I is calculated.
double BMI(double height, double weight) { }
Writing a Program
Precondition: 6eight is pro#ided in meters. Weight is pro#ided in 'ilograms. $. S0uare the height. Call this height%. %. .i#ide the )eight b height%. Call this 73I. Postcondition: 73I is calculated.
double BMI(double height, double weight) { double height2 = height * height; }
Writing a Program
Precondition: 6eight is pro#ided in meters. Weight is pro#ided in 'ilograms. $. S0uare the height. Call this height%. %. .i#ide the )eight b height%. Call this 73I. Postcondition: 73I is calculated.
double BMI(double height, double weight) { double height2 = height * height; double bmi = weight/height2; }
Writing a Program
Precondition: 6eight is pro#ided in meters. Weight is pro#ided in 'ilograms. $. S0uare the height. Call this height%. %. .i#ide the )eight b height%. Call this 73I. Postcondition: 73I is calculated.
double BMI(double height, double weight) { double height2 = height * height; double bmi = weight/height2; return bmi; }
-e"t Wee'