SlideShare a Scribd company logo
Introduction to Programming
Lecture # 1
Computer Program
• A computer program (software, or just a program) is a sequence of
instructions written to perform a specified task with a computer.
• A computer requires programs to function, typically executing the
program's instructions in a central processor.
• The program has an executable form that the computer can use directly to
execute the instructions. The same program in its human-readable source
code form, from which executable programs are derived (e.g., compiled)
• Computer source code is often written by computer programmers in
programming languages(C, C++, java)
• Source code may be converted into an executable file (sometimes called
an executable program or a binary) by a compiler and later executed by a
central processing unit.
• Alternatively, computer programs may be executed with the aid of an
interpreter, or may be embedded directly into hardware.
What is a Programming Language?
A vocabulary and set of
grammatical rules for instructing a
computer to perform specific tasks
Compiler
• Compiler is a computer program (or set of programs) that
transforms source code written in a programming language (the
source language) into another computer language (the target
language, often having a binary form known as object code).
• The name "compiler" is primarily used for programs that translate
source code from a high-level programming language to a lower
level language (e.g., assembly language or machine code).
Introduction to C++
• Most widely used programming language in existence
• Used in professional applications development because of its
immense flexibility and power
• Combines the facility for efficient procedural programming that it
inherits from C, with a powerful object-oriented programming
features
• Provides extensive facilities in its standard Library
What is an algorithm?
• In computer programming terms, an algorithm is a set of
well-defined instructions to solve a particular problem. It
takes a set of input(s) and produces the desired output.
Quality of Good Algorithm
• Input and output should be defined precisely.
• Each step in the algorithm should be clear and
unambiguous.
• Algorithms should be most effective among many different ways to
solve a problem.
• An algorithm shouldn't include computer code. Instead, the algorithm
should be written in such a way that it can be used in different
programming languages.
Example
• Write an algorithm to add two number.
Solution
Step 1: Start
Step 2: Declare variables num1, num2 and sum.
Step 3: Read values num1 and num2.
Step 4: Add num1 and num2 and assign the result to sum.
sum←num1+num2
Step 5: Display sum
Step 6: Stop
Flowchart
A flowchart is a diagrammatic representation of an algorithm. A
flowchart can be helpful for both writing programs and
explaining the program to others.
Symbol Used in Flow Chart
Flow chart to add two numbers
Example 2
Write an algorithm and draw a flowchart that will read the two
sides of a rectangle and calculate its area.
Solution
Step 1 start
Step2 : Declare a variable length and width
Step3: Reads the value of length and width
Step4: Calculate Area to multiply length and width;
Step5: Print A
Step 6:Stop
Flow chart
Example 3
Algorithm 2: Find the largest number among three numbers
Algorithm
Algorithm 2: Find the largest number among three numbers
Alogrithm
1. Start
2. Ask the user enter three integers a,b,c
3. Read the three values a,b,c
4. Check if a is greater than b
5. If true, then check a is greater than c
1. if true, then print ‘a’ as the greatest number
2. if false ,then print ‘c’ as the greatest number
6. If false, then check if b is greater than c
1. if true then print ‘b’ as the greatest number
2. if false, then print ‘C’ as the greatest number
7. Stop
Flowchart
Pseudocode
Pseudocode is an informal way of programming description
that does not require any strict programming language syntax
or underlying technology considerations. It is used for creating
an outline or a rough draft of a program. Pseudocode
summarizes a program’s flow, but excludes underlying details.
System designers write pseudocode to ensure that
programmers understand a software project's requirements
and align code accordingly.
Example
.Area of rectangle()
Begin
Read: Width & Length
Area=Width * Length
Print area
End
Example
Procedure: FindLargestNumber(a,b,c)
Begin
Read : a,b,c //(input)
If (a>b)
if (a>c)
Return a
Else
End
A Simple C++ Program
#include <iostream>
using namespace std;
int main( )
{
cout<<“Assalam-o-Alaikum";
return 0;
}//end of the main
<< is called insertion operator
>> is called extraction operator
Preprocessor Directive
Using Directive
Directives
1. Preprocessor Directive
- looks like a program statement but it’s not
- It is an instruction to the compiler
- A part of the compiler called preprocessor deals with these
directives before it begins the real compilation process
- The preprocessor directive #include tells the compiler to
insert another file into your source file (it inserts code of file
named after it as it is part of the source file)
2. Using Directive
- A C++ program can be divided into different namespaces
- A namespace is a part of the program in which certain names
are recognized
Keywords
• Reserved words in C++ are called keywords, have
special significance within the language
• Words “return” and “namespace” discussed in previous
example are examples of keywords
• Names for different entities that we use in our program
must not be same as any of the keywords in C++
Statements and Statement Blocks
• A statement is an instruction to the computer to do something. e.g.
adding two numbers or printing a string to the screen.
• Statements are the basic units for specifying
– What a program is to do, and
– The data elements it acts upon
• Most C++ statements end with a semicolon (;)
• Several statements can be enclosed between a pair of curly braces {} –
referred to as a statement block
Characters and Character Sets
• In your C++ programs you can use:
– Upper case letters ( A to Z )
– Lower case letters ( a to z )
– Space character
– Control characters ( new line, horizontal and vertical
tab)
– Special characters ( - [ ] {} () ~! # $%^&*+|  /.,<>:;’” )
Escape Sequences
• When using characters in the program certain characters
can be problematic
• Like you cannot use a “tab” or a “new line” directly as
characters
• You can enter control characters as constants by means
of an escape sequence
• For example:
– n for new line, t for horizontal tab
–  for backslash, ” for double quote
Escape Sequences
• An escape sequence is a sequence of characters that does not
represent itself when used inside a character or string literal, but is
translated into another character or a sequence of characters that
may be difficult or impossible to represent directly.
Escape Sequences
• The output we get is determined by what’s between
the outer double quotes in the statement
• cout<<“Assalam-o-Alaikum";
• A string of characters between a pair of double
quotes is called a string literal
• Double quote characters just identify the beginning
and end of the string literal and not part of the string
Escape Sequences
Escape Sequence Program
Output
Documenting the Programs
• Documentation of programs is extremely important -- it can be done
using comments
• Two ways to comment our programs
– Single-line comment
– Multi-line comment (Block comment)
• Example,
//You must not nest multi-line comments
/*This starts an outer comment
/*This starts an inner comment, but the start will not be recognized
because of the outer comment.
Instead, the end of the inner comment will be interpreted as the end
of the outer comment.*/
This will cause the compiler to try to compile this part of the outer
comment as C++ code. */
Sample Program
• Documentation of programs is extremely important -- it can be done
using comments
• Two ways to comment our programs
– Single-line comment
– Multi-line comment (Block comment)
• Example,
//You must not nest multi-line comments
/*This starts an outer comment
/*This starts an inner comment, but the start will not be recognized
because of the outer comment.
Instead, the end of the inner comment will be interpreted as the end
of the outer comment.*/
This will cause the compiler to try to compile this part of the outer
comment as C++ code. */
The Standard Library
• The standard library contains substantial amount of
functions and other functionality that support the basic
capabilities of C++
• To use C++ effectively, you should make sure that you
have a good familiarity with the contents of the standard
library
• The definitions and declarations necessary to use
standard library facilities appear in the standard header
files
• Everything in the C++ standard library is defined within
the namespace std.
Summary
• A program in C++ consists of at least one function, which is called
main()
• The executable part of a function is made up of statements
contained between a pair of braces {}
• Basic unit for specifying what our program is to do and the data
elements is called statement
• A pair of braces {----} defines a statement block
• In C++, a statement is terminated by a semicolon (;)
• Keywords are a set of reserve words that have specific meanings in
C++. No entity in our program can have a name similar to a
keyword
• The code containing functions is usually stored in files with the
extension .cpp

More Related Content

PPT
490450755-Chapter-2.ppt
PPT
490450755-Chapter-2.ppt
PPTX
POLITEKNIK MALAYSIA
PPT
Chapter-2 edited on Programming in Can refer this ppt
PPTX
Introduction Of C++
PPTX
1.0 Introduction to C programming for all first year courses.pptx
PPTX
Intro in understanding to C programming .pptx
PPTX
Intro in understanding to C programming .pptx
490450755-Chapter-2.ppt
490450755-Chapter-2.ppt
POLITEKNIK MALAYSIA
Chapter-2 edited on Programming in Can refer this ppt
Introduction Of C++
1.0 Introduction to C programming for all first year courses.pptx
Intro in understanding to C programming .pptx
Intro in understanding to C programming .pptx

Similar to Introduction To Programming subject1.ppt (20)

PPTX
Presentation c++
PPTX
Object oriented programming 7 first steps in oop using c++
PPTX
structure of a c program - slideshare.pptx
PPTX
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
PPTX
PPTX
PDF
Learning the C Language
PPTX
computer programming omputer programming
PPTX
PPTX
Lecture 1
PPTX
C lang7age programming powerpoint presentation
PPTX
Unit-1 (introduction to c language).pptx
PPTX
Unit ii
PPTX
C++ Introduction to basic C++ IN THIS YOU WOULD KHOW ABOUT BASIC C++
PPT
Lecture 01 2017
PPTX
C programming
PPTX
C programming
PPTX
C Programming Unit-1
PPTX
UNIT 5 C PROGRAMMING, PROGRAM STRUCTURE
Presentation c++
Object oriented programming 7 first steps in oop using c++
structure of a c program - slideshare.pptx
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
Learning the C Language
computer programming omputer programming
Lecture 1
C lang7age programming powerpoint presentation
Unit-1 (introduction to c language).pptx
Unit ii
C++ Introduction to basic C++ IN THIS YOU WOULD KHOW ABOUT BASIC C++
Lecture 01 2017
C programming
C programming
C Programming Unit-1
UNIT 5 C PROGRAMMING, PROGRAM STRUCTURE
Ad

Recently uploaded (20)

PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Modernizing your data center with Dell and AMD
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
A Presentation on Artificial Intelligence
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Encapsulation theory and applications.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
KodekX | Application Modernization Development
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
20250228 LYD VKU AI Blended-Learning.pptx
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
NewMind AI Weekly Chronicles - August'25 Week I
Modernizing your data center with Dell and AMD
Diabetes mellitus diagnosis method based random forest with bat algorithm
NewMind AI Monthly Chronicles - July 2025
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
A Presentation on Artificial Intelligence
Review of recent advances in non-invasive hemoglobin estimation
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Encapsulation theory and applications.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Encapsulation_ Review paper, used for researhc scholars
KodekX | Application Modernization Development
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Digital-Transformation-Roadmap-for-Companies.pptx
Understanding_Digital_Forensics_Presentation.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
Ad

Introduction To Programming subject1.ppt

  • 2. Computer Program • A computer program (software, or just a program) is a sequence of instructions written to perform a specified task with a computer. • A computer requires programs to function, typically executing the program's instructions in a central processor. • The program has an executable form that the computer can use directly to execute the instructions. The same program in its human-readable source code form, from which executable programs are derived (e.g., compiled) • Computer source code is often written by computer programmers in programming languages(C, C++, java) • Source code may be converted into an executable file (sometimes called an executable program or a binary) by a compiler and later executed by a central processing unit. • Alternatively, computer programs may be executed with the aid of an interpreter, or may be embedded directly into hardware.
  • 3. What is a Programming Language? A vocabulary and set of grammatical rules for instructing a computer to perform specific tasks
  • 4. Compiler • Compiler is a computer program (or set of programs) that transforms source code written in a programming language (the source language) into another computer language (the target language, often having a binary form known as object code). • The name "compiler" is primarily used for programs that translate source code from a high-level programming language to a lower level language (e.g., assembly language or machine code).
  • 5. Introduction to C++ • Most widely used programming language in existence • Used in professional applications development because of its immense flexibility and power • Combines the facility for efficient procedural programming that it inherits from C, with a powerful object-oriented programming features • Provides extensive facilities in its standard Library
  • 6. What is an algorithm? • In computer programming terms, an algorithm is a set of well-defined instructions to solve a particular problem. It takes a set of input(s) and produces the desired output.
  • 7. Quality of Good Algorithm • Input and output should be defined precisely. • Each step in the algorithm should be clear and unambiguous. • Algorithms should be most effective among many different ways to solve a problem. • An algorithm shouldn't include computer code. Instead, the algorithm should be written in such a way that it can be used in different programming languages.
  • 8. Example • Write an algorithm to add two number.
  • 9. Solution Step 1: Start Step 2: Declare variables num1, num2 and sum. Step 3: Read values num1 and num2. Step 4: Add num1 and num2 and assign the result to sum. sum←num1+num2 Step 5: Display sum Step 6: Stop
  • 10. Flowchart A flowchart is a diagrammatic representation of an algorithm. A flowchart can be helpful for both writing programs and explaining the program to others.
  • 11. Symbol Used in Flow Chart
  • 12. Flow chart to add two numbers
  • 13. Example 2 Write an algorithm and draw a flowchart that will read the two sides of a rectangle and calculate its area.
  • 14. Solution Step 1 start Step2 : Declare a variable length and width Step3: Reads the value of length and width Step4: Calculate Area to multiply length and width; Step5: Print A Step 6:Stop
  • 16. Example 3 Algorithm 2: Find the largest number among three numbers
  • 17. Algorithm Algorithm 2: Find the largest number among three numbers
  • 18. Alogrithm 1. Start 2. Ask the user enter three integers a,b,c 3. Read the three values a,b,c 4. Check if a is greater than b 5. If true, then check a is greater than c 1. if true, then print ‘a’ as the greatest number 2. if false ,then print ‘c’ as the greatest number 6. If false, then check if b is greater than c 1. if true then print ‘b’ as the greatest number 2. if false, then print ‘C’ as the greatest number 7. Stop
  • 20. Pseudocode Pseudocode is an informal way of programming description that does not require any strict programming language syntax or underlying technology considerations. It is used for creating an outline or a rough draft of a program. Pseudocode summarizes a program’s flow, but excludes underlying details. System designers write pseudocode to ensure that programmers understand a software project's requirements and align code accordingly.
  • 21. Example .Area of rectangle() Begin Read: Width & Length Area=Width * Length Print area End
  • 22. Example Procedure: FindLargestNumber(a,b,c) Begin Read : a,b,c //(input) If (a>b) if (a>c) Return a Else End
  • 23. A Simple C++ Program #include <iostream> using namespace std; int main( ) { cout<<“Assalam-o-Alaikum"; return 0; }//end of the main << is called insertion operator >> is called extraction operator Preprocessor Directive Using Directive
  • 24. Directives 1. Preprocessor Directive - looks like a program statement but it’s not - It is an instruction to the compiler - A part of the compiler called preprocessor deals with these directives before it begins the real compilation process - The preprocessor directive #include tells the compiler to insert another file into your source file (it inserts code of file named after it as it is part of the source file) 2. Using Directive - A C++ program can be divided into different namespaces - A namespace is a part of the program in which certain names are recognized
  • 25. Keywords • Reserved words in C++ are called keywords, have special significance within the language • Words “return” and “namespace” discussed in previous example are examples of keywords • Names for different entities that we use in our program must not be same as any of the keywords in C++
  • 26. Statements and Statement Blocks • A statement is an instruction to the computer to do something. e.g. adding two numbers or printing a string to the screen. • Statements are the basic units for specifying – What a program is to do, and – The data elements it acts upon • Most C++ statements end with a semicolon (;) • Several statements can be enclosed between a pair of curly braces {} – referred to as a statement block
  • 27. Characters and Character Sets • In your C++ programs you can use: – Upper case letters ( A to Z ) – Lower case letters ( a to z ) – Space character – Control characters ( new line, horizontal and vertical tab) – Special characters ( - [ ] {} () ~! # $%^&*+| /.,<>:;’” )
  • 28. Escape Sequences • When using characters in the program certain characters can be problematic • Like you cannot use a “tab” or a “new line” directly as characters • You can enter control characters as constants by means of an escape sequence • For example: – n for new line, t for horizontal tab – for backslash, ” for double quote
  • 29. Escape Sequences • An escape sequence is a sequence of characters that does not represent itself when used inside a character or string literal, but is translated into another character or a sequence of characters that may be difficult or impossible to represent directly.
  • 31. • The output we get is determined by what’s between the outer double quotes in the statement • cout<<“Assalam-o-Alaikum"; • A string of characters between a pair of double quotes is called a string literal • Double quote characters just identify the beginning and end of the string literal and not part of the string Escape Sequences
  • 34. Documenting the Programs • Documentation of programs is extremely important -- it can be done using comments • Two ways to comment our programs – Single-line comment – Multi-line comment (Block comment) • Example, //You must not nest multi-line comments /*This starts an outer comment /*This starts an inner comment, but the start will not be recognized because of the outer comment. Instead, the end of the inner comment will be interpreted as the end of the outer comment.*/ This will cause the compiler to try to compile this part of the outer comment as C++ code. */
  • 35. Sample Program • Documentation of programs is extremely important -- it can be done using comments • Two ways to comment our programs – Single-line comment – Multi-line comment (Block comment) • Example, //You must not nest multi-line comments /*This starts an outer comment /*This starts an inner comment, but the start will not be recognized because of the outer comment. Instead, the end of the inner comment will be interpreted as the end of the outer comment.*/ This will cause the compiler to try to compile this part of the outer comment as C++ code. */
  • 36. The Standard Library • The standard library contains substantial amount of functions and other functionality that support the basic capabilities of C++ • To use C++ effectively, you should make sure that you have a good familiarity with the contents of the standard library • The definitions and declarations necessary to use standard library facilities appear in the standard header files • Everything in the C++ standard library is defined within the namespace std.
  • 37. Summary • A program in C++ consists of at least one function, which is called main() • The executable part of a function is made up of statements contained between a pair of braces {} • Basic unit for specifying what our program is to do and the data elements is called statement • A pair of braces {----} defines a statement block • In C++, a statement is terminated by a semicolon (;) • Keywords are a set of reserve words that have specific meanings in C++. No entity in our program can have a name similar to a keyword • The code containing functions is usually stored in files with the extension .cpp

Editor's Notes

  • #3: 1. A programming language is a notation for writing programs, which are specifications of a computation or algorithm. 2. A programming language is used to write computer programs such as Applications, Utilities, Servers, Systems Programs A program is written as a series of human understandable computer instructions that can be read by a compiler and linker, and translated into machine code so that a computer can understand and run it.
  • #23: A stream is an abstraction that refers to the flow of data. Preprocessor directives are orders that we include within the code of our programs that are not instructions for the program itself but for the preprocessor. The preprocessor is executed automatically by the compiler when we compile a program in C++ and is in charge of making the first verifications and digestions of the program's code.
  • #24: using namespace std; says that all the program statements that follow are within the std namespace. Various program components such as cout are declared within this namespace. If we don’t use the using directive, we would need to append the std name to many program elements; For example; std::cout <<“Assalam-o-Alaikum”; To avoid adding std:: dozens of times in programs we use the using directive instead.
  • #26: Example declares the name sum to be a variable of type int (declaration)
  • #27: 8-bit extended ASCII character encoding