SlideShare a Scribd company logo
Introduction to Programming
Lesson 1
Objectives
Skills/Concepts MTA Exam Objectives
Understanding Computer
Programming
Understand computer storage and data
types (1.1)
Understanding Decision
Structures
Understand computer decision
structures (1.2)
Understanding Repetition
Structures
Identify the appropriate method for
handling repetition (1.3)
Understanding Exception
Handling
Understand error handling (1.4)
Algorithms
• Algorithm refers to a method for solving
problems.
• Common techniques for representing an
algorithms:
– Flowchart
– Decision Tables.
Flowcharts and Decision Tables
More precise than natural
languages
Less formal and easier to use than
programming 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
X > y?
Output x
Stop
Output y
No
Yes
Decision Table
• Useful for large number of conditions
• Compact and readable format
• A decision table to calculating discount:
Quantity < 10 Y N N N
Quantity < 50 Y Y N N
Quantity < 100 Y Y Y N
Discount 5% 10% 15% 20%
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
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.
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.
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.
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.
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.
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.
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.
The foreach Loop
• The foreach loop is an enhanced version of
the for loop for iterating through collections
such as arrays and lists.
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?
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
– 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

More Related Content

Similar to Programming with C++ (20)

PPT
Exception
abhay singh
 
PPTX
Lecture 1 Try Throw Catch.pptx
VishuSaini22
 
PPTX
Java Exceptions and Exception Handling
MaqdamYasir
 
PPT
Unit iii
snehaarao19
 
PPTX
Algorithm & data structure lec2
Abdul Khan
 
PDF
Algorithm Analysis.pdf
NayanChandak1
 
PDF
Introduction to programming by MUFIX Commnity
mazenet
 
PDF
Introduction To Programming (2009 2010)
SiliconExpert Technologies
 
PPTX
Advanced python
Novita Sari
 
PPT
Exception handling
pooja kumari
 
PDF
Astu DSA week 1-2.pdf
HailuSeyoum1
 
PPTX
Exception handling in ASP .NET
baabtra.com - No. 1 supplier of quality freshers
 
PPT
exceptionvdffhhhccvvvv-handling-in-java.ppt
yjrtytyuu
 
PPTX
Tutorial PM.pptx
ssusera5685d
 
PPTX
ANALYSIS AND DESIGN OF ALGORITHMS -M1-PPT
AIET
 
PPTX
What is Exception Handling?
Syed Bahadur Shah
 
PPTX
FPL -Part 2 ( Sem - I 2013)
Yogesh Deshpande
 
PPTX
Module 4-packages and exceptions in java.pptx
Radhika Venkatesh
 
PPTX
Introduction to C ++.pptx
VAIBHAVKADAGANCHI
 
PPT
Testing
nazeer pasha
 
Exception
abhay singh
 
Lecture 1 Try Throw Catch.pptx
VishuSaini22
 
Java Exceptions and Exception Handling
MaqdamYasir
 
Unit iii
snehaarao19
 
Algorithm & data structure lec2
Abdul Khan
 
Algorithm Analysis.pdf
NayanChandak1
 
Introduction to programming by MUFIX Commnity
mazenet
 
Introduction To Programming (2009 2010)
SiliconExpert Technologies
 
Advanced python
Novita Sari
 
Exception handling
pooja kumari
 
Astu DSA week 1-2.pdf
HailuSeyoum1
 
Exception handling in ASP .NET
baabtra.com - No. 1 supplier of quality freshers
 
exceptionvdffhhhccvvvv-handling-in-java.ppt
yjrtytyuu
 
Tutorial PM.pptx
ssusera5685d
 
ANALYSIS AND DESIGN OF ALGORITHMS -M1-PPT
AIET
 
What is Exception Handling?
Syed Bahadur Shah
 
FPL -Part 2 ( Sem - I 2013)
Yogesh Deshpande
 
Module 4-packages and exceptions in java.pptx
Radhika Venkatesh
 
Introduction to C ++.pptx
VAIBHAVKADAGANCHI
 
Testing
nazeer pasha
 

Recently uploaded (20)

PDF
Performance Report Sample (Draft7).pdf
AmgadMaher5
 
PDF
AUDITABILITY & COMPLIANCE OF AI SYSTEMS IN HEALTHCARE
GAHI Youssef
 
PDF
Choosing the Right Database for Indexing.pdf
Tamanna
 
PPTX
Rocket-Launched-PowerPoint-Template.pptx
Arden31
 
PPTX
apidays Munich 2025 - Building Telco-Aware Apps with Open Gateway APIs, Subhr...
apidays
 
DOC
MATRIX_AMAN IRAWAN_20227479046.docbbbnnb
vanitafiani1
 
PDF
Context Engineering vs. Prompt Engineering, A Comprehensive Guide.pdf
Tamanna
 
PDF
How to Avoid 7 Costly Mainframe Migration Mistakes
JP Infra Pvt Ltd
 
PPTX
Hadoop_EcoSystem slide by CIDAC India.pptx
migbaruget
 
