Computer Science Department FTSM Algorithm Knowledge: Understand algorithm representation using flowchart and pseudocode Skill: Map problem to solution.

Slides:



Advertisements
Similar presentations
TWO STEP EQUATIONS 1. SOLVE FOR X 2. DO THE ADDITION STEP FIRST
Advertisements

Chapter 4 Loops Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved
4 Control Statements: Part 1.
© 2008 Pearson Addison Wesley. All rights reserved Chapter Seven Costs.
Copyright © 2003 Pearson Education, Inc. Slide 1 Computer Systems Organization & Architecture Chapters 8-12 John D. Carpinelli.
Copyright © 2003 Pearson Education, Inc. Slide 1.
Chapter 1 The Study of Body Function Image PowerPoint
Copyright © 2011, Elsevier Inc. All rights reserved. Chapter 6 Author: Julia Richards and R. Scott Hawley.
Author: Julia Richards and R. Scott Hawley
1 Copyright © 2013 Elsevier Inc. All rights reserved. Appendix 01.
Writing Pseudocode And Making a Flow Chart A Number Guessing Game
© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 5: Repetition and Loop Statements Problem Solving & Program.
© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 11: Structure and Union Types Problem Solving & Program Design.
Chapter 3: Top-Down Design with Functions Problem Solving & Program Design in C Sixth Edition By Jeri R. Hanly & Elliot B. Koffman.
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Exit a Customer Chapter 8. Exit a Customer 8-2 Objectives Perform exit summary process consisting of the following steps: Review service records Close.
FACTORING ax2 + bx + c Think “unfoil” Work down, Show all steps.
Year 6 mental test 5 second questions
Year 6 mental test 10 second questions
Excel Functions. Part 1. Introduction 2 An Excel function is a formula or a procedure that is performed in the Visual Basic environment, outside the.
Solve Multi-step Equations
REVIEW: Arthropod ID. 1. Name the subphylum. 2. Name the subphylum. 3. Name the order.
Computer Science Department Introduction To Computers and Programming Knowledge: Understand the concepts of computer, hardware, software and programming.
Chapter 17 Linked Lists.
ABC Technology Project
1 University of Utah – School of Computing Computer Science 1021 "Thinking Like a Computer"
2 |SharePoint Saturday New York City
1 What is JavaScript? JavaScript was designed to add interactivity to HTML pages JavaScript is a scripting language A scripting language is a lightweight.
VOORBLAD.
Factor P 16 8(8-5ab) 4(d² + 4) 3rs(2r – s) 15cd(1 + 2cd) 8(4a² + 3b²)
Basel-ICU-Journal Challenge18/20/ Basel-ICU-Journal Challenge8/20/2014.
1..
© 2012 National Heart Foundation of Australia. Slide 2.
Science as a Process Chapter 1 Section 2.
Understanding Generalist Practice, 5e, Kirst-Ashman/Hull
CS101: Introduction to Computer programming
CS 240 Computer Programming 1
Model and Relationships 6 M 1 M M M M M M M M M M M M M M M M
25 seconds left…...
Systems Development and Documentation Techniques
H to shape fully developed personality to shape fully developed personality for successful application in life for successful.
Januar MDMDFSSMDMDFSSS
Chapter 10: The Traditional Approach to Design
Analyzing Genes and Genomes
Systems Analysis and Design in a Changing World, Fifth Edition
Types of selection structures
We will resume in: 25 Minutes.
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
Essential Cell Biology
Intracellular Compartments and Transport
PSSA Preparation.
Essential Cell Biology
1 Chapter 13 Nuclear Magnetic Resonance Spectroscopy.
Immunobiology: The Immune System in Health & Disease Sixth Edition
Energy Generation in Mitochondria and Chlorplasts
Computer Science Department
User Defined Functions Lesson 1 CS1313 Fall User Defined Functions 1 Outline 1.User Defined Functions 1 Outline 2.Standard Library Not Enough #1.
Control Structure: Loop (Part 1) Knowledge: Understand the various concepts of loop control structure Skill: Be able to develop a program involving loop.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 3 Loops.
Introduction to Programming
Algorithms and Problem Solving
Original Source : and Problem and Problem Solving.ppt.
Computer Science Department
Presentation transcript:

