Download presentation
Presentation is loading. Please wait.
1
Intro to Programming Part of Chapter 5
2
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
3
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++;
4
Conditional statement & Loop Conditional statement Conditional statement if Condition then Action if Condition then Action
5
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!”);
6
Conditional statement & Loop While loop While loop
7
Conditional statement & Loop For loop For loop
8
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
9
Conditional statement & Loop Select & Case Select & Case
10
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
11
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
12
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
13
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
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.