CIS162AD - C#.

Uploaded on:
CIS162AD. 2. Review of Topic. Pseudocode Flow Control StructuresFlowchartingIf, If-ElseNested If\'sSelect Case
Slide 1

CIS162AD - C# If Statements 04_decisions.ppt

Slide 2

Overview of Topic Pseudocode Flow Control Structures Flowcharting If, If-Else Nested If\'s Select Case – Switch proclamation

Slide 3

Pseudocode is a blend of C# code and English like explanations. Utilized when planning calculations. Whenever planning, we would prefer fundamentally not to be worried about strategy names (ToString). We need to focus on the configuration. I\'ll use pseudocode all through the course, so don\'t feel constrained to adjust my language structure. Be that as it may, if at whenever you are not certain around a summon, please make sure to request elucidation. 

Slide 4

The request in which proclamations are executed. There are four structures. Arrangement Control Structure Selection Control Structure Also alluded to as stretching (if and if-else) Case Control Structure (switch) Repetition Control Structure (circles) Flow Control Structures

Slide 5

Flowcharting A flowchart is a pictorial representation of a calculation or legitimate strides. Every progression is spoken to by an image and the bolts demonstrate the stream and request of the means. The state of the image demonstrates the sort of operation that is to happen. Flowcharts may help the move visual understudies learn and comprehend rationale.

Slide 6

Input or Output Begin or End Decision Processing Branch or Direction of Flow Flowchart Symbols

Slide 7

1. Arrangement Control Structure The request explanations are put (sequenced) //input intQty = int.Parse(txtQuantity.Text); decPrice = decimal.Parse(txtPrice.Text); /process decSubtotal = intQty * decPrice; //yield txtSubtotal.Text = decSubtotal.ToString("N"); The best way to show subtotal, articulations must be in a specific order.

Slide 8

Begin Input cost, qty subtotal = cost * qty Output subtotal End Flowchart – Sequence Control

Slide 9

2. Determination Control ( If ) Use if proclamations to figure out whether an arrangement of articulations ought to be executed. decSubtotal = intQty * decPrice if (chkSalesTax.Checked = genuine) decSalesTax = decSubtotal * cdecTAX_RATE; lblSalesTax.Text = decSalesTax.ToString("C");

Slide 10

Subtotal = qty * cost If assessable True Sales charge = subtotal * Tax Rate False Output deals charge Flowchart – If Statement

Slide 11

Selection Control (If-Else) Use if else explanations when there are a few choices to browse. on the off chance that (radNextDay.Checked == genuine) decShipping = cdecNEXT_DAY_SHIPPING_RATE; else decShipping = cdecTHREE_DAY_SHIPPING_RATE; After if else proclamation, decShipping will have a worth.

Slide 12

User chooses Shipping If Next Day Shipping = Next Day True False Shipping = Three Day Output Shipping Flowchart – If-Else Statement

Slide 13

Condition is an Expression Conditions assess to genuine or false. in the event that (condition) true – 1 or more articulations else false – 1 or more explanations

Slide 14

Block of code – Compound Statements Use supports to make a square of proclamations. Single articulations don\'t require props. on the off chance that (intHours > 40) { decRegularPay = 40 * decPayRate; decOvertimePay = (intHours – 40) * (decPayRate * cdec_OVERTIME_RATE); } else { decRegularPay = intHours * decPayRate; decOvertimePay = 0; } decGrossPay = decRegularPay + decOvertimePay;

Slide 15

Incorrect if-else if (intHours > 40) { decRegularPay = 40 * decPayRate; decOvertimePay = (intHours – 40) * (decPayRate * cdec_OVERTIME_RATE); } else decRegularPay = intHours * decPayRate; decOvertimePay = 0; decGrossPay = decRegularPay + decOvertimePay; decOvertimePay would dependably be set to zero, on the grounds that there is a solitary articulation for else since supports are excluded.

Slide 16

Nested If Statements First if must be valid keeping in mind the end goal to proceed. on the off chance that (intQuantity >= 1) if (decPrice >= 5.00M) decSubtotal = intQty * decPrice; else { MessageBox.Show("Invalid cost entered"); txtPrice.Focus(); txtPrice.SelectAll(); } else { MessageBox.Show("Invalid amount entered"); txtQuantity.Focus(); txtQuantity.SelectAll(); }

Slide 17

Matching an Else to If How are else articulations coordinated with an if? Compiler works it\'s way back. At the point when an else is experience, it thinks back to discover an if that has not been coordinated to an else. Why do we indent every level? We indent to make programs less demanding to peruse. Indenting has no impact on how compiler coordinates an else to an if.

Slide 18

Selection Control (else if) Multiway Branching Compare every condition through and through, square of code for 1 st genuine condition is executed, and afterward skip to the announcement taking after the if-else articulations. on the off chance that (radNextDay.Checked == genuine) decShipping = cdecNEXT_DAY_SHIPPING_RATE; else if (radThreeDay.Checked == genuine) decShipping = cdecTHREE_DAY_SHIPPING_RATE; else decShipping = cdecGROUND_SHIPPING_RATE;