Computer Science Department FTSM Algorithm Knowledge: Understand algorithm representation using flowchart and pseudocode Skill: Map problem to solution in flowchart and pseudocode forms

TK1913-C Programming2 TK1913-C Programming 2 Consider the following …. Problem: Baking a Cake How to solve: 1. Start 2. Preheat the oven at 180 o C 3. Prepare a baking pan 4. Beat butter with sugar 5. Mix them with flour, eggs and essence vanilla 6. Pour the dough into the baking pan 7. Put the pan into the oven 8. End Algorithm in Real Life

TK1913-C Programming3 TK1913-C Programming 3 Divide and Conquer Strategy in Algorithm Problem: Prepare a Breakfast 1.Start 2.Prepare a Breakfast 3.End

TK1913-C Programming4 TK1913-C Programming 4 1. Start 2. Prepare a Breakfast 2.1 Prepare a tuna sandwich 2.2 Prepare some chips 2.3 Make a cup of coffee 3. End Divide and Conquer Strategy in Algorithm

TK1913-C Programming5 TK1913-C Programming 5 1. Start 2. Prepare a Breakfast 2.1 Prepare a tuna sandwich Take 2 slices of bread Prepare tuna paste 2.2 Prepare some chips 2.3 Make a cup of coffee 3. End Divide and Conquer Strategy in Algorithm

TK1913-C Programming6 TK1913-C Programming 6 1. Start 2. Prepare a Breakfast 2.1 Prepare a tuna sandwich Take 2 slices of bread Prepare tuna paste 2.2 Prepare some chips Cut potatoes into slices Fry the potatoes 2.3 Make a cup of coffee 3. End Divide and Conquer Strategy in Algorithm

TK1913-C Programming7 TK1913-C Programming 7 1. Start 2. Prepare a Breakfast 2.1. Prepare a tuna sandwich Take 2 slices of bread Prepare tuna paste 2.2. Prepare some chips Cut potatoes into slices Fry the potatoes 2.3. Make a cup of coffee Boil water Add water with sugar and coffee 3. End Divide and Conquer Strategy in Algorithm

TK1913-C Programming8 TK1913-C Programming 8 What is the connection between these real life processes and algorithm? Something to ponder …

TK1913-C Programming9 TK1913-C Programming 9 A specific and step-by-step set of instructions for carrying out a procedure or solving a problem, usually with the requirement that the procedure terminate at some point 2 types of algorithm representation will be explained: Flowchart Pseudocode Structured Method (will be explained later) A method of designing problem solution Algorithm

TK1913-C Programming10 TK1913-C Programming 10 Flowchart represents algorithm graphically. It is intended for communication and documentation Flowchart

TK1913-C Programming11 TK1913-C Programming 11 Flowchart – Basic Syntax Start/EndSymbolSemantic Process Input/Output Test Connector Flow of activities

TK1913-C Programming12 TK1913-C Programming 12 Flowchart – Other Syntax Function callSymbolSemantic Magnetic Disc Stored Data Document/File Multiple Document/File

TK1913-C Programming13 TK1913-C Programming 13 Are the steps in the algorithm discussed earlier specific enough to be executed by computer? Something to ponder …

TK1913-C Programming14 TK1913-C Programming 14 Problem Solving Process Input Process Output

TK1913-C Programming15 TK1913-C Programming 15 Example 1 Calculate and display the price of a number of apples if the quantity in kg and price per kg are given. Quantity Price_per_kg Price_per_kgPrice Price = Quantity * Price_per_kg Input Process Output

TK1913-C Programming16 TK1913-C Programming 16 Flowchart: Calculate Price of Apples InputQuantity Start Price Quantity * Price_per_kg InputPrice_per_kg OutputPrice End

TK1913-C Programming17 TK1913-C Programming 17 void main() { scanf(%d,&quantity); scanf(%d,&price_per_kg); price = quantity*price_per_kg; printf(%d, price); } InputQuantity Start Price Quantity * Price_per_kg InputPrice_per_kg OutputPrice End C Program: Calculate Price of Apples

