Computing with C# and the.NET Framework Chapter 3 Software Engineering with Control Structures.

Slides:



Advertisements
Similar presentations
Selection Feature of C: Decision making statements: It allow us to take decisions as to which code is to be executed next. Since these statements control.
Advertisements

Decisions If statements in C.
More on Algorithms and Problem Solving
3. S/E with Control Structures 3.1 Relational Operators and Expressions 3.2 If and if-else Statements 3.3 The Type Double 3.4 Program Design with the While.
 2006 Pearson Education, Inc. All rights reserved Control Statements: Part 1.
INSTRUCTOR: SHIH-SHINH HUANG Windows Programming Using Java Chapter4: Control Statements Part I.
Repetition Chapter 4: Control structures. Introduction to OOPDr. S. GANNOUNI & Dr. A. TOUIRPage 2 Loop Statements After reading and studying this Section,
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 4 – Introducing Algorithms, Pseudocode and.
Chapter 3 - Structured Program Development
1 Objectives You should be able to describe: Relational Expressions The if-else Statement Nested if Statements The switch Statement Common Programming.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 3 - Structured Program Development Outline.
COMP 14 Introduction to Programming Miguel A. Otaduy May 18, 2004.
 2008 Pearson Education, Inc. All rights reserved Control Statements: Part 1.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 6: Repetition  Some additional operators increment and decrement.
Structured Program Development in C
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 30, 2005.
COMP 110 Introduction to Programming Mr. Joshua Stough September 24, 2007.
Section 3 - Selection and Repetition Constructs. Control Structures 1. Sequence 2. Selection 3. Repetition.
CIS3931 – Intro to JAVA Lecture Note Set 3 19-May-05.
Presented by Joaquin Vila Prepared by Sally Scott ACS 168 Problem Solving Using the Computer Week 12 Boolean Expressions, Switches, For-Loops Chapter 7.
COMPE 111 Introduction to Computer Engineering Programming in Python Atılım University
An ordered sequence of unambiguous and well-defined instructions that performs some task and halts in finite time Let's examine the four parts of this.
Flow Charting. Goals Create Algorithms using Flow Charting procedures. Distinguish between Flow Charting and Pseudocode. Top-Down Design Bottom-up Design.
Spring 2005, Gülcihan Özdemir Dağ Lecture 3, Page 1 BIL104E: Introduction to Scientific and Engineering Computing, Spring Lecture 3 Outline 3.1 Introduction.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 7.1 Test-Driving the Wage Calculator Application.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 4 – Wage Calculator Application: Introducing.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Structural Program Development: If, If-Else Outline.
Chapter 6 - VB 2005 by Schneider1 Chapter 6 – Repetition 6.1 Do While and Do Until Loops 6.2 Processing Lists of Data with Do Loops 6.3 For...Next Loops.
1 Conditional statements Dept. of Computer Engineering Faculty of Engineering, Kasetsart University Bangkok, Thailand.
CSCI 3328 Object Oriented Programming in C# Chapter 5: C# Control Statement – Part II UTPA – Fall
2 Objectives You should be able to describe: Relational Expressions Relational Expressions The if-else Statement The if-else Statement Nested if Statements.
Conditionals & boolean operators
Structured Program Development Outline 2.1Introduction 2.2Algorithms 2.3Pseudo code 2.4Control Structures 2.5The If Selection Structure 2.6The If/Else.
Lecture 2: Logical Problems with Choices. Problem Solving Before writing a program Have a thorough understanding of the problem Carefully plan an approach.
C Lecture Notes 1 Structured Program Development.
Dale Roberts 1 Program Control - Algorithms Department of Computer and Information Science, School of Science, IUPUI CSCI N305.
Chapter 3 - Structured Program Development Outline 3.1Introduction 3.2Algorithms 3.3Pseudocode 3.4Control Structures 3.5The If Selection Structure 3.6The.
 2008 Pearson Education, Inc. All rights reserved Control Statements: Part 1.
