Introduction to Programming

Slides:



Advertisements
Similar presentations
Recipes.
Advertisements

Exercise (1).
Chapter 2 - Problem Solving
Basics of Computer Programming Web Design Section 8-1.
Computer Science 101 Overview of Algorithms. Example: Make Pancakes Prepare batter Beat 2 eggs Add 1 tablespoon of brown sugar Add 1 cup of milk Add 2.
Ingredients 1 1/2 cups sugar 2/3 cup shortening or butter* 2 eggs 2 tablespoons milk 1 teaspoon vanilla extract 3 ¼ cups flour 2 1/2 teaspoons baking.
© 2011 wheresjenny.com BROWNIES SERVINGS: 16 PIECES PREPARATION TIME : ONE HOUR.
Programming Concepts (Part A) Ping Hsu. What is a program? WHITE CAKE RECIPE 1.Preheat oven to 350 degrees F (175 degrees C). 2.Grease and flour a 9x9.
Flowcharts Remember that a solution to a problem is called an algorithm. Algorithms are often a series of steps required to solve the problem. A flowchart.
Math Math Math Why do we study math? First of all, it’s all around us! First of all, it’s all around us!
By: Shaelyn Laurie How To Bake A Cake. Step 1: The Recipe Ingredients 2 cups (500 mL) sugar 4 eggs 2-1/2 cups (625 mL) all-purpose flour 1 cup (250 mL)
HOW TO MAKE A SPONGE CAKE? BY: Group 3 Donnette Yearwood Khadija Winchester Janine John.
Cake Recipe. Ingredients Utensils 1 st Step Pre-Heat oven to 180 degrees Celsius.
Original Source : and Problem and Problem Solving.ppt.
INGREDIENTS Water cream orange blossom water butter salt eggs vanilla sugar flour yolk sugar.
Mary Condes BANANA BREAD RECIPE.  3/4 c sugar  1/2 c margarine (1 stick)  2 eggs  1 1/2 c smashed bananas (4-6)  1 tsp vanilla  1 c shredded bran.
Baking Cookies English Club eats chocolate chip cookies!
RECIPE. NAME: Three chocolates cake. INGREDIENTS 3 cups 1 1/2 tsp 3/4 tsp 1 1/2 tsp 2 2/3 cups 1 cup + 2 Tb 1 cup + 2 Tb 1 cup + 2 Tb 5 large or 4 Jumbo.
Making a pizza First mix flour and water.
End Show Writing a computer program involves performing the following tasks. 1. Understanding the problem 2. Developing an Algorithm for the problem 3.
Following a Recipe The do’s and don’ts!. If you were taking a road trip to some place you had never been to before, what would you want to take with you?
1.02 C Work Plans 1 The secret for success!. Why use a work plan? Helps meal preparation run smoothly Implement these steps: 1.02CWork Plans2 Steps 1-
Algorithms A sequence of instructions 1. Preheat oven to 350 degrees F (175 degrees C). Grease and flour a 9x9 inch pan or line a muffin pan with paper.
How to Bake Brownies Julie Galbraith FVP12. Supplies Needed An Oven A Pan Butter Salt Flour Sugar Cocoa Vanilla Baking Powder Eggs Spoons Measuring Cups.
Snickerdoodles. Ingredients:  125ml margarine  185ml white sugar  1 egg  5ml vanilla extract  340ml all-purpose flour  5ml cream of tartar  2ml.
Made by Jennifer. Today we will be cooking a Roast and for desert are Cupcakes. To start a roast you have to pre-heat you oven to 180 degrees. Make sure.
Practice and Evaluation. Practice Develop a java class called: SumCalculator.java which computes a sum of all integer from 1 to 100 and displays the result.
How to make a BIG sponge cake! By Gina kinsman.. Ingredients! You will need: ½ cup of milk 2 teaspoons & table spoons of unsalted butter 8 large eggs.
Following a Recipe The do’s and don’ts! Original Author Unknown Modified By: CTAE Resource Network.
FROM SCRATCH UTENSILS NEEDED Original recipe makes 1 - 9x13 inch cake 9X13 Dish Pan Large Bowl.
The Apple Pie Meurotte TIME OF PREPARATION :25 min COOKING TIME: 20 min Ingredients: For the tart: _Pastry _500 G apples (Golden) C. _1 a teaspoon of cinnamon.
`. Lecture Overview Structure Programming Basic Control of Structure Programming Selection Logical Operations Iteration Flowchart.
Step by step guide. Preheat the Oven jpg STEP 1.
Pineapple Upside Down Cake Katherine Babbini. Collect all your ingredients.
2 cups Sugar 1/2 cup Butter 1/2 cup Hershey's Cocoa 1 teaspoon Vanilla 1 cup Boiling Folgers Coffee 1/2 cup Buttermilk 2 Eggs 2 cups Flour 1/4 teaspoon.
(12).  4 ounces of self raising flour  4 ounces of sugar  4 ounces of butter  2 eggs  Mixing bowl  Scales  Oven  Cooling rack  whisk.
Apple Crumble By: Branavi N. Step by step instructions on how to make this delicious dessert.
Program Development C# Programming January 30, 2007 Professor J. Sciame.
FACTORS OF PRODUCTION What is it made of??. LEARNING TARGET I can explain the factors of production I can describe the production process I can identify.
Introduction to design and analysis algorithm
How to Make Chocolate Chip Cookies
CS 101 – Oct. 7 Solving simple problems: create algorithm Structure of solution –Sequence of steps (1,2,3….) –Sometimes we need to make a choice –Sometimes.
How to Make Chocolate Chip Cookies Fast, Easy, and Yummy Original Author Unknown Modified By: CTAE Resource Network.
Flow Charts And Pseudo Codes Grade 12. An algorithm is a complete step-by- step procedure for solving a problem or accomplishing a task.
Sour Cream Pound Cake. 2 cups butter, softened 3 cups white sugar 6 eggs 1 teaspoon vanilla extract.
LET’S FINISH - TODAY’S OBJECTIVE: Create an algorithm to direct a human “robot” from one part of the room to another. Create an algorithm to direct a human.
Recipe of chouquettes.
How to Make a Cake Mrs. Janasik.
Following a Recipe The do’s and don’ts! Original Author Unknown
Recipe Notes.
Recipe.
Computer Science Department
Proportional Problems 2 – RECIPES
½ cup butter or margarine ½ cup peanut butter ¾ cup brown sugar
Lecture 2: Static Methods Expressions reading: 1.4 – 2.1
EASTER EGG BREAD „ŠIŠOR”.
CHOCOLATE Method Sugar, vanilla sugar and water are put in a cracker to boil: Cool the syrup with butter to work with it and pour over homogenized powdered.
COVERED BASICS ABOUT ALGORITHMS AND FLOWCHARTS
PROGRAM CONTROL STRUCTURE
Pink Cake.
Introduction to Algorithm – part 1
1.02 M Timetables 1.02M Timetables.
Recipes.
Control Structure Senior Lecturer
PROBLEM SOLVING CSC 111.
Lecture 2: Static Methods Expressions reading: 1.4 – 2.1
Birthday cake BABY MOMO.
Fruit Pizza Day 1 1/3 c. brown sugar 1 & 1/3 c. flour
Mini fruit cakes Ingredients 100g self raising flour 100g caster sugar
Fudgy Chocolate Brownies Recipe
Presentation transcript:

Introduction to Programming Algorithms Andreas Savva

What is an algorithm? An Algorithm is a detailed sequence of simple steps that are needed to solve a problem. It is a step-by-step solution to a problem.

Mathematical Example Problem: What is the value of x in the following equation? 5x – 10 = 30 Algorithm (Solution): Step 1: 5x = 30 + 10 Step 2: 5x = 40 Step 3: x = 40/5 Step 4: x = 8

Making a cake Step 1: Preheat oven to 200 degrees. Step 2: Mix the eggs with the sugar. Step 3: Add the butter, flour, and the rest of the ingredients. Step 4: Stir for 5 minutes. Step 5: Put the mixture into a baking pan and cook it in a 175 degrees for 40 minutes. Step 6: Keep it in the pan for 15 minutes to cool down. Step 7: Serve with vanilla ice-cream.

Algorithms The Problem: How will the robot go to the file folder? Step 1: Move 3 squares and turn right. Step 2: Move 1 square and turn left. Step 3: Move 2 squares and turn left. Step 4: Move 2 squares and turn right. etc. The Problem: How will the robot go to the file folder?

Representation of Algorithms Verbal representation Pseudo-code Flowchart

Verbal representation of Algorithms Example: Write an algorithm to read and calculate the average of three numbers. Algorithm: Step 1: Ask for the first number. Step 2: Ask for the second number. Step 3: Ask for the third number. Step 4: Add the three numbers to find their sum. Step 5: Divide the sum by 3. Step 6: Display the result.

Flowcharts - graphical representation of an algorithm Start – Finish Input – Output Processing Sub-programs (Separate flowchart) Choice Statements (Question, Decision) Comments Flow

Flowchart G R Sum a Average b c Start Read a Read b Read c Sum  a + b + c Average  Sum / 3 Display Average Finish

Structures For the solution of a problem we use three basic structures: Sequential structure Conditional structure Repetitive structure

Example 2 Write an algorithm to read two numbers and display the appropriate message if the two numbers are equal or not. Read a. Read b. If a = b then display that the two numbers are equal. Else display that the two numbers are NOT equal.

Conditional Structure Start Read a Read b FALSE a = b ? TRUE Display: ”The two numbers are not equal” Display: ”The two numbers are equal” Finish

Example 3 Write an algorithm to read two numbers a and b and find the sum of all the numbers between a and b inclusive. i.e. a = 3, b = 7, Sum = 3 + 4 + 5 + 6 + 7 = 25 a = 1, b = 100, Sum = 1 + 2 + 3 + … + 100 = 5,050 Read a, b Sum  0 Counter  a If Counter > b then Goto 8 Sum  Sum + Counter Counter  Counter + 1 Goto 4 Display Sum

Repetitive Structure Start Read a, b Sum  0 i  a i is the Counter i > b ? TRUE FALSE Sum  Sum + i i  i + 1 Display Sum Finish

Exercises Design a flowchart for the following problems: Calculate the weekly salary of an employee, when the employee-name, working-hours, and rate-per-hour are given. If the working-hours exceed 40, the rate-per-hour is double than the normal hour. Given 4 numbers X1, X2, X3, and X4, find and display the smaller one. Given two numbers A and B. Calculate and display the remainder of their division B:A. (Hind: Keep subtracting A from B until you find a smaller number than A. i.e. for the division 20:6 it will be 20 – 6 = 14; 14 – 6 = 8; 8 – 6 = 2; so Remainder = 2).