PSEUDOCODE. It is a conventional code to represent an algorithm

Size: px
Start display at page:

Download "PSEUDOCODE. It is a conventional code to represent an algorithm"

Transcription

1

2 PSEUDOCODE It is a conventional code to represent an algorithm

3 PSEUDOCODE It is a conventional code to represent an algorithm

4 PSEUDOCODE NOTATION Refers the syntax used to write an algorithm in pseudocode

5 PSEUDOCODE NOTATION Start an algorithm Algortihm NameOfTheAlgorithm { Finish an algorithm }

6 Data Types Primitives Data Objects Data Integer number int String (collection of chars) String Real number (Floating point) double Character (single alphanumeric symbol) char Boolean data (FALSE/TRUE) boolean

7 Data Types Default values int 0 double 0.0 char boolean FALSE String null Char values should be shown between String values should be shown between

8 Variable Is an abstract field which represent a storage location with a particular name. Physical storage location Abstract Field Is a reference of

9 Variable Different types of data could be stored in variables. Those data could change their value depending of different operations done with them 45 Data stored * 2 90

10 Naming a variable Is convenient to label the storage location with a name: Variable names are letters (A..Z, a..z) combined with decimal digits (0..9) and the underline symbol (_) No length limits No allowable special symbols (#$%&/()[]{}.,;! ) Variable names are case sensitive Variable names are all capitals, for example, CITY Self-documented names

11 Assigning values To store a value in a variable, the assignment operation should be done: Values will be assigned using =, for example: AGE=35 FIRSTNAME_OF_CLIENT= Fernando STATUS=TRUE GENDER= F AREAOFCIRCLE=

12 Assigning values Naming a variable AGE AGE Assigning a value 45 AGE = 45

13 Creating a variable To create the abstract field and the storage location of a variable, a declaration sentence has to be executed. This operation should be done previously to start using the variable Declaration syntax: Assignment operation Data type variable_name = value ; Sentence separator Type of the data to be stored Name of the variable Value to be stored

14 Output information Operation that indicates data is output in an output device: printer, screen, Output syntax: output ( Prompt ); The label is shown in an output device output (variable); The content of the variable is shown an output device output ( Prompt + variable); The label and the content of the variable is shown in an output device output ( Label + variable); + in this context is called concatenation operator, and it means link the label and the variable value

15 Example Problem: Given the value of a temperature in Celsius degrees, calculate the equivalent Fahrenheit degrees value Algorithm TemperaturesConvertion { double CELSIUS=0.0; double FAHRENHEIT=0.0; CELSIUS=37; FAHENHEIT=(9/5)*CELSIUS+32; output (CELSIUS+ C are equivalent to +FAHRENHEIT+ F ); }

16 Input Data Operation that permits to capture data from an input device and stores it in a variable. There are different instructions to input data for every data type. Input syntax: inputstring(string prompt); to get a String value inputint(string prompt); to get an integer value inputdouble(string prompt); to get a double value inputchar(string prompt); to get a char value inputboolean(string prompt); to get a boolean value

17 Example Problem: Given the value of a temperature in Celsius degrees, calculate the equivalent Fahrenheit degrees value Algorithm TemperaturesConvertion { double CELSIUS=0.0; double FAHRENHEIT=0.0; CELSIUS=inputDouble( Type the temperature in Celsius degrees ); FAHENHEIT=(9/5)*CELSIUS+32; output (CELSIUS+ C are equivalent to +FAHRENHEIT+ F ); }

18 Operators Are symbols to establish an arithmetic, logic or relational operations between data Arithmetic Operators: Relational Operators: Logic operators: + - * / % > >= < <= ==!= &&!

19 Arithmetic Operators Operator Computes Syntax Category + the sum of its two operands - subtracts the second operand from the first * the product of its operands / % divides its first operand by its second operand the remainder after dividing its first operand by its second a + b a - b a * b a / b a % b Additive Additive Multiplicative Multiplicative Multiplicative

20 Relational Operators Operator Computes Syntax Category > Greater than a > b Relational >= Greater than or equals to < Less than <= Less than or equals to a >= b a < b a <= b Relational Relational Relational == Equals to a == b Relational!= Is not equal to a!= b Relational

21 Logical Operators Operator Computes Syntax Category && P1 && P2 Are both values TRUE? Logic Is, at least, one value TRUE?! Is the opposite logical value P1 P2!P1 Logic Logic

22 Operators Precedence Category Operator Asociativity Postfix ( ) Left to Right Unary! Right to Left Multiplicative * / % Left to Right Additive + - Left to Right Relational < <= > >= Left to Right Equality ==!= Left to Right Logical AND && Left to Right Logical OR Left to Right Assignment = Right to Left

23 Functions Are pre-designed formulas to execute particular and complex calculations sqrt(value) calculates the square root of a value pow(base,power) calculates the result of an exponential expression xx yy abs(value) calculates the absolute value of a quantity : :

24 Exercise In an University, the final grade of a subject is calculated by the weighted average of three grades. The weights of the grades are given as percentages respectively: 20% to the first grade, 25% to the second grade and 55% to the third one, respectively. Develop an algorithm, in pseudocode, which takes the personal information of any student and calculate the final grade of a subject.

25 Exercise La instalación de criaderos de peces, en una zona rural del Valle del Cauca, exige la compilación de ciertos datos relacionados con los pescados que allí van a sembrarse: la especie, la talla (el largo del pez) y el peso, serán características que en cada criadero se determinarán mediante sensores especiales de tecnología de control. Implementar un algoritmo registre y calcule los datos necesarios para dar una información eficaz de cualquier pez. El factor de densidad lineal es un valor que permite generalizar y calcular el peso, dado solamente el tamaño y que en este caso será 1.75.

26 CONTROL FLOW STATEMENTS Break up the flow of execution by employing decision making, looping, and branching, enabling your program to conditionally execute particular blocks of code

27 CONDITION Is an expression which involves relational and/or logic operators. A boolean value is the result of a condition evaluation Examples: AGE >=35 AREA<23.7 AND SHAPE= CIRCLE Tip: relational operators: > < >= <= == Logic operators: AND OR NOT

28 if then STATEMENT It tells your algorithm to execute a certain section of code only if a particular test, of a condition, evaluates to true Syntax if (condition) then sentences for TRUE value; endif

29 if then STATEMENT Example: A web site has implemented a routine that gives the access to its content only if the user type an appropriate password. Implement an algorithm to solve this situation Algorithm AccessGranted{ String PASSW= AZ123b, PASSUSER=null; PASSUSER=inputString( Type the password ); if (PASSUSER=PASSW) then output( Welcome to the web site ); endif }

30 if then else STATEMENT The if-then-else statement provides a secondary path of execution when an "if" clause evaluates to false Syntax if (condition) then sentences for TRUE value; else sentences for FALSE value; endif

31 if then STATEMENT Example: A web site has implemented a routine that gives the access to its content only if the user type an appropriate password; in other case a pop up window will notices the wrong password. Implement an algorithm to solve this situation Algorithm AccessGranted{ String PASSW= AZ123b, PASSUSER=null; PASSUSER=inputString( Type the password ); if (PASSUSER=PASSW) then output( Welcome to the web site ); else output( Access hasn t be granted!!! ); endif }

32 EXERCISES Problem 1: Write an algorithm that recommends the number of calories a person should eat each day. Calories are units of energy found in all foods. Base your recommendation on the person's weight and whether the person has an active or sedentary (inactive) lifestyle. If the person is sedentary, that person's activity factor is 13. If the person is active, that person's activity factor is 15. Multiply the activity factor by the person's weight to get the recommended number of calories Problem 2: A code program to detect and advertise when a driver exceeds speed limits is required to be burned in a ROM memory and to be installed in a special device which will be used by the highway police. Develop a pseudocode of the algorithm to sketch the real program. Problem 3: Given a natural number, determine if it is an odd or even number Problem 4: Given two natural numbers A and B, determine if B is divisor of A

33 NESTED CONTROL FLOW STATEMENTS Consist of the combination or the link of two or more control flow statements to increase the functional power of an algorithm NESTING IF THEN ELSE STATEMENTS Syntax if (condition1) then sentences for TRUE value of condition 1; else if (condition2) then sentences for TRUE value of condition 2; else if (condition3) then sentences for TRUE value of condition 3; else if.. else sentences for FALSE value all conditions; endif

34 if then STATEMENT Example: Classify a triangle given the three sides length Algorithm Triangles { double SIDEA=0.0, SIDEB=0.0, SIDEC=0.0; SIDEA=inputDouble( Length of side A ); SIDEB=inputDouble( Length of side B ); SIDEC=inputDouble( Length of side C ); if (SIDEA==SIDEB AND SIDEB==SIDEC) then output ( Equilateral triangle ); else if (SIDEA==SIDEB OR SIDEA==SIDEC OR SIDEB==SIDEC) then output ( Isosceles triangle ); else output ( Scalene triangle ); }

35 EXERCISES Problem 1: Write a program to determine the cost of an automobile insurance premium, based on driver's age and the number of accidents that the driver has had. The basic insurance charge is $500. There is a surcharge of $100 if the driver is under 25 and an additional surcharge for accidents: # of accidents Accident Surcharge or more No insurance

36 EXERCISES Problem 2: Windows performs a date format in two ways: a short format which shows the date as mm / dd / yyyy; and a long format mmmm-dd-yyyy September (long format), 9/11/2013 (short format) Implement an algorithm, in pseudocode, that permits to convert a format date from short to long format

37 EXERCISES Problem 3: El personal que acude a un gimnasio deportivo se puede clasificar en socios o en invitados. El gimnasio cobra una tarifa fija por hora (no se cobran fracciones de la hora), pero para los socios hay un descuento del 20 % del valor a pagar. Además, para fomentar el ejercicio físico en adultos mayores, el gimnasio ofrece un descuento adicional del 10% del valor a pagar, a todas las personas con edad de 40 o más años. Desarrollar el algoritmo en pseudocódigo que permita calcular el valor a pagar por la utilización del gimnasio, de una persona cualquiera

38 EXERCISES Problem 4: Given the Cartesian coordinates of a point P (x, y), calculate Polar coordinates of P (r, θ) Given the polar coordinates of a point P (r, θ), calculate Cartesian coordinates of P (x, y) Use the following information

39 FLOW CHART It s a graphic data representation of an algorithm. Symbols: Perform a Task Start End Decision Manual Input Documentt Display

40 Example Start CELSIUS=0.0 FAHRENHEIT=0.0 Problem: Given the value of a temperature in Celsius degrees, calculate the equivalent Fahrenheit degrees value CELSIUS=inputDouble( Type the temperature in Celsius degrees ) Algorithm TemperaturesConvertion { double CELSIUS=0.0; double FAHRENHEIT=0.0; CELSIUS=inputDouble( Type the temperature in Celsius degrees ); FAHENHEIT=(9/5)*CELSIUS+32; output (CELSIUS+ C are equivalent to +FAHRENHEIT+ C ); } FAHENHEIT=(9/5)*CELSIUS+32 output (CELSIUS+ C are equivalent to +FAHRENHEIT+ C ); End

41 while loop STATEMENT The while statement continually executes a block of statements while a particular condition is true Syntax loop while condition statements; end loop Condition NO YES Statements

42 while loop STATEMENT Example: Print the first 5 even numbers out Algorithm Serie1 { int COUNTER=1; loop while COUNTER < 5 output(counter*2+ \n ); COUNTER=COUNTER+1; end loop }

43 while loop STATEMENT Example: Print the first 5 even numbers out Algorithm Serie1 { int COUNTER=1; loop while COUNTER < 5 output(counter*2+ \n ); COUNTER=COUNTER+1; end loop } COUNTER variable is a loop counter A loop counter is a variable that increments or decrements its value with a fixed quantity

44 while loop STATEMENT Example: Print the following series numbers: 300, 250, 200, 150, 100, 50, 0 Algorithm Serie2 { int COUNTER=300; loop while COUNTER > -1 output(counter+ \n ); COUNTER=COUNTER-50; end loop }

45 while loop STATEMENT Example: Determine the final printing of the following algorithm Algorithm Serie1 { int COUNTER=0, NUMBER=0, ACUM=0; loop while COUNTER < 4 NUMBER=inputInt( Type a natural number ); ACUM=ACUM+NUMBER; COUNTER=COUNTER+1; end loop output( The result is +ACUM); }

46 while loop STATEMENT Example: Determine the final printing of the following algorithm Algorithm Serie1 { int COUNTER=0, NUMBER=0, ACUM=0; loop while COUNTER < 4 NUMBER=inputInt( Type a natural number ); ACUM=ACUM+NUMBER; COUNTER=COUNTER+1; end loop output( The result is +ACUM); } ACUM variable is a loop accumulator A loop accumulator is a variable that increments or decrements its value with a variable quantity

47 while loop STATEMENT Loop counter and loop accumulator operators: N++ is equivalent to N=N+1 N-- is equivalent to N=N-1 N+=c is equivalent to N=N+c N-=c is equivalent to N=N-c N*=c is equivalent to N=N*c N/=c is equivalent to N=N/c Loop counter If c is a constant value N is a loop counter If c is a variable value N is a loop accumulator

48 while loop STATEMENT TRACE TABLE is a table used to test an algorithm by tracing the values of its variables during the algorithm flow Variable 1 Variable 2 Variable 3 output value value value value value value value value value value value value

49 while loop STATEMENT Example: Determine the final printing of the following algorithm Algorithm Serie1 { int COUNTER=0, NUMBER=0, ACUM=0; loop while COUNTER < 4 NUMBER=inputInt( Type a natural number ); ACUM=ACUM+NUMBER; COUNTER=COUNTER+1; end loop output( The result is +ACUM); } Trace Table COUNTER NUMBER ACUM OUTPUT Type a natural number Type a natural number Type a natural number Type a natural number 3 The result is 16

50 while loop STATEMENT Exercises: 1. Print a sequence of asterisk characters depending of a given value 2. Read and print values entered by a user until a particular sentinel value is encountered. Do not print the sentinel value. Assume the sentinel value is stored in a constant called SENTINEL. 3. Print the numbers between LOW and HIGH that are evenly divisible by four but not by five. 4. Given a natural number, determine if it is a perfect number 5. Generate the Fibonacci numbers

51 from/to loop STATEMENT Syntax loop counter from counter initial value to counter final value statements; end loop counter declaration statements counter increasing/decreasing Condition (involving the counter) NO YES

52 from/to loop STATEMENT Example: Write and algorithm in pseudocode to calculate the average of the students ages in a certain classroom Algorithm TheAverage { int QUANTITY=0, COUNTER=0, ACUM=0, AGE=0; QUANTITY=inputInt( Type the quantity of students ); loop COUNTER from 1 to QUANTITY AGE=inputInt( Type the age ); ACUM += AGE; end loop output ( The average is +(ACUM/QUANTITY)); }

53 from/to loop STATEMENT Example: Given a quantity of natural numbers, compute the sum of the odd numbers between 1 and the final number Algorithm SumOdd{ int QUANTITY=20, COUNTER=0; acum=0; QUANTITY=inputInt( Type the amount of numbers ); loop COUNTER from 1 to QUANTITY if(counter mod 2 0) then ACUM += NUMBER; end if end loop output ( The sum is +ACUM); }

54 from/to loop STATEMENT Exercises: 1. Given a positive integer number, calculate its factorial 2. Write a program called HarmonicSum to compute the sum of a harmonic series, as shown below, where n= Write a program called ComputePI to compute the value of π, using the following series expansion. You have to decide on the termination criterion used in the computation (such as the number of terms used or the magnitude of an additional term). Is this series suitable for computing π?

55 loop STATEMENTS 4. Write an algorithm in pseudocode to find out if a number is prime 5. Develop the trace table to the following algorithm: Algorithm Special { int N=0,M=0; N=inputInt ( Type a positive integer number ); loop while N>0 N/=10; M++; end loop output ( Value +M); }

56 Approved notation for developing pseudocode c_sup_1201_1b_e.pdf International Baccalaureate Organization 2012 IB Java Examination Tool Subset (JETS) c_sup_1201_1a_e.pdf

Announcements. Lab Friday, 1-2:30 and 3-4:30 in Boot your laptop and start Forte, if you brought your laptop

Announcements. Lab Friday, 1-2:30 and 3-4:30 in Boot your laptop and start Forte, if you brought your laptop Announcements Lab Friday, 1-2:30 and 3-4:30 in 26-152 Boot your laptop and start Forte, if you brought your laptop Create an empty file called Lecture4 and create an empty main() method in a class: 1.00

More information

Fundamentals of Programming (Python) Getting Started with Programming

Fundamentals of Programming (Python) Getting Started with Programming Fundamentals of Programming (Python) Getting Started with Programming Ali Taheri Sharif University of Technology Some slides have been adapted from Python Programming: An Introduction to Computer Science

More information

Computer Programming, I. Laboratory Manual. Experiment #2. Elementary Programming

Computer Programming, I. Laboratory Manual. Experiment #2. Elementary Programming Think Twice Code Once The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2005 Khaleel I. Shaheen Computer Programming, I Laboratory Manual Experiment #2

More information

CS313D: ADVANCED PROGRAMMING LANGUAGE

CS313D: ADVANCED PROGRAMMING LANGUAGE CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science department Lecture 2 : C# Language Basics Lecture Contents 2 The C# language First program Variables and constants Input/output Expressions and casting

More information

Repetition Structures

Repetition Structures Repetition Structures Chapter 5 Fall 2016, CSUS Introduction to Repetition Structures Chapter 5.1 1 Introduction to Repetition Structures A repetition structure causes a statement or set of statements

More information

Condition-Controlled Loop. Condition-Controlled Loop. If Statement. Various Forms. Conditional-Controlled Loop. Loop Caution.

Condition-Controlled Loop. Condition-Controlled Loop. If Statement. Various Forms. Conditional-Controlled Loop. Loop Caution. Repetition Structures Introduction to Repetition Structures Chapter 5 Spring 2016, CSUS Chapter 5.1 Introduction to Repetition Structures The Problems with Duplicate Code A repetition structure causes

More information

Control Statements: Part 1

Control Statements: Part 1 4 Let s all move one place on. Lewis Carroll Control Statements: Part 1 The wheel is come full circle. William Shakespeare How many apples fell on Newton s head before he took the hint! Robert Frost All

More information

Introduction to Java Applications

Introduction to Java Applications 2 Introduction to Java Applications OBJECTIVES In this chapter you will learn: To write simple Java applications. To use input and output statements. Java s primitive types. Basic memory concepts. To use

More information

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence Data and Variables Data Types Expressions Operators Precedence String Concatenation Variables Declaration Assignment Shorthand operators Review class All code in a java file is written in a class public

More information

Eng. Mohammed S. Abdualal

Eng. Mohammed S. Abdualal Islamic University of Gaza Faculty of Engineering Computer Engineering Dept. Computer Programming Lab (ECOM 2114) Created by Eng: Mohammed Alokshiya Modified by Eng: Mohammed Abdualal Lab 3 Selections

More information

Operators & Expressions

Operators & Expressions Operators & Expressions Operator An operator is a symbol used to indicate a specific operation on variables in a program. Example : symbol + is an add operator that adds two data items called operands.

More information

COP 2000 Introduction to Computer Programming Mid-Term Exam Review

COP 2000 Introduction to Computer Programming Mid-Term Exam Review he exam format will be different from the online quizzes. It will be written on the test paper with questions similar to those shown on the following pages. he exam will be closed book, but students can

More information

Unit 3. Operators. School of Science and Technology INTRODUCTION

Unit 3. Operators. School of Science and Technology INTRODUCTION INTRODUCTION Operators Unit 3 In the previous units (unit 1 and 2) you have learned about the basics of computer programming, different data types, constants, keywords and basic structure of a C program.

More information

Chapter 2 Working with Data Types and Operators

Chapter 2 Working with Data Types and Operators JavaScript, Fourth Edition 2-1 Chapter 2 Working with Data Types and Operators At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics

More information

Expressions. Arithmetic expressions. Logical expressions. Assignment expression. n Variables and constants linked with operators

Expressions. Arithmetic expressions. Logical expressions. Assignment expression. n Variables and constants linked with operators Expressions 1 Expressions n Variables and constants linked with operators Arithmetic expressions n Uses arithmetic operators n Can evaluate to any value Logical expressions n Uses relational and logical

More information

TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA

TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA 1 TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson, and instructor materials prepared

More information

3. Java - Language Constructs I

3. Java - Language Constructs I Educational Objectives 3. Java - Language Constructs I Names and Identifiers, Variables, Assignments, Constants, Datatypes, Operations, Evaluation of Expressions, Type Conversions You know the basic blocks

More information

o Counter and sentinel controlled loops o Formatting output o Type casting o Top-down, stepwise refinement

o Counter and sentinel controlled loops o Formatting output o Type casting o Top-down, stepwise refinement Last Time Let s all Repeat Together 10/3/05 CS150 Introduction to Computer Science 1 1 We covered o Counter and sentinel controlled loops o Formatting output Today we will o Type casting o Top-down, stepwise

More information

cs1114 REVIEW of details test closed laptop period

cs1114 REVIEW of details test closed laptop period python details DOES NOT COVER FUNCTIONS!!! This is a sample of some of the things that you are responsible for do not believe that if you know only the things on this test that they will get an A on any

More information

Course Outline. Introduction to java

Course Outline. Introduction to java Course Outline 1. Introduction to OO programming 2. Language Basics Syntax and Semantics 3. Algorithms, stepwise refinements. 4. Quiz/Assignment ( 5. Repetitions (for loops) 6. Writing simple classes 7.

More information

By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program

By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program 1 By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program variables. Apply C++ syntax rules to declare variables, initialize

More information

3. Java - Language Constructs I

3. Java - Language Constructs I Names and Identifiers A program (that is, a class) needs a name public class SudokuSolver {... 3. Java - Language Constructs I Names and Identifiers, Variables, Assignments, Constants, Datatypes, Operations,

More information

BCA-105 C Language What is C? History of C

BCA-105 C Language What is C? History of C C Language What is C? C is a programming language developed at AT & T s Bell Laboratories of USA in 1972. It was designed and written by a man named Dennis Ritchie. C seems so popular is because it is

More information

Unit 1 Lesson 4. Introduction to Control Statements

Unit 1 Lesson 4. Introduction to Control Statements Unit 1 Lesson 4 Introduction to Control Statements Essential Question: How are control loops used to alter the execution flow of a program? Lesson 4: Introduction to Control Statements Objectives: Use

More information

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved. Assoc. Prof. Dr. Marenglen Biba Before writing a program to solve a problem, have a thorough understanding of the problem and a carefully planned approach to solving it. Understand the types of building

More information

COMP Primitive and Class Types. Yi Hong May 14, 2015

COMP Primitive and Class Types. Yi Hong May 14, 2015 COMP 110-001 Primitive and Class Types Yi Hong May 14, 2015 Review What are the two major parts of an object? What is the relationship between class and object? Design a simple class for Student How to

More information

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types

More information

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved. Chapter 2 C++ Basics 1 Overview 2.1 Variables and Assignments 2.2 Input and Output 2.3 Data Types and Expressions 2.4 Simple Flow of Control 2.5 Program Style Slide 2-3 2.1 Variables and Assignments 2

More information

VBScript: Math Functions

VBScript: Math Functions C h a p t e r 3 VBScript: Math Functions In this chapter, you will learn how to use the following VBScript functions to World Class standards: 1. Writing Math Equations in VBScripts 2. Beginning a New

More information

Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 3

Object oriented programming. Instructor: Masoud Asghari Web page:   Ch: 3 Object oriented programming Instructor: Masoud Asghari Web page: http://www.masses.ir/lectures/oops2017sut Ch: 3 1 In this slide We follow: https://docs.oracle.com/javase/tutorial/index.html Trail: Learning

More information

SNS COLLEGE OF ENGINEERING

SNS COLLEGE OF ENGINEERING SNS COLLEGE OF ENGINEERING DEPARTMENT OF CSE Presented By Thillaiarasu.N SCRAMBLE 2 Solution 3 What is Pseudocode? 4 Consists of: Short Readable Formally styled English language Used for: Explaining the

More information

Ex: If you use a program to record sales, you will want to remember data:

Ex: If you use a program to record sales, you will want to remember data: Data Variables Programs need to remember values. Ex: If you use a program to record sales, you will want to remember data: A loaf of bread was sold to Sione Latu on 14/02/19 for T$1.00. Customer Name:

More information

Chapter 5. Repetition. Contents. Introduction. Three Types of Program Control. Two Types of Repetition. Three Syntax Structures for Looping in C++

Chapter 5. Repetition. Contents. Introduction. Three Types of Program Control. Two Types of Repetition. Three Syntax Structures for Looping in C++ Repetition Contents 1 Repetition 1.1 Introduction 1.2 Three Types of Program Control Chapter 5 Introduction 1.3 Two Types of Repetition 1.4 Three Structures for Looping in C++ 1.5 The while Control Structure

More information

Declaration and Memory

Declaration and Memory Declaration and Memory With the declaration int width; the compiler will set aside a 4-byte (32-bit) block of memory (see right) The compiler has a symbol table, which will have an entry such as Identifier

More information

Full file at

Full file at Java Programming, Fifth Edition 2-1 Chapter 2 Using Data within a Program At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics Additional

More information

CEN 414 Java Programming

CEN 414 Java Programming CEN 414 Java Programming Instructor: H. Esin ÜNAL SPRING 2017 Slides are modified from original slides of Y. Daniel Liang WEEK 2 ELEMENTARY PROGRAMMING 2 Computing the Area of a Circle public class ComputeArea

More information

A Look Back at Arithmetic Operators: the Increment and Decrement

A Look Back at Arithmetic Operators: the Increment and Decrement A Look Back at Arithmetic Operators: the Increment and Decrement Spring Semester 2016 Programming and Data Structure 27 Increment (++) and Decrement (--) Both of these are unary operators; they operate

More information

Unit-II Programming and Problem Solving (BE1/4 CSE-2)

Unit-II Programming and Problem Solving (BE1/4 CSE-2) Unit-II Programming and Problem Solving (BE1/4 CSE-2) Problem Solving: Algorithm: It is a part of the plan for the computer program. An algorithm is an effective procedure for solving a problem in a finite

More information

Chapter 2. Elementary Programming

Chapter 2. Elementary Programming Chapter 2 Elementary Programming 1 Objectives To write Java programs to perform simple calculations To obtain input from the console using the Scanner class To use identifiers to name variables, constants,

More information

Fundamentals. Fundamentals. Fundamentals. We build up instructions from three types of materials

Fundamentals. Fundamentals. Fundamentals. We build up instructions from three types of materials Fundamentals We build up instructions from three types of materials Constants Expressions Fundamentals Constants are just that, they are values that don t change as our macros are executing Fundamentals

More information

What we will do today Explain and look at examples of. Programs that examine data. Data types. Topic 4. variables. expressions. assignment statements

What we will do today Explain and look at examples of. Programs that examine data. Data types. Topic 4. variables. expressions. assignment statements Topic 4 Variables Once a programmer has understood the use of variables, he has understood the essence of programming -Edsger Dijkstra What we will do today Explain and look at examples of primitive data

More information

Le L c e t c ur u e e 2 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Variables Operators

Le L c e t c ur u e e 2 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Variables Operators Course Name: Advanced Java Lecture 2 Topics to be covered Variables Operators Variables -Introduction A variables can be considered as a name given to the location in memory where values are stored. One

More information

Chapter 2: Data and Expressions

Chapter 2: Data and Expressions Chapter 2: Data and Expressions CS 121 Department of Computer Science College of Engineering Boise State University January 15, 2015 Chapter 2: Data and Expressions CS 121 1 / 1 Chapter 2 Part 1: Data

More information

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved. Chapter 2 C++ Basics Overview 2.1 Variables and Assignments 2.2 Input and Output 2.3 Data Types and Expressions 2.4 Simple Flow of Control 2.5 Program Style 3 2.1 Variables and Assignments Variables and

More information

Chapter 2. C++ Basics

Chapter 2. C++ Basics Chapter 2 C++ Basics Overview 2.1 Variables and Assignments 2.2 Input and Output 2.3 Data Types and Expressions 2.4 Simple Flow of Control 2.5 Program Style Slide 2-2 2.1 Variables and Assignments Variables

More information

Chapter 3 Problem Solving and the Computer

Chapter 3 Problem Solving and the Computer Chapter 3 Problem Solving and the Computer An algorithm is a step-by-step operations that the CPU must execute in order to solve a problem, or to perform that task. A program is the specification of an

More information

b) Use one of your methods to calculate the area of figure c.

b) Use one of your methods to calculate the area of figure c. Task 9: 1. Look at the polygons below. a) Describe at least three different methods for calculating the areas of these polygons. While each method does not necessarily have to work for all three figures,