Repetition. Control of Flow SEQUENCE SELECTION (if..else, switch…case) REPETITION.
1 Chapter 4: Basic Control Flow ► Chapter Goals  To be able to implement decisions using if statements  To understand statement blocks  To learn how.
1 Lecture 3 Control Structures else/if and while.
Week 8: Decisions Bryan Burlingame 21 October 2015.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
ICT Introduction to Programming Chapter 4 – Control Structures I.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
A FIRST BOOK OF C++ CHAPTER 5 REPETITION. OBJECTIVES In this chapter, you will learn about: The while Statement Interactive while Loops The for Statement.
Week 4 Program Control Structure
Copyright 2008 by Pearson Education Building Java Programs Chapter 4 Lecture 4-1: if and if/else Statements reading: 4.2 self-check: #4-5, 7, 10, 11 exercises:
SCIENTIFIC NOTATION Expressing a quantity as: a number between 1 and 10 multiplied by 10 to the appropriate power.
Copyright © 2012 Pearson Education, Inc. Chapter 5: Loops.
Computing with C# and the.NET Framework Chapter 4 More Control Structures and Types ©2003, 2011 Art Gittleman.
C++ Programming Lecture 5 Control Structure I (Selection) – Part I The Hashemite University Computer Engineering Department (Adapted from the textbook.
Copyright 2006 Addison-Wesley Brief Version of Starting Out with C++ Chapter 5 Looping.
 2003 Prentice Hall, Inc. All rights reserved. 1 Basic C++ Programming.
Lecture 7 – Repetition (Loop) FTMK, UTeM – Sem /2014.
An Introduction to Programming with C++ Sixth Edition Chapter 5 The Selection Structure.
Copyright © 2014 Pearson Addison-Wesley. All rights reserved. 4 Simple Flow of Control.
1 Chapter 4 - Control Statements: Part 1 Outline 4.1 Introduction 4.4 Control Structures 4.5 if Selection Structure 4.6 if/else Selection Structure 4.7.
Data Types and Expressions
The Selection Structure
C# and the .NET Framework
Programming Fundamentals
Chapter 5: Looping Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Lecture 2: Logical Problems with Choices
Structured Program
Chapter 3 - Structured Program Development
3 Control Statements:.
Chapter 3 - Structured Program Development
Standard Notation to Scientific Notation
Structural Program Development: If, If-Else
Presentation transcript:

Computing with C# and the.NET Framework Chapter 3 Software Engineering with Control Structures

Figure 3.1 Java relational and equality operators Operator Symbol MeaningExample <less than31 < 25is false <=less than or equal to464 <= 7213is true >greater than-98 > -12is false >=greater than or equal to9 >= 99is false ==equal to9 == is false !=not equal to292 != 377is true

The if Statement Type bool Two values, true and false if (condition) if_true_statement The condition is a bool expression. If it is true then the if_true_statement will be executed if (x >2) y = x + 17;

Figure 3.2 The sequence control flow Entry int item1 = 25; int item2 = 12; Item2 = item1+15; Exit

Figure 3.3 Control flow for the if statement condition false if_true_statement true

Figure 3.4 Control Flow for Example 3.2 int hours = int.parse(Console.ReadLine()); Hour s >40 Console.WriteLine( “you worked {0} hours”, hours); False Console.WriteLine(“You “ + “worked overtime this week”) True

The if-else statement Choose between two alternatives if (condition)if ( x <= 20) if_true_statementx += 5;else if_false_statementx+=2;

Figure 3.5 Flow chart for the if-else statement Condition if_true_statementif_false_statement TrueFalse

Blocks Group a sequence of statements inside braces { x = 5; y = -8; z = x*y; } May use a block in an if or if-else statement

Figure 3.6 Flow chart for if statement with block, step 1 Z <= 10 True False x = 2; y = 7;

Figure 3.7 Flow chart if statement with block, step 2 Z <= 10 x = 2; True False y = 7;

Scientific Notation Small or large numbers are hard to read Use exponents instead 3.937E-8 instead of E12 instead of 5,880,000,000,000 E or e E12 or E+12

Type double Provides about 16 decimal places double length = E5; // exponent double height 1.83; // fixed +,-,*,/ operators

Formatted Output {0:E} Scientific default (three decimal places) {0:F2} Fixed-point, two decimal places {O:G} General, default (same as {0}) Uses scientific notation if exponent is less than -4 or if the exponent is greater or equal to the number of significant digits in the number

Figure 3.8 Conversion of mixed-mode expression 2.54 Original expression After Conversion

while statement Provides repetition while (condition) while_true_statement while (x < 10) x += 2; If x = 5, then x becomes 7, 9 before loop stops while (x < 10) x -= 4; //does not terminate if x starts at 5

Figure 3.9 Flow chart for the while loop Condition while_true_statement FalseTrue

Figure 3.10 Pseudocode for the sum of test scores problem Read the quantity of scores; while(count < quantity) { Read the next score; Add the score to the total so far; Increment the count of scores; } Display the quantity and the total;

Debugging Read the code carefully to determine where the error might be located Add WriteLine statements to get more information Test thoroughly Use a debugger if available