1 Statements and Expressions

Size: px
Start display at page:

Download "1 Statements and Expressions"

Transcription

1 ME 5241 Computer Aided Engineering Tom Chase Fall 2000 PSEUDO-CODE Pseudo-code is used to refine the logic of functions to its simplest possible form before writing the logic in any specific programming language. Pseudo-code encourages you to simplify logic by restricting you to only three action constructs: if-then, if-then-, and for. Functions developed using pseudo-code are generally simpler, more reliable, easier to read, and easier to maintain than functions developed without it. Therefore, investing in the extra step of writing a preliminary draft of a function in pseudo-code is likely to reduce your overall development time. The pseudo-code that we will use in this class 1 is defined below. Our pseudo-code is loosely based on the C or C++ programming language. We will introduce its usage with simple examples. Since our pseudo-code has only three action constructs, learning it requires little study. First, formats for statements and expressions used in the three basic action constructs are defined. Then, two of the three basic action constructs, if-then and if-then-, are presented. The convention for delineating functions in pseudo-code is described next. The third action construct, for, is then defined, with clarification of how to set up for statements to do iterative computations. This document ends by noting a tempting go to construct from the early days of FORTRAN that should never be used today. 1 Statements and Expressions 1.1 Simple Statements x = 3.0 call mat_mult y = sin( deg * PI / ) write( ymin, cupcrv( ymin ), ymax, cupcrv( ymax ) ) Note 1: Calling arguments of functions need not be listed in pseudo-code if an input-output chart for the function is attached. Note 2: Read and write statements should simply indicate variables that are read into or printed from the program; formats are not required in the pseudo-code. 1 No specific format for pseudo-code has been adopted as a standard. The literature presents a wide variety of rules and definitions ranging from very lenient to very constrained. The pseudo-code used in this class is relatively constrained. 1

2 1.2 Compound Statements Compound statements are needed when more than one operation must be performed as one condition of an if statement or one iteration in a for statement. The compound statement consists of multiple simple and/or compound statements delimited by opening and closing brackets (, ): xmxob = x - xob ymyob = y - yob c1 = xmxob * cos( gamma ) + ymyob * sin( gamma ) 1.3 Expression An expression is a statement whose result is a logical type. In C and C++, a logical is typically represented as a simple integer taking the value of 1 ( TRUE ) or 0 ( FALSE ). FORTRAN supports an intrinsic LOGICAL parameter type. i >= j x < 0.0 iok (Note that iok is assumed to be a logical variable in the last example.) 2 Conditional Statements 2.1 if-then if expression then statement if iok then if ( ( cupcrv( ymin) * cupcrv( ymax ) ) > 0.0 ) then write( ymin, cupcrv( ymin ), ymax, cupcrv( ymax ) ) iok = 0 Note that the statement to be performed if iok is TRUE is a simple statement, which happens to be another if statement. However, the statement performed if the second expression is TRUE is a compound statement. 2

3 Example C translation: if ( iok ) if ( cupcrv( ymin ) * cupcrv( ymax ) > 0.0 ) printf( "%lf %lf %lf %lf\n", ymin, cupcrv( ymin ), ymax, cupcrv( ymax ) ); iok = 0; Example FORTRAN translation: if ( iok ) then if ( cupcrv( ymin ) * cupcrv( ymax ).GT.0.0 ) then write( 6, 100 ) ymin, cupcrv( ymin ), $ ymax, cupcrv( ymax ) iok =.FALSE. endif endif 2.2 if-then- if expression then statement statement if iok then call results write( error message ) call lnkdes Example C translation: if iok results( ans ); printf( "Warning: Error!\n" ); lnkdes(); 3

4 Example FORTRAN translation: if ( iok ) then call results( ans ) write( 6, 200 ) call lnkdes() endif 3 Program and Function Delineation The executable statements of a function are delineated by opening and closing brackets (similar to a compound statement): function func1 (simple or compound statement) function message write( "this is a message" ) Example C translation: void message printf( " this is a message\n" ); Example FORTRAN translation: subroutine message() write( 6, 20 ) 20 format( this is a message ) end Note: Calling arguments for functions are not shown in the pseudo-code, as they are presumed to be defined on an associated input-output chart for the function. 4

