Introduction to Programming

Slides:



Advertisements
Similar presentations
Introduction to Programming Lesson 1. Objectives Skills/ConceptsMTA Exam Objectives Understanding Computer Programming Understand computer storage and.
Advertisements

Control Structures Control structures are used to manage the order in which statements in computer programs will be executed Three different approaches.
By Sam Nasr Nasr Information Systems May 14, 2013.
True or false A variable of type char can hold the value 301. ( F )
5-1 Flow of Control Recitation-01/25/2008  CS 180  Department of Computer Science  Purdue University.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Conditional Statements Control Structures.
1 Exception Handling Introduction to Exception Handling Exception Handling in PLs –Ada –C++ –Java Sebesta Chapter 14.
1 Chapter Eight Exception Handling. 2 Objectives Learn about exceptions and the Exception class How to purposely generate a SystemException Learn about.
Understanding Events and Exceptions Lesson 3. Objective Domain Matrix Skills/ConceptsMTA Exam Objectives Understand events and event handling Understand.
CIS 199 Test 01 Review. Computer Hardware  Central Processing Unit (CPU)  Brains  Operations performed here  Main Memory (RAM)  Scratchpad  Work.
Control Structures – Selection Chapter 4 2 Chapter Topics  Control Structures  Relational Operators  Logical (Boolean) Operators  Logical Expressions.
Lecture 4 C Program Control Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
CPS120: Introduction to Computer Science Decision Making in Programs.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Introduction to Exception Handling and Defensive Programming.
CPS120: Introduction to Computer Science Decision Making in Programs.
2Object-Oriented Program Development Using C++ 3 Basic Loop Structures Loops repeat execution of an instruction set Three repetition structures: while,
Chapter 7 Selection Dept of Computer Engineering Khon Kaen University.
8-1 Compilers Compiler A program that translates a high-level language program into machine code High-level languages provide a richer set of instructions.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
 Control Flow statements ◦ Selection statements ◦ Iteration statements ◦ Jump statements.
CPS120: Introduction to Computer Science Decision Making in Programs.
Copyright © Curt Hill Flow of Control A Quick Overview.
Exception Handling How to handle the runtime errors.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
Introduction to Programming Lesson 1. Algorithms Algorithm refers to a method for solving problems. Common techniques for representing an algorithms:
Introduction to Programming G50PRO University of Nottingham Unit 6 : Control Flow Statements 2 Paul Tennent
C Program Control September 15, OBJECTIVES The essentials of counter-controlled repetition. To use the for and do...while repetition statements.
1 ENERGY 211 / CME 211 Lecture 3 September 26, 2008.
C++ Lesson 1.
Information and Computer Sciences University of Hawaii, Manoa
Chapter 4 – C Program Control
Java Language Basics.
CIS 200 Test 01 Review.
Objectives You should be able to describe: Interactive Keyboard Input
The switch Statement, and Introduction to Looping
Exceptions, Templates, and the Standard Template Library (STL)
Why exception handling in C++?
Multiple variables can be created in one declaration
CS1371 Introduction to Computing for Engineers
Prof: Dr. Shu-Ching Chen TA: Samira Pouyanfar Hector Cen Fall 2017
BY GAWARE S.R. COMPUTER SCI. DEPARTMENT
Indexer AKEEL AHMED.
Programming Fundamentals
Expressions and Control Flow in JavaScript
Control Structures – Selection
11/10/2018.
Chapter 5 - Functions Outline 5.1 Introduction
Arrays, For loop While loop Do while loop
Repeating Instructions And Advance collection
MSIS 655 Advanced Business Applications Programming
CNS 3260 C# .NET Software Development
Starting JavaProgramming
Topics Introduction to File Input and Output
Exception Handling and Reading / Writing Files
Introduction to Primitive Data types
Coding Concepts (Basics)
Chapter 6 Control Statements: Part 2
Computer Science Core Concepts
2. Second Step for Learning C++ Programming • Data Type • Char • Float
Chapter8: Statement-Level Control Structures April 9, 2019
Dr. Sampath Jayarathna Cal Poly Pomona
Arrays October 6, 2006 ComS 207: Programming I (in Java)
Chapter 4 - Program Control
Chap 7. Advanced Control Statements in Java
Topics Introduction to File Input and Output
Chapter 11: Exception Handling
ICS103: Programming in C 5: Repetition and Loop Statements
Introduction to Primitive Data types
Presentation transcript:

Introduction to Programming Lesson 1

Microsoft .NET Framework Introducing C# Microsoft .NET Framework An Execution Environment Reusable Class Libraries Language Compilers The C# Programming Language Part of the .NET Framework High-level Language Program needs to be compiled before they can be executed. Case sensitive Tip: Add your own speaker notes here.

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 Provides temporary storage during program execution. int number = 10; Constants Data fields whose value cannot be modified. const int i = 10; Arrays A collection of items in which each item can be accessed by a unique index. int[] numbers = { 1, 2, 3, 4, 5 }; Operators Symbols that specify which operation to perform on operands before returning a result. Methods Methods are code blocks containing a series of statements. Methods can receive input via arguments and can return a value to the caller.

The if Statement The switch Statement The if-else Statement Decision Structures The if Statement The if-else Statement The switch Statement

The if Statement The if statement will execute a given sequence of statements only if the corresponding Boolean expression evaluates to true. Tip: Add your own speaker notes here.

The if-else Statement The if-else statement allows your program to perform one action if the Boolean expression evaluates to true and a different action if the Boolean expression evaluates to false. Tip: Add your own speaker notes here.

The switch Statement The switch statement allows multi-way branching. In many cases, using a switch statement can simplify a complex combination of if-else statements. Tip: Add your own speaker notes here.

Repetition Structures The while Loop The do-while Loop The for Loop The foreach Loop Recursion

The while Loop The while loop repeatedly executes a block of statements until a specified Boolean expression evaluates to false. Tip: Add your own speaker notes here.

The do-while Loop The do-while loop repeatedly executes a block of statements until a specified Boolean expression evaluates to false. The do-while loop tests the condition at the bottom of the loop. Tip: Add your own speaker notes here.

The for Loop The for loop combines the three elements of iteration—the initialization expression, the termination condition expression, and the counting expression—into a more readable code. Tip: Add your own speaker notes here.

The foreach Loop The foreach loop is an enhanced version of the for loop for iterating through collections such as arrays and lists. Tip: Add your own speaker notes here.

Recursion Recursion is a programming technique that causes a method to call itself in order to compute a result. Tip: Add your own speaker notes here.

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. Tip: Add your own speaker notes here.

Unhandled Exceptions What happens when the file c:\data.txt is not found in this code?

Handling Exceptions with try-catch Place the code that throws the exceptions inside a try block. Place the code that handles an exception inside a catch block. You can have more than one catch blocks for each try block. Each catch block handles a specific exception type. A try block must have at least a catch block or a finally block associated with it.

Exception Handling Sample

The finally Block The finally block is used in association with the try block. The finally block is always executed regardless of whether an exception is thrown. The finally block is often used to write clean-up code.

try-catch-finally Example

Recap Algorithms C# Programming Language Decision Structures 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