More information

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics Java Programming, Sixth Edition 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics Additional Projects Additional

More information

Special Section: Building Your Own Compiler

Special Section: Building Your Own Compiler cshtp6_19_datastructures_compiler.fm Page 1 Tuesday, February 14, 2017 10:31 AM 1 Chapter 19 Special Section: Building Your Own Compiler In Exercises8.31 8.33, we introduced Simpletron Machine Language

More information

Chapter 2: Data and Expressions

Chapter 2: Data and Expressions Chapter 2: Data and Expressions CS 121 Department of Computer Science College of Engineering Boise State University August 21, 2017 Chapter 2: Data and Expressions CS 121 1 / 51 Chapter 1 Terminology Review

More information

Java How to Program, 9/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Java How to Program, 9/e. Copyright by Pearson Education, Inc. All Rights Reserved. Java How to Program, 9/e Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved. Copyright 1992-2012 by Pearson Copyright 1992-2012 by Pearson Before writing a program to solve a problem, have

More information

Chapter 4 Introduction to Control Statements

Chapter 4 Introduction to Control Statements Introduction to Control Statements Fundamentals of Java: AP Computer Science Essentials, 4th Edition 1 Objectives 2 How do you use the increment and decrement operators? What are the standard math methods?

More information

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types and

More information