5 4 Repetitive Statments 4.1 for for (integer parameter) = (integer or integer parameter) to/downto (integer or integer parameter) do statement for row = 1 to nrow do for col = 1 to ncol do write( matrix( nrow, ncol ) ) Example C translation: for ( row = 0; row < nrow; row++ ) for ( col = 0; col < ncol; col++ ) printf( "%10.5lf", matrix[ row ][ col ] ); printf( "\n" ); Example FORTRAN translation: do row = 1, nrow write( 6, 30 ) ( matrix( row, col ), col = 1, ncol ) enddo 4.2 Using for Statements to Avoid Infinite Loops While and repeat statements are not included as recommended pseudo-code constructs, since their usage may lead to infinite loops. Instead, I recommend that you construct all loops using for statements. The only justifiable exception to this rule is event-driven loops, which will not be necessary in the projects assigned in this class. 4.3 Implementing Iterative Computations Iterative computations should be implemented by writing a function containing nothing but the iterative computation in a for loop. The upper limit for the loop should be set as a maximum sensible number of iterations. Convergence is checked within the loop. If convergence is achieved before completion of the loop, the loop and function are terminated simultaneously with a return statement within the loop. If the loop completes without converging, an informative error message is printed. Please note that writing an iterative loop using a while or repeat statement is not allowed in this class. We ask that you use the for loop construct instead because it yields more robust code. Specifically, a user can accidently specify unrealistic convergence criteria 5

6 that will send a while or repeat loop into an infinite loop. If the iteration is done using a for loop instead, the loop is guaranteed to stop in a finite number of attempts in the case that convergence doesn t occur. As an example, consider a function written to ensure that an angle, measured in degrees, is between 0 and 360 deg. The input-output chart for the function is: arbitrary input angle (angin) angchk output angle in range 0 to 360 deg (angout) The pseudo-code to implement this function might appear as follows: function angchk angout = angin for i = 1 to 5 do if ( angout >= ) then angout = angout if ( angout < 0.0 ) then angout = angout return write( "error: input angle out of conversion range" ) Note that this function will successfully convert any angle between deg to deg to an equivalent angle between 0 and 360 deg. If the input angle is outside this range, the function prints an informative error message and terminates. The for loop prevents iterating more than 5 times in attempting to convert a nonsensical angle to the desired range. 5 A Note on GO TO Statements The following GO TO construct is not permitted in this class: 100 continue angle = angle if ( angle.ge ) go to 100 This construct is disallowed because: 1. Such constructs readily lead to infinite loops. 2. The construct is not obvious as a loop; i.e., it is difficult to read. 6

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

Theory of control structures

Theory of control structures Theory of control structures Paper written by Bohm and Jacopini in 1966 proposed that all programs can be written using 3 types of control structures. Theory of control structures sequential structures

More information

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University 9/5/6 CS Introduction to Computing II Wayne Snyder Department Boston University Today: Arrays (D and D) Methods Program structure Fields vs local variables Next time: Program structure continued: Classes

More information

Control Structures. CIS 118 Intro to LINUX

Control Structures. CIS 118 Intro to LINUX Control Structures CIS 118 Intro to LINUX Basic Control Structures TEST The test utility, has many formats for evaluating expressions. For example, when given three arguments, will return the value true

More information

Programming for Electrical and Computer Engineers. Pointers and Arrays

Programming for Electrical and Computer Engineers. Pointers and Arrays Programming for Electrical and Computer Engineers Pointers and Arrays Dr. D. J. Jackson Lecture 12-1 Introduction C allows us to perform arithmetic addition and subtraction on pointers to array elements.

More information

Stat 579: Objects in R Vectors

Stat 579: Objects in R Vectors Stat 579: Objects in R Vectors Ranjan Maitra 2220 Snedecor Hall Department of Statistics Iowa State University. Phone: 515-294-7757 maitra@iastate.edu, 1/23 Logical Vectors I R allows manipulation of logical

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 (C) 2010 Pearson Education, Inc. All for repetition statement do while repetition statement switch multiple-selection statement break statement continue statement Logical

More information

Program Development (SAS IML)

Program Development (SAS IML) Program Development (SAS IML) τρ 1 Review SAS IML Functions for generating matrix BLOCK Function I Function J Function REPEAT Function SHAPE Function 2 BLOCK Forms block-diagonal matrices The BLOCK function

More information

Integer Representation. Variables. Real Representation. Integer Overflow/Underflow

Integer Representation. Variables. Real Representation. Integer Overflow/Underflow Variables Integer Representation Variables are used to store a value. The value a variable holds may change over its lifetime. At any point in time a variable stores one value (except quantum computers!)

More information

Introduction to Visual Basic and Visual C++ Arithmetic Expression. Arithmetic Expression. Using Arithmetic Expression. Lesson 4.

Introduction to Visual Basic and Visual C++ Arithmetic Expression. Arithmetic Expression. Using Arithmetic Expression. Lesson 4. Introduction to Visual Basic and Visual C++ Arithmetic Expression Lesson 4 Calculation I154-1-A A @ Peter Lo 2010 1 I154-1-A A @ Peter Lo 2010 2 Arithmetic Expression Using Arithmetic Expression Calculations

More information

Fortran 90 Two Commonly Used Statements

Fortran 90 Two Commonly Used Statements Fortran 90 Two Commonly Used Statements 1. DO Loops (Compiled primarily from Hahn [1994]) Lab 6B BSYSE 512 Research and Teaching Methods The DO loop (or its equivalent) is one of the most powerful statements

