Intro to Programming Part of Chapter 5. Algorithms An algorithm is an ordered set of executable steps that defines a terminating process. An algorithm.

Slides:



Advertisements
Similar presentations
Chapter 4 - Control Statements
Advertisements

Credit hours: 4 Contact hours: 50 (30 Theory, 20 Lab) Prerequisite: TB143 Introduction to Personal Computers.
Chapter 5 Loops Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved.
ISP 121 Algorithmsand Computer Programming. Why Know Simple Programming?  You can create powerful macros in Access / Excel / Word / ??? to manipulate.
Introduction to Flowcharting
Objectives In this chapter, you will learn about:
Chapter 6 - Repetition. Introduction u Many applications require certain operations to be carried out more than once. Such situations require repetition.
1 Lecture 14 Chapter 6 Looping Dale/Weems/Headington.
Summary of Loops Programming. COMP102 Prog Fundamentals I: Summary of Loops /Slide 2 Which Loop to Use? l for loop n for calculations that are repeated.
CHAPTER 2 ANALYSIS OF ALGORITHMS Part 2. 2 Running time of Basic operations Basic operations do not depend on the size of input, their running time is.
Intro to Python Paul Martin. History Designed by Guido van Rossum Goal: “Combine remarkable power with very clear syntax” Very popular in science labs.
Lecture Notes 8/30/05 Program Design & Intro to Algorithms.
JavaScript Switch Statement. Switch JavaScript Switch Statement If you have a lot of conditions, you can use a switch statement instead of an if…elseif…
Writing algorithms using the while-statement. Previously discussed Syntax of while-statement:
Bash Shell Scripting 10 Second Guide Common environment variables PATH - Sets the search path for any executable command. Similar to the PATH variable.
C++ Basics CSci 107. A C++ program //include headers; these are modules that include functions that you may use in your //program; we will almost always.
Scripting CBIS BASH Scripting Step 1 – Create the bash file. Usually a good idea to end it in.sh file1.sh Step 2 – Using CHMOD make the bash file.
PRINCIPLES OF PROGRAMMING Revision. A Computer  A useful tool for solving a great variety of problems.  To make a computer do anything (i.e. solve.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 8 - JavaScript: Control Structures I Outline 8.1 Introduction 8.2 Algorithms 8.3 Pseudocode 8.4.
Looping While-continue.
Outlines Chapter 3 –Chapter 3 – Loops & Revision –Loops while do … while – revision 1.
CS107 Introduction to Computer Science Java Basics.
INTRODUCTION TO ALGORITHMS PROGRAMMING. Objectives Give a definition of the term algorithm Describe the various parts of the pseudocode algorithm or algorithm.
While Loops Indefinite Iteration. Last lesson we looked at definite loops using the ‘For’ statement. The while loop keeps going while some condition is.
Chapter 5 Loops.
Controlling Function Behavior Sequence, Selection and Repetition.
Intro to Python Adriane Huber Debbie Bartlett Python Lab #1Python Lab #1 1.
Chapter 4 Loops Write code that prints out the numbers Very often, we want to repeat a (group of) statement(s). In C++, we have 3 major ways of.
Control Structures II Repetition (Loops). Why Is Repetition Needed? How can you solve the following problem: What is the sum of all the numbers from 1.
Chapter 05 (Part III) Control Statements: Part II.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 5: Introduction to C: More Control Flow.
TK 1914 : C++ Programming Control Structures I (Selection)
1 EMT 101 – Engineering Programming Dr. Farzad Ismail School of Aerospace Engineering Universiti Sains Malaysia Nibong Tebal Pulau Pinang Week 2.
Counter-Controlled Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
1 JavaScript: Control Structures. 2 Control Structures Flowcharting JavaScript’s sequence structure.
1. Understand the application of Pseudo Code for programming purposes 2. Be able to write algorithms in Pseudo Code.
Conditional Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
CS 240 – Computer Programming I Lab Kalpa Gunaratna –
Think Possibility 1 Iterative Constructs ITERATION / LOOPS C provides three loop structures: the for-loop, the while-loop, and the do-while-loop. Each.
Copyright © 2012 Pearson Education, Inc. Chapter 5: Loops.
Think First, Code Second Understand the problem Work out step by step procedure for solving the problem (algorithm) top down design and stepwise refinement.
Algorithms JPC and JWD © 2002 McGraw-Hill, Inc. 2 Algorithms 2 An Algorithm is a finite set of precise instructions for performing a computation or for.
Copyright 2006 Addison-Wesley Brief Version of Starting Out with C++ Chapter 5 Looping.
Control Structures WHILE Statement Looping. S E Q C E N U E REPITITION …a step or sequence of steps that are repeated until some condition is satisfied.
Computer Programming Week 1: The Basics of CP 1 st semester 2012 School of Information Technology Website:
Selection Using IF THEN ELSE CASE Introducing Loops.
JavaScript: Control Structures I Outline 1 Introduction 2 Algorithms 3 Pseudocode 4 Control Structures 5 if Selection Structure 6 if/else Selection Structure.
Looping I (while statement). CSCE 1062 Outline  Looping/repetition construct  while statement (section 5.1)
Basic concepts of C++ Presented by Prof. Satyajit De
Introduction to Computer Programming
CHAPTER 4 DECISIONS & LOOPS
Chapter 4 Repetition Statements (loops)
REPETITION CONTROL STRUCTURE
CS161 Introduction to Computer Science
While Statement.
Loops The loop blocks you've used in Scratch can all be recreated in C! Loops allow for the repetition of code until a condition is met. There are three.
Computers & Programming Languages
For -G7 programing language Teacher / Shamsa Hassan Alhassouni.
Algorithms Take a look at the worksheet. What do we already know, and what will we have to learn in this term?
Selection Statements.
Lab5 PROGRAMMING 1 Loop chapter4.
Computer Science Core Concepts
Control Structures Part 1
Note the rights settings.
A LESSON IN LOOPING What is a loop?
Decisions, decisions, decisions
Print the following triangle, using nested loops
C++ Basics CSci 107. A C++ program //include headers; these are modules that include functions that you may use in your //program; we will almost always.
CS 1428 Exam I Review.
Presentation transcript:

Intro to Programming Part of Chapter 5

Algorithms An algorithm is an ordered set of executable steps that defines a terminating process. An algorithm is an ordered set of executable steps that defines a terminating process. Procedure to solve the problem Procedure to solve the problem

Terminology Procedure & Function Procedure & Function Syntax (a programming language standard) Syntax (a programming language standard) BASIC: PRINT “Hello!” BASIC: PRINT “Hello!” C: printf(“Hello!”); C: printf(“Hello!”); C++: cout << “Hello!”; C++: cout << “Hello!”; JAVA: System.out.print(“Hello!”); JAVA: System.out.print(“Hello!”); Variable & Constant Variable & Constant C:int Var = 0; C:int Var = 0; Var = Var++;

Conditional statement & Loop Conditional statement Conditional statement if Condition then Action if Condition then Action

Conditional statement & Loop Loop (Recursice Structure) Loop (Recursice Structure) while Condition do Action while Condition do Action C: while( Var >= 100) C: while( Var >= 100)printf(“TRUE”); For loop (Iterative Structure) For loop (Iterative Structure) for Iterative statement do Action for Iterative statement do Action C:for( Var = 1; Var <= 3; Var ++) C:for( Var = 1; Var <= 3; Var ++)printf(“Hello!”);

Conditional statement & Loop While loop While loop

Conditional statement & Loop For loop For loop

Conditional statement & Loop Select & Case Select & Case BASIC: SELECT CASE Name$ BASIC: SELECT CASE Name$ CASE "Ted" PRINT “Greetings." CASE "Mike" PRINT "Go away!" CASE ELSE PRINT "Hello, "; Name$ END SELECT

Conditional statement & Loop Select & Case Select & Case

Practice 1 Create a program with following specifications. Create a program with following specifications. Specification Specification First prompts the user with First prompts the user with “Do you want to exit? (Y/N)” Exit program only if the input is “Y” otherwise, keep running the prompt message Exit program only if the input is “Y” otherwise, keep running the prompt message “Y” or “y”  Exit the program “Y” or “y”  Exit the program “N” or “n”  Keep looping “N” or “n”  Keep looping

Practice 2 Specification Specification Prompt message “Enter you name: ” Prompt message “Enter you name: ” “EK”  “Hello, instructor EK.”  Exit program “EK”  “Hello, instructor EK.”  Exit program “Peter”  “Want to exit program? (Y/N)” “Peter”  “Want to exit program? (Y/N)” Y  Exit program N  “Whatever, I’m terminating” Exit program Any Names else  “Hello, Name”  Exit program Any Names else  “Hello, Name”  Exit program

Practice 3 Specification Specification Prompt “How many times you want me to write?” Prompt “How many times you want me to write?” Get an input (N) Get an input (N) N has to be more than or equal to 10 N has to be more than or equal to 10 If not  Print “Input has to be >= 10” Prompt the MSG and get new N If yes  Continue

Practice 3 (Cont.) Print Print “1. I will not bully anyone in class again.” “2. I will not bully anyone in class again.” “3. I will not bully anyone in class again.” …… “(N). I will not bully anyone in class again.” Try: Write the new msg on a new line and on the same line