Programming for Engineers Iteration

Programming for Engineers Iteration Programming for Engineers Iteration ICEN 200 Spring 2018 Prof. Dola Saha 1 Data type conversions Grade average example,-./0 class average = 23450-67 893/0298 Grade and number of students can be integers

More information

Sir Muhammad Naveed. Arslan Ahmed Shaad ( ) Muhammad Bilal ( )

Sir Muhammad Naveed. Arslan Ahmed Shaad ( ) Muhammad Bilal ( ) Sir Muhammad Naveed Arslan Ahmed Shaad (1163135 ) Muhammad Bilal ( 1163122 ) www.techo786.wordpress.com CHAPTER: 2 NOTES:- VARIABLES AND OPERATORS The given Questions can also be attempted as Long Questions.

More information

Chapter 3 Syntax, Errors, and Debugging. Fundamentals of Java

Chapter 3 Syntax, Errors, and Debugging. Fundamentals of Java Chapter 3 Syntax, Errors, and Debugging Objectives Construct and use numeric and string literals. Name and use variables and constants. Create arithmetic expressions. Understand the precedence of different

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

Full file at

Full file at Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class

More information

Section A Arithmetic ( 5) Exercise A

Section A Arithmetic ( 5) Exercise A Section A Arithmetic In the non-calculator section of the examination there might be times when you need to work with quite awkward numbers quickly and accurately. In particular you must be very familiar