More information

n Group of statements that are executed repeatedly while some condition remains true

n Group of statements that are executed repeatedly while some condition remains true Looping 1 Loops n Group of statements that are executed repeatedly while some condition remains true n Each execution of the group of statements is called an iteration of the loop 2 Example counter 1,

More information

1 Introduction to MATLAB

1 Introduction to MATLAB 1 Introduction to MATLAB 1.1 Quick Overview This chapter is not intended to be a comprehensive manual of MATLAB R. Our sole aim is to provide sufficient information to give you a good start. If you are

More information

LECTURE 0: Introduction and Background

LECTURE 0: Introduction and Background 1 LECTURE 0: Introduction and Background September 10, 2012 1 Computational science The role of computational science has become increasingly significant during the last few decades. It has become the

More information

13. Section 9 Exercises

13. Section 9 Exercises 13 Section 9 Exercises Exercise 9-1: The matrix m is an array of 4 arrays, each with 6 members If m is regarded as a 2- dimensional array, then m[1][2] is m[2][5] is m[4][1] is m[3] is 73 Program Memory

More information

Fundamentals of Programming Session 13

Fundamentals of Programming Session 13 Fundamentals of Programming Session 13 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2014 These slides have been created using Deitel s slides Sharif University of Technology Outlines

More information

Chapter 5 Control Statements: Part 2 Section 5.2 Essentials of Counter-Controlled Repetition

Chapter 5 Control Statements: Part 2 Section 5.2 Essentials of Counter-Controlled Repetition Chapter 5 Control Statements: Part 2 Section 5.2 Essentials of Counter-Controlled Repetition 5.2 Q1: Counter-controlled repetition requires a. A control variable and initial value. b. A control variable

More information

CA4003 Compiler Construction Assignment Language Definition

CA4003 Compiler Construction Assignment Language Definition CA4003 Compiler Construction Assignment Language Definition David Sinclair 2017-2018 1 Overview The language is not case sensitive. A nonterminal, X, is represented by enclosing it in angle brackets, e.g.

More information

Flow Control. CSC215 Lecture

Flow Control. CSC215 Lecture Flow Control CSC215 Lecture Outline Blocks and compound statements Conditional statements if - statement if-else - statement switch - statement? : opertator Nested conditional statements Repetitive statements

More information

Warm-up and Memoization

