300 likes | 433 Views
CS 100 Introduction to Computing Seminar September 16, 2014. Let's Work on Some Programs (1). Textbook, page 77, Programming Exercise #2 Develop an algorithm. Let's Work on Some Programs (2). Textbook, page 77, Programming Exercise #2 Develop an algorithm Step 1: Introduce the program
E N D
CS 100 Introduction to Computing Seminar September 16, 2014
Let's Work on Some Programs (1) • Textbook, page 77, Programming Exercise #2 • Develop an algorithm
Let's Work on Some Programs (2) • Textbook, page 77, Programming Exercise #2 • Develop an algorithm • Step 1: Introduce the program • Step 2: Ask for the amount of projected sales • Step 3: Record the user’s response for projected sales. • Step 4: Calculate the projected profit. • Step 5: Provide the user with the projected profit. • Step 6: Stop
Let's Work on Some Programs (3) • Textbook, page 77, Programming Exercise #2 • Develop a flow chart
Let's Work on Some Programs (4) • Textbook, page 77, Programming Exercise #2 • Develop a flow chart • http://www.cs.sunyit.edu/~urbanc/cs_100_sep_16_1.pdf
Let's Work on Some Programs (5) • Textbook, page 77, Programming Exercise #2 • Develop source code
Let's Work on Some Programs (6) • # Create and initialize variables to hold the sales total and the profit • Sales_total = 0.0 • profit = 0.0 • # Step 1: Introduce the program • print ("This program answers Program Exercise #2") • # Step 2: Ask for the amount of projected sales • # Step 3: Record the user’s response for projected sales. • salesTotal = float(input("Enter the projected sales: ")) • # Continued on next slide
Let's Work on Some Programs (7) • # Step 4: Calculate the projected profit. • profit = sales_total * 0.23 • # Step 5: Provide the user with the projected profit. • print ("The projected profit is " , format(profit, '.2f')) • # Step 6: Stop
Let's Work on Some Programs (8) • Textbook, page 77, Programming Exercise #3 • Develop an algorithm
Let's Work on Some Programs (9) • Textbook, page 77, Programming Exercise #3 • Develop an algorithm • # Step 1: Introduce the program • # Step 2: Ask for the amount of square feet of the tract of land. • # Step 3: Record the user’s input for the tract of land. • # Step 4: Calculate the acreage ( tract_size / 43560 ). • # Step 5: Provide the use with the number of acres. • # Step 6: Stop
Let's Work on Some Programs (10) • Textbook, page 77, Programming Exercise #3 • Develop a flow chart
Let's Work on Some Programs (11) • Textbook, page 77, Programming Exercise #3 • Develop a flow chart • http://web.cs.sunyit.edu/~urbanc/cs_100_sep_16_2.pdf
Let's Work on Some Programs (12) • Textbook, page 77, Programming Exercise #3 • Develop source code
Let's Work on Some Programs (13) • # Variables to hold the size of the tract and number of acres. • tract_size = 0.0 • acres = 0.0 • # Step 1: Introduce the program • print ("This program answers Program Exercise #3") • # Step 2: Ask for the square feet in the tract of land. • # Step 3: Record the user’s input for the tract of land. • tract_size = input("Enter the number of square feet in the tract: ")
Let's Work on Some Programs (14) • # Step 4: Calculate the acreage (tract_size / 43560). • acres = float(tract_size) / 43560 • # Step 5: Provide the use with the number of acres. • print ("The size of that tract is" , format(acres , '.2f' ) , "acres.") • # Step 6: Stop
Let's Work on Some Programs (15) • Textbook, page 77, Programming Exercise #4 • Develop an algorithm • Remember: there are only sequential instructions… you cannot use a "loop"
Let's Work on Some Programs (16a) • Textbook, page 77, Programming Exercise #4 • Develop an algorithm • # Step 1: Introduce the program • # Step 2: Ask for the price of the first item • # Step 3: Record the price of the first item • # Step 4: Ask for the price of the second item • # Step 5: Record the price of the second item • # Step 6: Ask for the price of the third item • # Step 7: Record the price of the third item • # Continued on next slide
Let's Work on Some Programs (16b) • Textbook, page 77, Programming Exercise #4 • Develop an algorithm • # Step 8: Ask for the price of the fourth item • # Step 9: Record the price of the fourth item • # Step 10: Ask for the price of the fifth item • # Step 11: Record the price of the fifth item • # Step 12: Calculate the subtotal cost of all 5 items • # Step 13: Calculate the sales tax amount (subtotal * tax rate) • # Step 14: Calculate the total (subtotal + sales tax amount) • # Step 15: Communicate the subtotal, sales tax, and total values • # Step 16: Stop
Let's Work on Some Programs (17) • Textbook, page 77, Programming Exercise #4 • Develop a flow chart
Let's Work on Some Programs (18) • Textbook, page 77, Programming Exercise #4 • Develop a flow chart • http://web.cs.sunyit.edu/~urbanc/cs_100_sep_16_3.pdf
Let's Work on Some Programs (19) • Textbook, page 77, Programming Exercise #4 • Develop source code
Let's Work on Some Programs (20) • Textbook, page 77, Programming Exercise #4 • Develop source code • http://web.cs.sunyit.edu/~urbanc/cs_100_sep_16_c1.html
Let's Work on Some Programs (21) • Textbook, page 77, Programming Exercise #10 • Develop an algorithm
Let's Work on Some Programs (22) • Textbook, page 77, Programming Exercise #10 • Develop an algorithm • # Step 1: Introduce the program • # Step 2: Ask the user for the desired number of cookies • # Step 3: Record the user’s input for the number of cookies • # Step 4: Calculate the cups of sugar needed • # Step 5: Calculate the cups of butter needed • # Step 6: Calculate the cups of flour
Let's Work on Some Programs (23) • Textbook, page 77, Programming Exercise #10 • Develop an algorithm • # Step 7, 8, and 9: Communicate the amount of butter, sugar, • # and flour needed to make the specified number of cookies. • # Step 10: Stop
Let's Work on Some Programs (23) • Textbook, page 77, Programming Exercise #10 • Develop a flow chart
Let's Work on Some Programs (24) • Textbook, page 77, Programming Exercise #10 • Develop a flow chart • http://web.cs.sunyit.edu/~urbanc/cs_100_sep_16_4.pdf
Let's Work on Some Programs (25) • Textbook, page 77, Programming Exercise #4 • Develop source code
Let's Work on Some Programs (26) • Textbook, page 77, Programming Exercise #4 • Develop source code • http://web.cs.sunyit.edu/~urbanc/cs_100_sep_16_c2.html
Thursday: Practice Exam • Chapters 1 and 2 and anything/everything covered in class