More information

Lecture 3 Tao Wang 1

Lecture 3 Tao Wang 1 Lecture 3 Tao Wang 1 Objectives In this chapter, you will learn about: Arithmetic operations Variables and declaration statements Program input using the cin object Common programming errors C++ for Engineers

More information

Java Notes. 10th ICSE. Saravanan Ganesh

Java Notes. 10th ICSE. Saravanan Ganesh Java Notes 10th ICSE Saravanan Ganesh 13 Java Character Set Character set is a set of valid characters that a language can recognise A character represents any letter, digit or any other sign Java uses

More information

Building Java Programs. Chapter 2: Primitive Data and Definite Loops

Building Java Programs. Chapter 2: Primitive Data and Definite Loops Building Java Programs Chapter 2: Primitive Data and Definite Loops Copyright 2008 2006 by Pearson Education 1 Lecture outline data concepts Primitive types: int, double, char (for now) Expressions: operators,

More information

COP 4516: Math for Programming Contest Notes

COP 4516: Math for Programming Contest Notes COP 4516: Math for Programming Contest Notes Euclid's Algorithm Euclid's Algorithm is the efficient way to determine the greatest common divisor between two integers. Given two positive integers a and

More information

Variable and Data Type I

Variable and Data Type I Islamic University Of Gaza Faculty of Engineering Computer Engineering Department Lab 2 Variable and Data Type I Eng. Ibraheem Lubbad September 24, 2016 Variable is reserved a location in memory to store

