98-361 Lesson01 Slides
98-361 Lesson01 Slides
98-361 Lesson01 Slides
Lesson 1
Objectives
Skills/Concepts
Understanding Computer
Programming
Understanding Decision
Structures
Understanding Repetition
Structures
Understanding Exception
Handling
Algorithms
Algorithm refers to a method for
solving problems.
Common techniques for representing
an algorithms:
Flowchart
Flowcharts and Decision Tables
Decision Tables.
More precise than natural
languages
Flowcharts
A flowchart is a graphical
representation of an algorithm.
Common Flowchart Symbols
Start or end of an algorithm
Process or computational operation
Input or out operation
Decision making operation
Direction of the flow of control
Flowchart Example
A flowchart that compares two numbers:
Start
Input x
Input y
No
X > y?
Yes
Output
x
Stop
Output
y
Decision Table
Useful for large number of conditions
Compact and readable format
A decision table to calculating
discount:
Quantity <
10
Quantity <
50
Quantity <
100
Discount
5%
10%
15%
20%
Introducing C#
Microsoft .NET Framework
An Execution Environment
Reusable Class Libraries
Language Compilers
Structure of a C# Program
Elements of a C# Program
Select common elements of a C#
program:
Data Types
Types of data in a program. Common data types are int
(integers), char (single character value), float (floating
point values).
Variables
Constants
Arrays
Operators
Methods
Decision Structures
The if
Statement The if-else The switch
Statement Statement
The if Statement
The if statement will execute a given
sequence of statements only if the
corresponding Boolean expression
evaluates to true.
Repetition Structures
The while Loop
The do-while Loop
The for Loop
The foreach Loop
Recursion
Recursion
Recursion is a programming
technique that causes a method to
call itself in order to compute a
result.
Exception Handling
An exception is an unexpected error condition
that occurs during program execution.
When exception occurs, the runtime creates an
exception object and throws it.
Unless you catch the exception, the program
execution will terminate.
Exceptions are an object of the System.Exception
class or one of its derived classes.
Example: DivideByZeroException exception
object is thrown when the program attempts to
divide by zero.
Example: FileNotFoundException exception
object is throws when the program cannot find
a given file.
Unhandled Exceptions
What happens when the file
c:\data.txt is not found in this code?
try-catch-finally Example
Recap
Algorithms
Flowchart, decision table
C# Programming Language
Variables, constants, data types, arrays,
operators, methods
Decision Structures
if, if-else, switch
Repetition Structures
while, do-while, for, foreach, recursion
Exception Handling
try-catch, try-finally, try-catch