DOC PREVIEW
TAMU CSCE 110 - 07-selection And Iteration
Type Miscellaneous
Pages 52

This preview shows page 1-2-3-25-26-27-28-50-51-52 out of 52 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 52 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 52 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 52 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 52 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 52 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 52 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 52 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 52 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 52 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 52 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 52 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

J. Michael MooreStructured ProgrammingCPSC 110Drawn from James Tam's materialJ. Michael MooreProgramming Structure• ___________________• ___________________• ___________________J. Michael MooreSequence• Programs are executed at a time.• A compound statement a sequence of statements as a __________statement.J. Michael MooreCompound Statementbeginstatement1;statement2;..end;J. Michael MooreHigh Level View Of Decision Making For The ComputerIs income below $10,000?FalseIs income between $10K - $20K?TrueIncome tax = 20%Falseetc.True•Nominal income deduction•Eligible for social assistanceJ. Michael MooreDecision-Making In Pascal• Decisions are questions with answers that are either _____or ______ (Boolean) e.g., Is it true that the variable 'x' is positive?• The program branches one way or another depending upon the answer to the question.J. Michael MooreIf-ThenQuestion?Execute a statementTrueFalseRemainder of the programJ. Michael MooreBoolean expression• Decision-making: checking if a particular condition is trueFormat:if (boolean-expression) thenstatement;additional statements;• Example:if (age >= 18) thenwriteln('You are an adult');writeln('Tell me more about yourself');If-ThenIndicates ________ ________________ _________ _________J. Michael MooreAllowable Operands For Boolean ExpressionsCan also stand alone as a Boolean expression (it is a boolean value)•integer•real•boolean•char•constOperands:Boolean-expression:operand relational-operator operandORboolean-valueJ. Michael MooreRelational Operators For Boolean ExpressionsIf (operand relational-operator operand) thenPascal Mathematical operator equivalent Meaning< < Less than> > Greater than= = Equal to<= ≤ Less than or equal to>= ≥ Greater than or equal to<> ≠ Not equal toJ. Michael MooreStatement / Body• Body of if-then consists of a single statement• Format:if (Boolean expression) thens1;s2;• Example:if (x = 1) thenwriteln('Body of if');writeln ('After body');If-Then (Simple Statement)Indicates _______________________________________________________. (Note: _________________________ ____________________________.)J. Michael MooreBody / Compound Statement• Body of if-then consists of multiple statements• Format:if (Boolean expression) thenbegins1;s2;:sn;end;sn+1;If-Then (Compound Statement)Indicates _________________________________________________________________________________J. Michael MooreIf-Then (Compound Statement)• Example:taxRate := 0.2;if (income < 10000) thenbeginwriteln('Eligable for social assistance');taxCredit = 100;end;tax = income * taxRate;J. Michael MooreIf-Then: What Gets Executed• When true, the if executes ____________which is a _________ statement.• ________statement: the body follows the 'then' and precedes the first semi-colon.• _______________statement: the body is enclosed within the begin-end pair as a compound statement.J. Michael MooreIf-Then-ElseQuestion?Execute a statementTrueFalseExecute a statementRemainder of the programJ. Michael Moore• Decision-making with two conditions (true or false)• Format:if (boolean-expression) thenbody of 'if'elsebody of 'else';additional statements;If-Then-ElseNo semi-colon ___________________________________________________________!!!Semi-colon _______________ __________________________ _________________________.Note: ____________________ _________________________ _______________.J. Michael MooreIf-Then-Else• Example:if (age >= 18) thenwriteln('Adult')elsewriteln('Not an adult');writeln('Tell me more about yourself');J. Michael MooreIf-Then-Else (Simple Statement)• Body of if-then-else consists of a _______statement• Format:if (Boolean expression) thens1elses2;s3;____________________________________________________________________________!!!_____________________________________________________________________________.J. Michael MooreIf-Then-Else (Simple Statement)• Example:if (x = 1) thenwriteln('body of if')elsewriteln('body of else');writeln('after if-then-else');J. Michael MooreIf-Then-Else (Compound Statement)• if (boolean-expression) thenbegins1;:sn;endelsebeginsn+1;:sn + m;end;sn + m + 1;No semi-colon (__________________________________!)Semi-colon (_____________________________________________________________________________!– _______________________________________)J. Michael MooreIf-Then(Compound Statement)• Example:if (income < 10000) thenbeginwriteln('Eligible for social assistance');taxRate := 0.1;endelsebeginwriteln('Not eligible for social assistance');taxRate := 0.2;end;tax = income * taxRate;J. Michael MooreQuick Summary: If Vs. If-Else•If:– Evaluates a __________________ (asks a question)– If the expression evaluates to _____ then execute the '______' of the _____.– If the expression evaluates to _______ then _________________________________________.– Use when your program evaluates a ____________ __________ and code will be ____________ only when the expression evaluates to ________.J. Michael MooreQuick Summary: If Vs. If-Else• If-else:– Evaluates a __________________ (asks a question)– If the expression evaluates to _____ then execute the '_______' of the ______.– If the expression evaluates to _____ then execute the '_______' of the ______.– Use when your program evaluates a _____________ ___________ and ________ code will ____________if the expression evaluates to _____ than if the expression evaluates to _____.J. Michael MooreNested Decision Making• Decision making is dependent.• The first decision must evaluate to ________before the ____________decisions are even ____________for evaluation.Question 1?TrueQuestion 2?TrueStatement Remainder of the programFalseFalseJ. Michael MooreOuter bodyInner bodyNested Decision Making• One decision is made ___________________• ______ decisions must evaluate to ______ before ______ decisions are even ___________ for evaluation.• Format:if (Boolean expression) thenif (Boolean expression) theninner body• Example: if (income < 10000) thenif (citizen = true) thenwriteln('Eligable for social assistance');tax := income * TAX_RATE;J. Michael MooreIs this for x or y????if (x > 0) thenif (y > 0) thenwriteln('x and y greater than


View Full Document

TAMU CSCE 110 - 07-selection And Iteration

Type: Miscellaneous
Pages: 52
Documents in this Course
06-IO

06-IO

29 pages

21-OOP

21-OOP

8 pages

key

key

6 pages

21-OOP

21-OOP

8 pages

Load more
Download 07-selection And Iteration
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view 07-selection And Iteration and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view 07-selection And Iteration 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?