Warm-up and Memoization CSE341 Spring 05 Due Wednesday, May 11 Assignment 4 Part I Warm-up and Memoization Warm-up As a warm-up, write the following Scheme functions: 1. Write the function foldl of the form (foldl func initial

More information

Lecture 10. Daily Puzzle

Lecture 10. Daily Puzzle Lecture 10 Daily Puzzle Imagine there is a ditch, 10 feet wide, which is far too wide to jump. Using only eight narrow planks, each no more than 9 feet long, construct a bridge across the ditch. Daily

More information

FLOW CHART AND PSEUDO CODE

FLOW CHART AND PSEUDO CODE FLOW CHART AND PSEUDO CODE Flowchart A Flowchart is a pictorial representation of an algorithm. The First flowchart is made by John Von Newman in 1945. It is a symbolic diagram of operation sequence, dataflow,

More information

UNIT 2 ARRAYS 2.0 INTRODUCTION. Structure. Page Nos.

UNIT 2 ARRAYS 2.0 INTRODUCTION. Structure. Page Nos. UNIT 2 ARRAYS Arrays Structure Page Nos. 2.0 Introduction 23 2.1 Objectives 24 2.2 Arrays and Pointers 24 2.3 Sparse Matrices 25 2.4 Polynomials 28 2.5 Representation of Arrays 30 2.5.1 Row Major Representation

More information

Lesson 6A Loops. By John B. Owen All rights reserved 2011, revised 2014

Lesson 6A Loops. By John B. Owen All rights reserved 2011, revised 2014 Lesson 6A Loops By John B. Owen All rights reserved 2011, revised 2014 Topic List Objectives Loop structure 4 parts Three loop styles Example of a while loop Example of a do while loop Comparison while

More information

Chapter 12: Pointers and Arrays. Chapter 12. Pointers and Arrays. Copyright 2008 W. W. Norton & Company. All rights reserved.

Chapter 12: Pointers and Arrays. Chapter 12. Pointers and Arrays. Copyright 2008 W. W. Norton & Company. All rights reserved. Chapter 12 Pointers and Arrays 1 Introduction C allows us to perform arithmetic addition and subtraction on pointers to array elements. This leads to an alternative way of processing arrays in which pointers

More information

Fortran. (FORmula TRANslator) History

Fortran. (FORmula TRANslator) History Fortran (FORmula TRANslator) History FORTRAN vs. Fortran 1954 FORTRAN first successful high level language John Backus (IBM) 1958 FORTRAN II (Logical IF, subroutines, functions) 1961 FORTRAN IV 1966 FORTRAN

More information

This document contains additional questions; it is not intended to be treated as a complete paper.

This document contains additional questions; it is not intended to be treated as a complete paper. AS COMPUTER SCIENCE Paper 1 Additional Questions IMPORTANT NOTES These questions focus primarily on topics that were not covered by the AQA AS and A-level Computing specifications, introduced in 2009.

More information

Homework. Reading: Chapter 17 Homework: All exercises from Chapter 17 Due: 10/27 Correction: Chapter 16 homework is due 10/25

Homework. Reading: Chapter 17 Homework: All exercises from Chapter 17 Due: 10/27 Correction: Chapter 16 homework is due 10/25 Homework Reading: Chapter 17 Homework: All exercises from Chapter 17 Due: 10/27 Correction: Chapter 16 homework is due 10/25 Copyright c 2002 2017 UMaine Computer Science Department 1 / 33 1 COS 140: Foundations

More information

Information Regarding Program Input.

Information Regarding Program Input. 1 APES documentation (revision date: 17.03.10). Information Regarding Program Input. General Comments Finite element analyses generally require large amounts of input data. The preparation of this data

More information

1 Introduction to MATLAB

1 Introduction to MATLAB 1 Introduction to MATLAB 1.1 General Information Quick Overview This chapter is not intended to be a comprehensive manual of MATLAB R. Our sole aim is to provide sufficient information to give you a good

More information

STUDENT LESSON A12 Iterations

STUDENT LESSON A12 Iterations STUDENT LESSON A12 Iterations Java Curriculum for AP Computer Science, Student Lesson A12 1 STUDENT LESSON A12 Iterations INTRODUCTION: Solving problems on a computer very often requires a repetition of

More information

2nd Year Computational Physics Week 1 (experienced): Series, sequences & matrices

2nd Year Computational Physics Week 1 (experienced): Series, sequences & matrices 2nd Year Computational Physics Week 1 (experienced): Series, sequences & matrices 1 Last compiled September 28, 2017 2 Contents 1 Introduction 5 2 Prelab Questions 6 3 Quick check of your skills 9 3.1

More information

Team Prob. Team Prob

Team Prob. Team Prob 1 Introduction In this module, we will be simulating the draft lottery used by the National Basketball Association (NBA). Each year, the worst 14 teams are entered into a drawing to determine who will

More information

What Secret the Bisection Method Hides? by Namir Clement Shammas

What Secret the Bisection Method Hides? by Namir Clement Shammas What Secret the Bisection Method Hides? 1 What Secret the Bisection Method Hides? by Namir Clement Shammas Introduction Over the past few years I have modified the simple root-seeking Bisection Method

More information

Numerical Methods in Scientific Computation

Numerical Methods in Scientific Computation Numerical Methods in Scientific Computation Programming and Software Introduction to error analysis 1 Packages vs. Programming Packages MATLAB Excel Mathematica Maple Packages do the work for you Most

More information

QUIZ. 1. Explain the meaning of the angle brackets in the declaration of v below:

QUIZ. 1. Explain the meaning of the angle brackets in the declaration of v below: QUIZ 1. Explain the meaning of the angle brackets in the declaration of v below: This is a template, used for generic programming! QUIZ 2. Why is the vector class called a container? 3. Explain how the

More information

Software Testing for Developer Development Testing. Duvan Luong, Ph.D. Operational Excellence Networks

Software Testing for Developer Development Testing. Duvan Luong, Ph.D. Operational Excellence Networks Software Testing for Developer Development Testing Duvan Luong, Ph.D. Operational Excellence Networks Contents R&D Testing Approaches Static Analysis White Box Testing Black Box Testing 4/2/2012 2 Development

More information

Functions in C C Programming and Software Tools

Functions in C C Programming and Software Tools Functions in C C Programming and Software Tools N.C. State Department of Computer Science Functions in C Functions are also called subroutines or procedures One part of a program calls (or invokes the

More information

PROGRAMMAZIONE I A.A. 2017/2018

PROGRAMMAZIONE I A.A. 2017/2018 PROGRAMMAZIONE I A.A. 2017/2018 ARRAYS ARRAYS An array contains objects of a given type, stored consecutively in a continuous memory block. The individual objects are called the elements of an array. The

More information

Computational Methods of Scientific Programming. Lecturers Thomas A Herring Chris Hill

Computational Methods of Scientific Programming. Lecturers Thomas A Herring Chris Hill 12.010 Computational Methods of Scientific Programming Lecturers Thomas A Herring Chris Hill Review of Lecture 2 Examined computer hardware Computer basics and the main features of programs Program design:

More information

CSE101-lec#12. Designing Structured Programs Introduction to Functions. Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU

CSE101-lec#12. Designing Structured Programs Introduction to Functions. Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU CSE101-lec#12 Designing Structured Programs Introduction to Functions Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU Outline Designing structured programs in C: Counter-controlled repetition

More information

FORTRAN 90: Functions, Modules, and Subroutines. Meteorology 227 Fall 2017

FORTRAN 90: Functions, Modules, and Subroutines. Meteorology 227 Fall 2017 FORTRAN 90: Functions, Modules, and Subroutines Meteorology 227 Fall 2017 Purpose First step in modular program design Cannot always anticipate all of the steps that will be needed to solve a problem Easier

More information

V3 1/3/2015. Programming in C. Example 1. Example Ch 05 A 1. What if we want to process three different pairs of integers?

V3 1/3/2015. Programming in C. Example 1. Example Ch 05 A 1. What if we want to process three different pairs of integers? Programming in C 1 Example 1 What if we want to process three different pairs of integers? 2 Example 2 One solution is to copy and paste the necessary lines of code. Consider the following modification:

More information

Semantics via Syntax. f (4) = if define f (x) =2 x + 55.

Semantics via Syntax. f (4) = if define f (x) =2 x + 55. 1 Semantics via Syntax The specification of a programming language starts with its syntax. As every programmer knows, the syntax of a language comes in the shape of a variant of a BNF (Backus-Naur Form)

More information

Lab #10 Multi-dimensional Arrays

Lab #10 Multi-dimensional Arrays Multi-dimensional Arrays Sheet s Owner Student ID Name Signature Group partner 1. Two-Dimensional Arrays Arrays that we have seen and used so far are one dimensional arrays, where each element is indexed

More information

CS1102: Macros and Recursion

CS1102: Macros and Recursion CS1102: Macros and Recursion Kathi Fisler, WPI October 5, 2009 This lecture looks at several more macro examples. It aims to show you when you can use recursion safely with macros and when you can t. 1

More information

Algorithm Concepts. 1 Basic Algorithm Concepts. May 16, Computational Method

Algorithm Concepts. 1 Basic Algorithm Concepts. May 16, Computational Method Algorithm Concepts David R. Musser Brian Osman May 16, 2003 This document contains Section 1 of Algorithm Concepts, a collection of algorithm concept descriptions in both Web page and print form under

More information

CS 221 Lecture. Tuesday, 11 October 2011

CS 221 Lecture. Tuesday, 11 October 2011 CS 221 Lecture Tuesday, 11 October 2011 "Computers in the future may weigh no more than 1.5 tons." - Popular Mechanics, forecasting the relentless march of science, 1949. Today s Topics 1. Announcements

More information

write (unit=*,fmt=*) i =, i! will print: i = 3

write (unit=*,fmt=*) i =, i! will print: i = 3 I/O (F book, chapters 9, 10 and 15) All I/O in Fortran90 is record-based, typically with record delimiters of some kind. This is in contrast to C, which has stream I/O, with no record delimiters required.

More information

Ansoft HFSS Convergence

Ansoft HFSS Convergence Data Max Delta Matrix Parameters Ansoft HFSS Choose from the Executive Commands window to view information about the solution. If you have solved for a driven solution, the following window appears: Maxwell

More information

An interesting related problem is Buffon s Needle which was first proposed in the mid-1700 s.

An interesting related problem is Buffon s Needle which was first proposed in the mid-1700 s. Using Monte Carlo to Estimate π using Buffon s Needle Problem An interesting related problem is Buffon s Needle which was first proposed in the mid-1700 s. Here s the problem (in a simplified form). Suppose

More information

بسم اهلل الرمحن الرحيم

بسم اهلل الرمحن الرحيم بسم اهلل الرمحن الرحيم Fundamentals of Programming C Session # 10 By: Saeed Haratian Fall 2015 Outlines Examples Using the for Statement switch Multiple-Selection Statement do while Repetition Statement

More information

First Order Predicate Logic CIS 32

First Order Predicate Logic CIS 32 First Order Predicate Logic CIS 32 Functionalia Demos? HW 3 is out on the web-page. Today: Predicate Logic Constructing the Logical Agent Predicate Logic First-order predicate logic More expressive than

More information

C PROGRAMMING LANGUAGE. POINTERS, ARRAYS, OPERATORS AND LOOP. CAAM 519, CHAPTER5

C PROGRAMMING LANGUAGE. POINTERS, ARRAYS, OPERATORS AND LOOP. CAAM 519, CHAPTER5 C PROGRAMMING LANGUAGE. POINTERS, ARRAYS, OPERATORS AND LOOP. CAAM 519, CHAPTER5 1. Pointers As Kernighan and Ritchie state, a pointer is a variable that contains the address of a variable. They have been

More information

ME1107 Computing Y Yan.

ME1107 Computing Y Yan. ME1107 Computing 1 2008-2009 Y Yan http://www.staff.city.ac.uk/~ensyy About Fortran Fortran Formula Translation High level computer language Basic, Fortran, C, C++, Java, C#, (Matlab) What do we learn?

More information

Modularity and Reusability I. Functions and code reuse

Modularity and Reusability I. Functions and code reuse Modularity and Reusability I Functions and code reuse Copyright 2006 2009 Stewart Weiss On being efficient When you realize that a piece of Perl code that you wrote may be useful in future programs, you

More information

Constraint Satisfaction Problems

Constraint Satisfaction Problems Constraint Satisfaction Problems Robert Platt Northeastern University Some images and slides are used from: 1. AIMA What is a CSP? The space of all search problems states and actions are atomic goals are

More information

Fortran Coding Standards and Style

Fortran Coding Standards and Style Fortran Coding Standards and Style The Fortran Company Version 20160112 Copyright 2015-2016, The Fortran Company All rights reserved. Redistribution, with or without modification, is permitted provided

More information

Introduction to Computers II Lecture 4. Dr Ali Ziya Alkar Dr Mehmet Demirer

Introduction to Computers II Lecture 4. Dr Ali Ziya Alkar Dr Mehmet Demirer Introduction to Computers II Lecture 4 Dr Ali Ziya Alkar Dr Mehmet Demirer 1 Contents: Utilizing the existing information Top-down design Start with the broadest statement of the problem Works down to

More information

HOW TO INVENT AN ALGORITHM

HOW TO INVENT AN ALGORITHM HOW TO INVENT AN ALGORITHM Here are all the ideas from the previous topics combined into a strategy for inventing algorithms. How to Invent an Algorithm Step What? How? 1 Understand the problem by solving

More information

Programming II (CS300)

Programming II (CS300) 1 Programming II (CS300) Chapter 10 Recursion and Search MOUNA KACEM mouna@cs.wisc.edu Spring 2019 Recursion: General Overview 2 Recursion in Algorithms Recursion is the use of recursive algorithms to

More information

Estimating DCMs Using Mplus. Chapter 9 Example Data

Estimating DCMs Using Mplus. Chapter 9 Example Data Estimating DCMs Using Mplus 1 NCME 2012: Diagnostic Measurement Workshop Chapter 9 Example Data Example assessment 7 items Measuring 3 attributes Q matrix Item Attribute 1 Attribute 2 Attribute 3 1 1 0

More information

Algorithms & Data Structures

Algorithms & Data Structures GATE- 2016-17 Postal Correspondence 1 Algorithms & Data Structures Computer Science & Information Technology (CS) 20 Rank under AIR 100 Postal Correspondence Examination Oriented Theory, Practice Set Key

More information

(Refer Slide Time 01:41 min)

(Refer Slide Time 01:41 min) Programming and Data Structure Dr. P.P.Chakraborty Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture # 03 C Programming - II We shall continue our study of

More information

Dr. Iyad Jafar. Adapted from the publisher slides

Dr. Iyad Jafar. Adapted from the publisher slides Computer Applications Lab Lab 5 Programming in Matlab Chapter 4 Sections 1,2,3,4 Dr. Iyad Jafar Adapted from the publisher slides Outline Program design and development Relational operators and logical

More information

Chapter 8 Statement-Level Control Structures

Chapter 8 Statement-Level Control Structures Chapter 8 Statement-Level Control Structures In Chapter 7, the flow of control within expressions, which is governed by operator associativity and precedence rules, was discussed. This chapter discusses

More information

Data 8 Final Review #1

Data 8 Final Review #1 Data 8 Final Review #1 Topics we ll cover: Visualizations Arrays and Table Manipulations Programming constructs (functions, for loops, conditional statements) Chance, Simulation, Sampling and Distributions

More information

Object-Oriented Design Lecture 11 CS 3500 Spring 2010 (Pucella) Tuesday, Feb 16, 2010

Object-Oriented Design Lecture 11 CS 3500 Spring 2010 (Pucella) Tuesday, Feb 16, 2010 Object-Oriented Design Lecture 11 CS 3500 Spring 2010 (Pucella) Tuesday, Feb 16, 2010 11 Polymorphism The functional iterator interface we have defined last lecture is nice, but it is not very general.

More information

Module 4: Decision-making and forming loops

Module 4: Decision-making and forming loops 1 Module 4: Decision-making and forming loops 1. Introduction 2. Decision making 2.1. Simple if statement 2.2. The if else Statement 2.3. Nested if Statement 3. The switch case 4. Forming loops 4.1. The

More information

What is recursion? Recursion. How can a function call itself? Recursive message() modified. contains a reference to itself. Week 7. Gaddis:

What is recursion? Recursion. How can a function call itself? Recursive message() modified. contains a reference to itself. Week 7. Gaddis: Recursion What is recursion? Week 7! Generally, when something contains a reference to itself Gaddis:19.1-19.4! Math: defining a function in terms of itself CS 5301 Fall 2013 Jill Seaman 1! Computer science:

More information

Control Flow Structures

Control Flow Structures Control Flow Structures STAT 133 Gaston Sanchez Department of Statistics, UC Berkeley gastonsanchez.com github.com/gastonstat/stat133 Course web: gastonsanchez.com/stat133 Expressions 2 Expressions R code

More information

DO NOT. UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N.

DO NOT. UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. CS61B Fall 2013 UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division Test #2 Solutions DO NOT P. N. Hilfinger REPRODUCE 1 Test #2 Solution 2 Problems

More information

INTRODUCTION TO MATLAB, SIMULINK, AND THE COMMUNICATION TOOLBOX

INTRODUCTION TO MATLAB, SIMULINK, AND THE COMMUNICATION TOOLBOX INTRODUCTION TO MATLAB, SIMULINK, AND THE COMMUNICATION TOOLBOX 1) Objective The objective of this lab is to review how to access Matlab, Simulink, and the Communications Toolbox, and to become familiar

More information

12 whereas if I terminate the expression with a semicolon, the printed output is suppressed.

12 whereas if I terminate the expression with a semicolon, the printed output is suppressed. Example 4 Printing and Plotting Matlab provides numerous print and plot options. This example illustrates the basics and provides enough detail that you can use it for typical classroom work and assignments.

More information

Practice problems Set 2

Practice problems Set 2 Practice problems Set 2 1) Write a program to obtain transpose of a 4 x 4 matrix. The transpose of matrix is obtained by exchanging the elements of each row with the elements of the corresponding column.