More information

Looping Subtasks. We will examine some basic algorithms that use the while and if constructs. These subtasks include

Looping Subtasks. We will examine some basic algorithms that use the while and if constructs. These subtasks include 1 Programming in C Looping Subtasks We will examine some basic algorithms that use the while and if constructs. These subtasks include Reading unknown quantity of data Counting things Accumulating (summing)

More information

APS Sixth Grade Math District Benchmark Assessment NM Math Standards Alignment

APS Sixth Grade Math District Benchmark Assessment NM Math Standards Alignment SIXTH GRADE NM STANDARDS Strand: NUMBER AND OPERATIONS Standard: Students will understand numerical concepts and mathematical operations. 5-8 Benchmark N.: Understand numbers, ways of representing numbers,

More information

PROGRAMMING IN C AND C++:

PROGRAMMING IN C AND C++: PROGRAMMING IN C AND C++: Week 1 1. Introductions 2. Using Dos commands, make a directory: C:\users\YearOfJoining\Sectionx\USERNAME\CS101 3. Getting started with Visual C++. 4. Write a program to print

More information

Computer Programming CS F111

Computer Programming CS F111 Computer Programming CS F111 BITS Pilani Dubai Campus NAND KUMAR Basics of C Programming BITS Pilani Dubai Campus Write a program that 1. Asks 5 marks from the user, find the average of the marks and print