TK1913-C Programming18 TK1913-C Programming 18 void main() { scanf(%d,&quantity); scanf(%d,&price_per_kg); price = quantity*price_per_kg; printf(%d, price); } C Program: Calculate Price of Apples Its not complete! Declare the variables…

TK1913-C Programming19 TK1913-C Programming 19 void main() { int quantity, price_per_kg, price; scanf(%d,&quantity); scanf(%d,&price_per_kg); price = quantity*price_per_kg; printf(%d, price); } Well done ! But…what are they? C Program: Calculate Price of Apples

TK1913-C Programming20 TK1913-C Programming 20 void main() { int quantity, price_per_kg, price; scanf(%d,&quantity); scanf(%d,&price_per_kg); price = quantity*price_per_kg; printf(%d, price); }Start Declaration }Input Process Output End C Program: Calculate Price of Apples

TK1913-C Programming21 TK1913-C Programming 21 Chapter 4 } Chapter 5 Chapter 6 Chapter 5 C Program: Calculate Price of Apples void main() { int quantity, price_per_kg, price; scanf(%d,&quantity); scanf(%d,&price_per_kg); price = quantity*price_per_kg; printf(%d, price); }

TK1913-C Programming22 TK1913-C Programming 22 Example 2 A car park has the following charges: The 1 st hour costs RM2.00. The subsequent hours cost RM1.00 per hour. Write an algorithm based on a vehicles entry and exit time. Entry_time Exit_time Exit_time Charge???? Input Process Output

TK1913-C Programming23 TK1913-C Programming 23 Flowchart: Calculate Car Park Charge Input Entry_time Input Exit_time Start OutputCharge End Period Exit_time – Entry_time Period > 1? Yes Charge 2 + (Period * 1) Charge 2 No

TK1913-C Programming24 TK1913-C Programming 24 scanf(%d%d,&entry_time,&exit_time); period = exit_time – entry_time; Input Entry_time Input Exit_time Start OutputCharge End Period Exit_time – Entry_time Period > 1? Yes Charge 2 + (Period * 1) Charge 2 No if (period > 1) charge = 2 + ( period *1); else charge = 2; printf(%d,charge); Flowchart: Calculate Car Park Charge

TK1913-C Programming25 TK1913-C Programming 25 void main() { int entry_time, exit_time, period, charge; scanf(%d%d,&entry_time,&exit_time); period = exit_time – entry_time; if (period > 1) charge = 2 + (period * 1); else charge = 2; printf(%d,charge); } } Chapter 7 C Program: Calculate Car Park Charge

TK1913-C Programming26 TK1913-C Programming 26 Write a program to calculate the average mark of three TK1913s students. Example 3 Mark A Mark B Mark B Mark C Mark C Average_mark???? Input Process Output THINK!!

TK1913-C Programming27 TK1913-C Programming 27 Identify the input and output of the problem. If necessary, use Divide & Conquer strategy to decompose the problem into smaller and manageable sub problems. Decompose the problem until all the sub problems can be solved to get the required results For each sub problem, identify and list out the steps involved in solving it Algorithm Development Guidelines

TK1913-C Programming28 TK1913-C Programming 28 What might be the disadvantage of flowchart? Something to ponder …

TK1913-C Programming29 TK1913-C Programming 29 An outline of a program, written in a form that can easily be converted into real programming statements. It resembles the actual program that will be implemented later. However, it cannot be compiled nor executed. Pseudocode normally codes the following actions: Initialisation of variables Assignment of values to the variables Arithmetic operations Relational operations Pseudocode

TK1913-C Programming30 TK1913-C Programming Start quantity 2. Read quantity price_per_kg 3. Read price_per_kg 4. pricequantityprice_per_kg 4. price quantity * price_per_kg price 5. Print price 6. End Example of Pseudocode

TK1913-C Programming31 TK1913-C Programming 31 Guidelines on Writing Pseudocode Refer to the handouts in your manual …. OK??

TK1913-C Programming32 TK1913-C Programming 32 CFlow Demonstration

TK1913-C Programming33 TK1913-C Programming 33 End of Lecture 2 Yes !! Thats all? Whats next??? INTRODUCTION TO C on the way …