More information

Structures, Operators

Structures, Operators Structures Typedef Operators Type conversion Structures, Operators Basics of Programming 1 G. Horváth, A.B. Nagy, Z. Zsóka, P. Fiala, A. Vitéz 10 October, 2018 c based on slides by Zsóka, Fiala, Vitéz

More information

2 Making Decisions. Store the value 3 in memory location y

2 Making Decisions. Store the value 3 in memory location y 2.1 Aims 2 Making Decisions By the end of this worksheet, you will be able to: Do arithmetic Start to use FORTRAN intrinsic functions Begin to understand program flow and logic Know how to test for zero

More information

CS 361 Computer Systems Fall 2017 Homework Assignment 4 - Inter-Process Communications & I/O

CS 361 Computer Systems Fall 2017 Homework Assignment 4 - Inter-Process Communications & I/O CS 361 Computer Systems Fall 2017 Homework Assignment 4 - Inter-Process Communications & I/O Overall Assignment For this assignment, you are to write three programs that will work together using inter-process

More information

Functions in C C Programming and Software Tools. N.C. State Department of Computer Science

Functions in C C Programming and Software Tools. N.C. State Department of Computer Science Functions in C C Programming and Software Tools N.C. State Department of Computer Science Functions in C Functions are also called subroutines or procedures One part of a program calls (or invokes the

More information

Review Functions Subroutines Flow Control Summary

Review Functions Subroutines Flow Control Summary OUTLINE 1 REVIEW 2 FUNCTIONS Why use functions How do they work 3 SUBROUTINES Why use subroutines? How do they work 4 FLOW CONTROL Logical Control Looping 5 SUMMARY OUTLINE 1 REVIEW 2 FUNCTIONS Why use

More information

1.1 Basic Concepts 1

1.1 Basic Concepts 1 1.1 Basic Concepts 1 What is Data Structure? (1) Data Structure How do we store (input/output) data in a (mostly) main memory? Ex) How to store a Matrix in a memory? We need to specify a data structure