More information

Types and Expressions. Chapter 3

Types and Expressions. Chapter 3 Types and Expressions Chapter 3 Chapter Contents 3.1 Introductory Example: Einstein's Equation 3.2 Primitive Types and Reference Types 3.3 Numeric Types and Expressions 3.4 Assignment Expressions 3.5 Java's

More information

CHAPTER 2 PROBLEM SOLVING TECHNIQUES. Mr Mohd Hatta Bin Hj Mohamed Ali Computer Programming BFC2042

CHAPTER 2 PROBLEM SOLVING TECHNIQUES. Mr Mohd Hatta Bin Hj Mohamed Ali Computer Programming BFC2042 CHAPTER 2 PROBLEM SOLVING TECHNIQUES Mr Mohd Hatta Bin Hj Mohamed Ali Computer Programming BFC2042 Software Engineering vs Problem Solving Software Engineering - A branch of Computer Science & provides

More information

C/C++ Programming for Engineers: Working with Integer Variables

C/C++ Programming for Engineers: Working with Integer Variables C/C++ Programming for Engineers: Working with Integer Variables John T. Bell Department of Computer Science University of Illinois, Chicago Preview Every good program should begin with a large comment

More information

Add Subtract Multiply Divide

Add Subtract Multiply Divide ARITHMETIC OPERATORS if AND if/else AND while LOOP Order of Operation (Precedence Part 1) Copyright 2014 Dan McElroy Add Subtract Multiply Divide + Add - Subtract * Multiply / Divide = gives the quotient