PPTX
Exploring Multilingual Embeddings for Italian Semantic Search: A Pretrained a...
Sease
 
PDF
apidays Helsinki & North 2025 - REST in Peace? Hunting the Dominant Design fo...
apidays
 
PPT
1 DATALINK CONTROL and it's applications
karunanidhilithesh
 
PDF
Avatar for apidays apidays PRO June 07, 2025 0 5 apidays Helsinki & North 2...
apidays
 
PDF
R Cookbook - Processing and Manipulating Geological spatial data with R.pdf
OtnielSimopiaref2
 
PPTX
AI Project Cycle and Ethical Frameworks.pptx
RiddhimaVarshney1
 
PPTX
Usage of Power BI for Pharmaceutical Data analysis.pptx
Anisha Herala
 
PPTX
This PowerPoint presentation titled "Data Visualization: Turning Data into In...
HemaDivyaKantamaneni
 
PPT
01 presentation finyyyal معهد معايره.ppt
eltohamym057
 
PPTX
Introduction to Artificial Intelligence.pptx
StarToon1
 
PPTX
DATA-COLLECTION METHODS, TYPES AND SOURCES
biggdaad011
 
Performance Report Sample (Draft7).pdf
AmgadMaher5
 
AUDITABILITY & COMPLIANCE OF AI SYSTEMS IN HEALTHCARE
GAHI Youssef
 
Choosing the Right Database for Indexing.pdf
Tamanna
 
Rocket-Launched-PowerPoint-Template.pptx
Arden31
 
apidays Munich 2025 - Building Telco-Aware Apps with Open Gateway APIs, Subhr...
apidays
 
MATRIX_AMAN IRAWAN_20227479046.docbbbnnb
vanitafiani1
 
Context Engineering vs. Prompt Engineering, A Comprehensive Guide.pdf
Tamanna
 
How to Avoid 7 Costly Mainframe Migration Mistakes
JP Infra Pvt Ltd
 
Hadoop_EcoSystem slide by CIDAC India.pptx
migbaruget
 
Exploring Multilingual Embeddings for Italian Semantic Search: A Pretrained a...
Sease
 
apidays Helsinki & North 2025 - REST in Peace? Hunting the Dominant Design fo...
apidays
 
1 DATALINK CONTROL and it's applications
karunanidhilithesh
 
Avatar for apidays apidays PRO June 07, 2025 0 5 apidays Helsinki & North 2...
apidays
 
R Cookbook - Processing and Manipulating Geological spatial data with R.pdf
OtnielSimopiaref2
 
AI Project Cycle and Ethical Frameworks.pptx
RiddhimaVarshney1
 
Usage of Power BI for Pharmaceutical Data analysis.pptx
Anisha Herala
 
This PowerPoint presentation titled "Data Visualization: Turning Data into In...
HemaDivyaKantamaneni
 
01 presentation finyyyal معهد معايره.ppt
eltohamym057
 
Introduction to Artificial Intelligence.pptx
StarToon1
 
DATA-COLLECTION METHODS, TYPES AND SOURCES
biggdaad011
 
Ad

Programming with C++

  • 2. Objectives Skills/Concepts MTA Exam Objectives Understanding Computer Programming Understand computer storage and data types (1.1) Understanding Decision Structures Understand computer decision structures (1.2) Understanding Repetition Structures Identify the appropriate method for handling repetition (1.3) Understanding Exception Handling Understand error handling (1.4)
  • 3. Algorithms • Algorithm refers to a method for solving problems. • Common techniques for representing an algorithms: – Flowchart – Decision Tables. Flowcharts and Decision Tables More precise than natural languages Less formal and easier to use than programming languages
  • 4. 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
  • 5. Flowchart Example • A flowchart that compares two numbers: Start Input x Input y X > y? Output x Stop Output y No Yes
  • 6. Decision Table • Useful for large number of conditions • Compact and readable format • A decision table to calculating discount: Quantity < 10 Y N N N Quantity < 50 Y Y N N Quantity < 100 Y Y Y N Discount 5% 10% 15% 20%
  • 7. 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
  • 8. Structure of a C# Program
  • 9. 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.
  • 10. Decision Structures The if Statement The if-else Statement The switch Statement
  • 11. The if Statement • The if statement will execute a given sequence of statements only if the corresponding Boolean expression evaluates to true.
  • 12. 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.
  • 13. 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.
  • 14. Repetition Structures The while Loop The do-while Loop The for Loop The foreach Loop Recursion
  • 15. The while Loop • The while loop repeatedly executes a block of statements until a specified Boolean expression evaluates to false.
  • 16. 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.
  • 17. 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.
  • 18. The foreach Loop • The foreach loop is an enhanced version of the for loop for iterating through collections such as arrays and lists.
  • 19. Recursion • Recursion is a programming technique that causes a method to call itself in order to compute a result.
  • 20. 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.
  • 21. Unhandled Exceptions • What happens when the file c:data.txt is not found in this code?
  • 22. 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.
  • 24. 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.
  • 26. 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