More information

34. Recursion. Java. Summer 2008 Instructor: Dr. Masoud Yaghini

34. Recursion. Java. Summer 2008 Instructor: Dr. Masoud Yaghini 34. Recursion Java Summer 2008 Instructor: Dr. Masoud Yaghini Outline Introduction Example: Factorials Example: Fibonacci Numbers Recursion vs. Iteration References Introduction Introduction Recursion

More information

Math Modeling in Java: An S-I Compartment Model

Math Modeling in Java: An S-I Compartment Model 1 Math Modeling in Java: An S-I Compartment Model Basic Concepts What is a compartment model? A compartment model is one in which a population is modeled by treating its members as if they are separated

More information

An algorithm may be expressed in a number of ways:

An algorithm may be expressed in a number of ways: Expressing Algorithms pseudo-language 1 An algorithm may be expressed in a number of ways: natural language: flow charts: pseudo-code: programming language: usually verbose and ambiguous avoid most (if

More information

CSE 120. Computer Science Principles

CSE 120. Computer Science Principles Adam Blank Lecture 17 Winter 2017 CSE 120 Computer Science Principles CSE 120: Computer Science Principles Proofs & Computation e w h e q 0 q 1 q 2 q 3 h,e w,e w,h w,h q garbage w,h,e CSE = Abstraction

More information

AMath 483/583 Lecture 21

AMath 483/583 Lecture 21 AMath 483/583 Lecture 21 Outline: Review MPI, reduce and bcast MPI send and receive Master Worker paradigm References: $UWHPSC/codes/mpi class notes: MPI section class notes: MPI section of bibliography

More information

01. Function Description and Limitation 02. Fortran File Preparation 03. DLL File Preparation 04. Using the USSR material model in midas FEA

01. Function Description and Limitation 02. Fortran File Preparation 03. DLL File Preparation 04. Using the USSR material model in midas FEA midas FEA User Supplied Subroutine User Manual 01. Function Description and Limitation 02. Fortran File Preparation 03. DLL File Preparation 04. Using the USSR material model in midas FEA MIDAS Information

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

Our Strategy for Learning Fortran 90

Our Strategy for Learning Fortran 90 Our Strategy for Learning Fortran 90 We want to consider some computational problems which build in complexity. evaluating an integral solving nonlinear equations vector/matrix operations fitting data

More information

DECISION MAKING STATEMENTS

DECISION MAKING STATEMENTS DECISION MAKING STATEMENTS If, else if, switch case These statements allow the execution of selective statements based on certain decision criteria. C language provides the following statements: if statement

More information

Control Constructs: Loops - while loops - iterative loops (counting loops)

Control Constructs: Loops - while loops - iterative loops (counting loops) 4. Loops Control Constructs: Loops - while loops - iterative loops (counting loops) While loop do... if (logical_expression) exit... do while (logical_expression)... statement block logical expression.false.

More information

Programming II (CS300)

Programming II (CS300) 1 Programming II (CS300) Chapter 10 Recursion and Search MOUNA KACEM Recursion: General Overview 2 Recursion in Algorithms Recursion is the use of recursive algorithms to solve a problem A recursive algorithm

More information

COSC 122 Computer Fluency. Iteration and Arrays. Dr. Ramon Lawrence University of British Columbia Okanagan

COSC 122 Computer Fluency. Iteration and Arrays. Dr. Ramon Lawrence University of British Columbia Okanagan COSC 122 Computer Fluency Iteration and Arrays Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca Key Points 1) A loop repeats a set of statements multiple times until some