Slide 19

= ! = < > < = > = Equal to Not Equal to Less than Greater than Less than or equivalent to Greater than or equivalent to Relational Operators Relational Operators are utilized to shape conditions, and conditions can include constants, variables, numeric administrators, and capacities.

Slide 20

Assignment (=) versus Comparison (==) if (x = 12)/may produce language structure mistake. in the event that (x == 12)/examination The mistake message created will need to do with a certain information change to bool. On the off chance that you get this mistake, watch that you utilized 2 measure up to signs.

Slide 21

Logical Operators Compound or Complex Conditions can be structure utilizing Logical Operators. && – And, both conditions must be genuine | – Or, either condition must be genuine ! – Not, turns around the subsequent condition

Slide 22

&& - And Logical Operator Both conditions must be valid all together for the whole condition to be valid. in the event that (intQty > 0 && intQty < 51) decSubtotal = intQty * decPrice; Else MessageBox.Show ("Enter a quality somewhere around 1 and 50"); What happens if qty = 25? What happens if qty = 60?

Slide 23

Use Parentheses Use brackets to clear up or bunch conditions. All conditions must be encased with external enclosures. on the off chance that ((intQty > 0) && (intQty < 51)) decSubtotal = intQty * decPrice; else MessageBox.Show ("Enter a worth somewhere around 1 and 50");

Slide 24

| - Or Logical Operator Either condition must be valid for the whole condition to be valid. The funnel character is situated over the Enter key; must move to choose it, and two of them are entered beside each other. on the off chance that ((intQty < 1) || (intQty > 50)) MessageBox.Show "Enter a quality somewhere around 1 and 50"); else decSubtotal = intQty * decPrice; What happens if qty = 25? What happens if qty = 60?

Slide 25

Pipe Character - | Where is the channel character on the console? On most consoles It is right over the Enter key Shares the key with the oblique punctuation line - \ Must hold the movement key go get it Instead of a strong line, it is appeared as a broken line For the Or administrator, 2 funnel characters must be entered - |. For the And administrator, 2 ampersands characters must be entered - &&.

Slide 26

Short-Circuit Comparisons In a compound correlation, if the outcome (True or False) can be resolved before assessing the whole Boolean Expression. This enhances execution. Furthermore, – The 2 nd condition is not assessed if the 1 st assesses to False – the consequence of a whole assessment of an And would be False at any rate. On the other hand - The 2 nd condition is not assessed if the 1 st assesses to True – the aftereffect of a whole assessment of an Or would be True in any case. Utilizing single administrators (& or | ) powers the second condition to be tried. This is just required if the condition incorporates an estimation. In the event that we required intCount augmented every time, this would be the right linguistic structure so that the 2 nd condition is handled. (intAmount > 0 & intCount++ < intLimit)

Slide 27

! – Not Logical Operator Not administrator makes the condition the opposite it assessed to… If condition is valid, Not makes it false. On the off chance that condition is false, Not makes it genuine. in the event that ! (intQty = 50) true intQty < > 50 else false intQty = 50 Confusing, do whatever it takes not to utilize Not.

Slide 28

check =0 limit = 10 min=5 if ((number = 0) && (limit < 20)) if (tally = 0 && limit < 20) if (limit > 20 | tally < 5 ) if ! (tally = 12) if ((number = 10) | (limit > 5 && min < 10)) True Practice Exercises

Slide 29

Comparing Boolean\'s Booleans are variables that are equivalent to either True or False. A few properties are additionally True or False. The accompanying condition will return True if the radio catch for Next Day was checked: if (radNextDay.Checked = genuine) The alternate route to the above condition is to leave = valid off as takes after: if (radNextDay.Checked) We ought to normally express the sought condition (= valid) to maintain a strategic distance from bugs and perplexity.

Slide 30

Comparing Strings String variables, properties, or literals can likewise be thought about. Just (==) and (!=) can be utilized with strings. Can utilize CompareTo technique – more on this later. Strings are contrasted from left with right. The characters\' twofold esteem is utilized to figured out which is more prominent or not exactly. This implies capitalization is considered. ASCII Code Table records the parallel qualities.

Slide 31

ASCII Table ASC II table demonstrates the double estimation of each of the 256 characters. American Standard Code for Information Interchange The Dec segment demonstrates the decimal estimation of the twofold esteem. Parallel qualities are normally changed over to hexadecimal (Hex) in light of the fact that the worth can spoke to with two digits rather than 8. Turn upward CR, HT, Space, An, a Shows that a capital An is not the same as a lower case a. Indicates how values will be sorted (examining succession). Unicode – 2 bytes, 16 bits, 65,536 one of a kind characters

Slide 32

ToUpper and ToLower Methods Use ToUpper and ToLower techniques for the String class to change over str

View more...