More information

Mathematics LV 5 (with QuickTables)

Mathematics LV 5 (with QuickTables) Mathematics LV 5 (with QuickTables) This course covers the topics shown below. Students navigate learning paths based on their level of readiness. Institutional users may customize the scope and sequence

More information

Condition Controlled Loops. Introduction to Programming - Python

Condition Controlled Loops. Introduction to Programming - Python + Condition Controlled Loops Introduction to Programming - Python + Repetition Structures n Programmers commonly find that they need to write code that performs the same task over and over again + Example:

More information

Math Glossary Numbers and Arithmetic

Math Glossary Numbers and Arithmetic Math Glossary Numbers and Arithmetic Version 0.1.1 September 1, 200 Next release: On or before September 0, 200. E-mail edu@ezlink.com for the latest version. Copyright 200 by Brad Jolly All Rights Reserved

More information

DEPARTMENT OF MATHS, MJ COLLEGE

DEPARTMENT OF MATHS, MJ COLLEGE T. Y. B.Sc. Mathematics MTH- 356 (A) : Programming in C Unit 1 : Basic Concepts Syllabus : Introduction, Character set, C token, Keywords, Constants, Variables, Data types, Symbolic constants, Over flow,

More information

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators JAVA Standard Edition Java - Basic Operators Java provides a rich set of operators to manipulate variables.

More information

Object Oriented Programming with Java

Object Oriented Programming with Java Object Oriented Programming with Java What is Object Oriented Programming? Object Oriented Programming consists of creating outline structures that are easily reused over and over again. There are four

More information

The Arithmetic Operators. Unary Operators. Relational Operators. Examples of use of ++ and

The Arithmetic Operators. Unary Operators. Relational Operators. Examples of use of ++ and The Arithmetic Operators The arithmetic operators refer to the standard mathematical operators: addition, subtraction, multiplication, division and modulus. Op. Use Description + x + y adds x and y x y

More information

The Arithmetic Operators

The Arithmetic Operators The Arithmetic Operators The arithmetic operators refer to the standard mathematical operators: addition, subtraction, multiplication, division and modulus. Examples: Op. Use Description + x + y adds x

More information

Intro to Computational Programming in C Engineering For Kids!

Intro to Computational Programming in C Engineering For Kids! CONTROL STRUCTURES CONDITIONAL EXPRESSIONS Take the construction like this: Simple example: if (conditional expression) statement(s) we do if the condition is true statement(s) we do if the condition is