More information

Method & Tools for Program Analysis & Design

Method & Tools for Program Analysis & Design Method & Tools for Program Analysis & Design TMB208 Pemrograman Teknik Kredit: 3 (2-3) 1 Programming Logic and Design, Introductory, Fourth Edition 2 1 Programming Methods Based on structures of programming

More information

Computer Programming & Problem Solving ( CPPS ) Turbo C Programming For The PC (Revised Edition ) By Robert Lafore

Computer Programming & Problem Solving ( CPPS ) Turbo C Programming For The PC (Revised Edition ) By Robert Lafore Sir Syed University of Engineering and Technology. Computer ming & Problem Solving ( CPPS ) Functions Chapter No 1 Compiled By: Sir Syed University of Engineering & Technology Computer Engineering Department

More information

APS105. Malloc and 2D Arrays. Textbook Chapters 6.4, Datatype Size

APS105. Malloc and 2D Arrays. Textbook Chapters 6.4, Datatype Size APS105 Malloc and 2D Arrays Textbook Chapters 6.4, 10.2 Datatype Size Datatypes have varying size: char: 1B int: 4B double: 8B int sizeof(): a builtin function that returns size of a type int x =

More information

Data Structures STAT 133. Gaston Sanchez. Department of Statistics, UC Berkeley

Data Structures STAT 133. Gaston Sanchez. Department of Statistics, UC Berkeley Data Structures STAT 133 Gaston Sanchez Department of Statistics, UC Berkeley gastonsanchez.com github.com/gastonstat/stat133 Course web: gastonsanchez.com/stat133 Data Types and Structures To make the

More information

2.2 (a) Statement, subroutine, procedure, function, parameter, loop

2.2 (a) Statement, subroutine, procedure, function, parameter, loop Chapter 2.2: The structure of procedural programs 2.2 (a) Statement, subroutine, procedure, function, parameter, loop Procedural programs are ones in which instructions are executed in the order defined

More information

Chapter 2: Functions and Control Structures

Chapter 2: Functions and Control Structures Chapter 2: Functions and Control Structures TRUE/FALSE 1. A function definition contains the lines of code that make up a function. T PTS: 1 REF: 75 2. Functions are placed within parentheses that follow

More information

Example C++ Program Demonstrating Usage of a Pointer to a Function in the Call to Another Function

Example C++ Program Demonstrating Usage of a Pointer to a Function in the Call to Another Function ME 5241 Computer Aided Engineering Tom Chase Fall 2000 Example C++ Program Demonstrating Usage of a Pointer to a Function in the Call to Another Function The sample code below implements the Newton s Method

More information