More information

19 Much that I bound, I could not free; Much that I freed returned to me. Lee Wilson Dodd

19 Much that I bound, I could not free; Much that I freed returned to me. Lee Wilson Dodd 19 Much that I bound, I could not free; Much that I freed returned to me. Lee Wilson Dodd Will you walk a little faster? said a whiting to a snail, There s a porpoise close behind us, and he s treading

More information

STUDENT OUTLINE. Lesson 8: Structured Programming, Control Structures, if-else Statements, Pseudocode

STUDENT OUTLINE. Lesson 8: Structured Programming, Control Structures, if-else Statements, Pseudocode STUDENT OUTLINE Lesson 8: Structured Programming, Control Structures, if- Statements, Pseudocode INTRODUCTION: This lesson is the first of four covering the standard control structures of a high-level

More information

Building Java Programs

Building Java Programs Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading: 2.1-2.2 1 2 Data and expressions reading: 2.1 3 The computer s view Internally, computers store everything as 1 s and 0

More information

More Things We Can Do With It! Overview. Circle Calculations. πr 2. π = More operators and expression types More statements

More Things We Can Do With It! Overview. Circle Calculations. πr 2. π = More operators and expression types More statements More Things We Can Do With It! More operators and expression types More s 11 October 2007 Ariel Shamir 1 Overview Variables and declaration More operators and expressions String type and getting input

More information

ENGR 101 Engineering Design Workshop

ENGR 101 Engineering Design Workshop ENGR 101 Engineering Design Workshop Lecture 2: Variables, Statements/Expressions, if-else Edgardo Molina City College of New York Literals, Variables, Data Types, Statements and Expressions Python as

More information

Control Statements. Musa M. Ameen Computer Engineering Dept.

Control Statements. Musa M. Ameen Computer Engineering Dept. 2 Control Statements Musa M. Ameen Computer Engineering Dept. 1 OBJECTIVES In this chapter you will learn: To use basic problem-solving techniques. To develop algorithms through the process of topdown,

More information

Variable and Data Type I

Variable and Data Type I The Islamic University of Gaza Faculty of Engineering Dept. of Computer Engineering Intro. To Computers (LNGG 1003) Lab 2 Variable and Data Type I Eng. Ibraheem Lubbad February 18, 2017 Variable is reserved

More information

Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur

Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur Operators and Expressions 8/24/2012 Dept of CS&E 2 Arithmetic operators Relational operators Logical operators

More information

Loops / Repetition Statements

Loops / Repetition Statements Loops / Repetition Statements Repetition statements allow us to execute a statement multiple times Often they are referred to as loops C has three kinds of repetition statements: the while loop the for

More information

Chapter 4: Basic C Operators

Chapter 4: Basic C Operators Chapter 4: Basic C Operators In this chapter, you will learn about: Arithmetic operators Unary operators Binary operators Assignment operators Equalities and relational operators Logical operators Conditional

More information

Scheme of work Cambridge International AS & A Level Computing (9691)

Scheme of work Cambridge International AS & A Level Computing (9691) Scheme of work Cambridge International AS & A Level Computing (9691) Unit 2: Practical programming techniques Recommended prior knowledge Students beginning this course are not expected to have studied

More information

Review for Test 1 (Chapter 1-5)

Review for Test 1 (Chapter 1-5) Review for Test 1 (Chapter 1-5) 1. Introduction to Computers, Programs, and Java a) What is a computer? b) What is a computer program? c) A bit is a binary digit 0 or 1. A byte is a sequence of 8 bits.

More information

REPETITION CONTROL STRUCTURE LOGO

REPETITION CONTROL STRUCTURE LOGO CSC 128: FUNDAMENTALS OF COMPUTER PROBLEM SOLVING REPETITION CONTROL STRUCTURE 1 Contents 1 Introduction 2 for loop 3 while loop 4 do while loop 2 Introduction It is used when a statement or a block of

More information

ECE 122 Engineering Problem Solving with Java

ECE 122 Engineering Problem Solving with Java ECE 122 Engineering Problem Solving with Java Lecture 3 Expression Evaluation and Program Interaction Outline Problem: How do I input data and use it in complicated expressions Creating complicated expressions

More information

Chapter 2: Data and Expressions

Chapter 2: Data and Expressions Chapter 2: Data and Expressions CS 121 Department of Computer Science College of Engineering Boise State University April 21, 2015 Chapter 2: Data and Expressions CS 121 1 / 53 Chapter 2 Part 1: Data Types

More information

Chapter 2 ELEMENTARY PROGRAMMING

Chapter 2 ELEMENTARY PROGRAMMING Chapter 2 ELEMENTARY PROGRAMMING Lecture notes for computer programming 1 Faculty of Engineering and Information Technology Prepared by: Iyad Albayouk ١ Objectives To write Java programs to perform simple

More information

Information Science 1

Information Science 1 Topics covered Information Science 1 Terms and concepts from Week 8 Simple calculations Documenting programs Simple Calcula,ons Expressions Arithmetic operators and arithmetic operator precedence Mixed-type

More information

Operators. Java operators are classified into three categories:

Operators. Java operators are classified into three categories: Operators Operators are symbols that perform arithmetic and logical operations on operands and provide a meaningful result. Operands are data values (variables or constants) which are involved in operations.

More information

In this chapter you ll learn:

In this chapter you ll learn: Much that I bound, I could not free; Much that I freed returned to me. Lee Wilson Dodd Will you walk a little faster? said a whiting to a snail, There s a porpoise close behind us, and he s treading on

More information