KEMBAR78
lecture Slides - Week 1.programming fundamentals | PPTX
1
Programming
Fundamentals
LEC TUR E : 1 & 2
WE E K: 1
INS TR UC TO R : M R . A B D UL KHA LI Q
B OO K: C ++, HOW TO PRO GR A M BY D E I TE L 9 E
2
Outline
Introduction to problem solving
Von Neumann Architecture
Computer Organization
History Of Programming Languages
Integrated Development Environment (IDE)
Ways Of Writing The Algorithm
The Concept And Features Of The Algorithm
The C++ programming language
Data Types and Variables in C++
What is a Computer?
A computer is a device capable of performing computations and making logical decisions
Computers process data under the control of sets of instructions called computer programs
Hardware – various devices comprising a computer
◦ Keyboard, screen, mouse, disks, memory, CD-ROM, and processing units
Software – programs that run a computer OR set of instruction+documentation.
3
PROGRAMMING
A programming language is a computer language programmers use to develop software
programs, scripts, or other sets of instructions for computers to execute.
Although many languages share similarities, each has its own syntax. Once a programmer learns
the languages rules, syntax, and structure, they write the source code in a text editor or IDE.
Then, the programmer often compiles the code into machine language that can be understood by
the computer. Scripting languages, which do not require a compiler, use an interpreter to execute
the script.
4
5
Introduction to Problem Solving
Solving problems is the core of computer science. Programmers must first understand how a
human solves a problem, then understand how to translate this "algorithm" into something a
computer can do, and finally how to "write" the specific syntax (required by a computer) to get
the job done. It is sometimes the case that a machine will solve a problem in a completely
different way than a human.
6
Computer Programmers are problem solvers. In order to solve a problem on a computer you must:
1.Know how to represent the information (data) describing the problem.
2.Determine the steps to transform the information from one representation into another.
Von Neumann Architecture
Von Neumann architecture was first published by John von Neumann in 1945.
His computer architecture design consists of a Control Unit, Arithmetic and Logic Unit (ALU),
Memory Unit, Registers and Inputs/Outputs.
Von Neumann architecture is based on the stored-program computer concept, where instruction
data and program data are stored in the same memory. This design is still used in
most computers produced today.
7
8
Central Processing Unit (CPU)
The Central Processing Unit (CPU) is the electronic circuit responsible for executing the instructions of a
computer program.
It is sometimes referred to as the microprocessor or processor.
The CPU contains the ALU, CU and a variety of registers.
Registers
Registers are high speed storage areas in the CPU. All data must be stored in a register before it can be
processed.
Arithmetic and Logic Unit (ALU)
The ALU allows arithmetic (add, subtract etc) and logic (AND, OR, NOT etc) operations to be carried out.
Control Unit (CU)
The control unit controls the operation of the computer’s ALU, memory and input/output devices, telling
them how to respond to the program instructions it has just read and interpreted from the memory unit.
The control unit also provides the timing and control signals required by other computer components.
9
Computer Organization
Six logical units in every computer:
1. Input unit
◦ obtains information from input devices (keyboard, mouse)
2. Output unit
◦ outputs information (to screen, to printer, to control other devices)
3. Memory unit
◦ rapid access, low capacity, stores input information
4. Arithmetic and logic unit (ALU)
◦ performs arithmetic calculations and logic decisions
5. Central processing unit (CPU)
◦ supervises and coordinates the other sections of the computer
6. Secondary storage unit
◦ cheap, long-term, high-capacity storage, stores inactive programs
10
Machine Languages, Assembly Languages, and High-level
Languages
Three types of programming languages
1. Machine languages
– strings of numbers giving machine specific instructions
– Example:
+1300042774
+1400593419
+1200274027
2. Assembly languages
– English-like abbreviations representing elementary computer operations (translated via assemblers)
– Example:
LOAD BASEPAY
ADD OVERPAY
STORE GROSSPAY
11
Machine Languages, Assembly Languages, and High-level
Languages (II)
3. High-level languages
◦ similar to everyday English and use mathematical notations
(translated via compilers)
◦ Example:
grossPay = basePay + overTimePay
12
History of Programming languages: C and C++
C++ evolved from C, which was developed by Dennis Ritchie at Bell Laboratories. C is available for most
computers and is hardware independent. With careful design, it’s possible to write C programs that are
portable to most computers.
The American National Standards Institute (ANSI) cooperated with the International Organization for
Standardization (ISO) to standardize C worldwide; the joint standard document was published in 1990.
C++, an extension of C, was developed by Bjarne Stroustrup in 1979 at Bell Laboratories. Originally called
“C with Classes”, it was renamed to C++ in the early 1980s. C++ provides a number of features that “spruce
up” the C language, but more importantly, it provides capabilities for object-oriented programming.
◦ objects - reuseable software components, model things in the real world
◦ Object-oriented programs are easy to understand, correct and modify
13
Other High-level Languages
A few other high-level languages have achieved broad acceptance
FORTRAN
◦ for scientific and engineering applications
COBOL
◦ used to manipulate large amounts of data
Pascal
◦ intended for academic use
14
Basics of a Typical C++ Environment
15
• Phases of C++ Programs:
1. Edit
2. Preprocess
3. Compile
4. Link
5. Load
6. Execute
Loader
Primary
Memory
Program is created in
the editor and stored
on disk.
Preprocessor program
processes the code.
Loader puts program
in memory.
CPU takes each
instruction and
executes it, possibly
storing new data
values as the program
executes.
Compiler
Compiler creates
object code and stores
it on disk.
Linker links the object
code with the libraries,
creates a.out and
stores it on disk
Editor
Preprocessor
Linker
CPU
Primary
Memory
.
.
.
.
.
.
.
.
.
.
.
.
Disk
Disk
Disk
Disk
Disk
Integrated Development Environment (IDE)
Integrated development environments (IDE) are applications that facilitates the development of other
applications. Designed to encompass all programming tasks in one application, one of the main
benefits of an IDE is that they offer a central interface with all the tools a developer needs, including:
•Code editor: Designed for writing and editing source code, these editors are distinguished from text
editors because work to either simplify or enhance the process of writing and editing of code for
developers
•Compiler: Compilers transform source code that is written in a human readable/writable language in
a form that computers can execute.
•Debugger: Debuggers are used during testing and can help developers debug their application
programs.
•Build automation tools: These can help automate developer tasks that are more common to save
time.
16
17
18
The Concept And Features Of The Algorithm
Algorithm is a step-by-step procedure, which defines a set of instructions to be executed in a
certain order to get the desired output. Algorithms are generally created independent of
underlying languages, i.e. an algorithm can be implemented in more than one programming
language.
Example: Write an algorithm for making a cup of tea
1. Put the teabag in a cup.
2. Fill the kettle with water.
3. Boil the water in the kettle.
4. Pour some of the boiled water into the cup.
5. Add milk to the cup.
6. Add sugar to the cup.
7. Stir the tea.
8. Drink the tea.
19
Algorithm Examples
Task: Add two numbers entered by the user
20
Algorithm Examples
Task: Find the largest number among three numbers
21
Ways Of Writing The Algorithm
English language
Flowchart
Pseudocode: It’s simply an implementation of an algorithm in the form of
annotations and informative text written in plain English. It has no syntax like any
of the programming language and thus can’t be compiled or interpreted by the
computer.
Evolution of Operating Systems
Batch processing
◦ do only one job or task at a time
Operating systems
◦ manage transitions between jobs
◦ increased throughput - amount of work computers process
Multiprogramming
◦ many jobs or tasks sharing the computer resources
Timesharing
◦ runs a small portion of one user’s job then moves on to service the next user
22
Personal Computing, Distributed Computing, and Client/Server
Computing
Personal computers
◦ economical enough for individual
Distributed computing
◦ organizations computing is distributed over networks
client/server computing
◦ sharing of information, across computer networks, between file servers and clients (personal computers)
23
24
Introduction to C++ Programming
The C++ language facilitates a structured and disciplined approach to computer program design
Following are several examples that illustrate many important features of C++. Each example is
analyzed one statement at a time.
1.19 Printing a line of text
1 // Fig. 1.2: fig01_02.cpp
2 // A first program in C++
3 #include <iostream>
4
5 int main()
6 {
7 std::cout << "Welcome to C++!n";
8
9 return 0; // indicate that program ended successfully
10 }
Welcome to C++!
preprocessor directive
Message to the C++ preprocessor
Lines beginning with # are preprocessor directives
#include <iostream> tells the preprocessor to
include the contents of the file <iostream>, which
includes input/output operations (such as printing to
the screen).
Comments
Written between /* and */ or following a //
Improve program readability and do not cause the
computer to perform any action
C++ programs contain one or more functions, exactly
one of which must be main
Parenthesis used to indicate a function
int means that main "returns" an integer value.
More in Chapter 3.
Left brace { begins the body of every function
and a right brace } ends it
Prints the string of characters contained between the
quotation marks.
The entire line, including std::cout, the <<
operator, the string "Welcome to C++!n" and
the semicolon (;), is called a statement.
All statements must end with a semicolon.
return is one a way to exit a
function.
return 0, in this case, means that
the program terminated normally.
26
A Simple Program:
Printing a Line of Text
std::cout
◦ standard output stream object
◦ “connected” to the screen
◦ we need the std:: to specify what "namespace" cout belongs to
◦ we shall remove this prefix with using statements
<<
◦ stream insertion operator
◦ value to the right of the operator (right operand) inserted into output
stream (which is connected to the screen)
std::cout << " Welcome to C++!n"

◦ escape character
◦ indicates that a “special” character is to be output
27
1.19 A Simple Program:
Printing a Line of Text (II)
There are multiple ways to print text
◦ Following are more examples
Escape Sequence Description
n Newline. Position the screen cursor to the
beginning of the next line.
t Horizontal tab. Move the screen cursor to the next
tab stop.
r Carriage return. Position the screen cursor to the
beginning of the current line; do not advance to the
next line.
a Alert. Sound the system bell.
 Backslash. Used to print a backslash character.
" Double quote. Used to print a double quote
character.
1. Load <iostream>
2. main
2.1 Print "Welcome"
2.2 Print "to C++!"
2.3 newline
2.4 exit (return 0)
Welcome to C++!
1 // Fig. 1.4: fig01_04.cpp
2 // Printing a line with multiple statements
3 #include <iostream>
4
5 int main()
6 {
7 std::cout << "Welcome ";
8 std::cout << "to C++!n";
9
10 return 0; // indicate that program ended successfully
11 }
Unless new line 'n' is specified, the text continues
on the same line.
1. Load <iostream>
2. main
2.1 Print "Welcome"
2.2 newline
2.3 Print "to"
2.4 newline
2.5 newline
2.6 Print "C++!"
2.7 newline
2.8 exit (return 0)
1 // Fig. 1.5: fig01_05.cpp
2 // Printing multiple lines with a single statement
3 #include <iostream>
4
5 int main()
6 {
7 std::cout << "WelcomentonnC++!n";
8
9 return 0; // indicate that program ended successfully
10 }
Welcome
to
C++!
Multiple lines can be printed with one
statement
30
Another Simple Program:
Adding Two Integers
Variables
◦ location in memory where a value can be stored for use by a program
◦ must be declared with a name and a data type before they can be used
◦ Must appear before variable is used
◦ Some common data types are:
◦ int - integer numbers
◦ char - characters
◦ double - floating point numbers
◦ Example: int myVariable;
◦ Declares a variable named myVariable of type int
Example: int variable1, variable2;
◦ Declares two variables, each of type int
31
Another Simple Program:
Adding Two Integers (II)
>> (stream extraction operator)
◦ When used with std::cin, waits for user to input a value and stores the value in the variable to
the right of the operator.
◦ user types number, then presses the Enter (Return) key to send the data to the computer
◦ Example:
int myVariable;
std::cin >> myVariable;
◦ waits for user input, then stores input in myVariable
= (assignment operator )
◦ assigns value to a variable
◦ binary operator (has two operands)
sum = variable1 + variable2;
Addition operator
1. Load <iostream>
2. main
2.1 Initialize variables integer1, integer2,
and sum
2.2 Print "Enter first integer"
2.2.1 Get input
2.3 Print "Enter second integer"
2.3.1 Get input
2.4 Add variables and put result into sum
2.5 Print "Sum is"
2.5.1 Output sum
2.6 exit (return 0)
Program Output
1 // Fig. 1.6: fig01_06.cpp
2 // Addition program
3 #include <iostream>
4
5 int main()
6 {
7 int integer1, integer2, sum; // declaration
8
9 std::cout << "Enter first integern"; // prompt
10 std::cin >> integer1; // read an integer
11 std::cout << "Enter second integern"; // prompt
12 std::cin >> integer2; // read an integer
13 sum = integer1 + integer2; // assignment of sum
14 std::cout << "Sum is " << sum << std::endl; // print sum
15
16 return 0; // indicate that program ended successfully
17 }
Enter first integer
45
Enter second integer
72
Sum is 117
Notice how std::cin is used to get user
input.
Variables can be output using std::cout << variableName
std::endl flushes the buffer and
prints a newline.

lecture Slides - Week 1.programming fundamentals

  • 1.
    1 Programming Fundamentals LEC TUR E: 1 & 2 WE E K: 1 INS TR UC TO R : M R . A B D UL KHA LI Q B OO K: C ++, HOW TO PRO GR A M BY D E I TE L 9 E
  • 2.
    2 Outline Introduction to problemsolving Von Neumann Architecture Computer Organization History Of Programming Languages Integrated Development Environment (IDE) Ways Of Writing The Algorithm The Concept And Features Of The Algorithm The C++ programming language Data Types and Variables in C++
  • 3.
    What is aComputer? A computer is a device capable of performing computations and making logical decisions Computers process data under the control of sets of instructions called computer programs Hardware – various devices comprising a computer ◦ Keyboard, screen, mouse, disks, memory, CD-ROM, and processing units Software – programs that run a computer OR set of instruction+documentation. 3
  • 4.
    PROGRAMMING A programming languageis a computer language programmers use to develop software programs, scripts, or other sets of instructions for computers to execute. Although many languages share similarities, each has its own syntax. Once a programmer learns the languages rules, syntax, and structure, they write the source code in a text editor or IDE. Then, the programmer often compiles the code into machine language that can be understood by the computer. Scripting languages, which do not require a compiler, use an interpreter to execute the script. 4
  • 5.
    5 Introduction to ProblemSolving Solving problems is the core of computer science. Programmers must first understand how a human solves a problem, then understand how to translate this "algorithm" into something a computer can do, and finally how to "write" the specific syntax (required by a computer) to get the job done. It is sometimes the case that a machine will solve a problem in a completely different way than a human.
  • 6.
    6 Computer Programmers areproblem solvers. In order to solve a problem on a computer you must: 1.Know how to represent the information (data) describing the problem. 2.Determine the steps to transform the information from one representation into another.
  • 7.
    Von Neumann Architecture VonNeumann architecture was first published by John von Neumann in 1945. His computer architecture design consists of a Control Unit, Arithmetic and Logic Unit (ALU), Memory Unit, Registers and Inputs/Outputs. Von Neumann architecture is based on the stored-program computer concept, where instruction data and program data are stored in the same memory. This design is still used in most computers produced today. 7
  • 8.
  • 9.
    Central Processing Unit(CPU) The Central Processing Unit (CPU) is the electronic circuit responsible for executing the instructions of a computer program. It is sometimes referred to as the microprocessor or processor. The CPU contains the ALU, CU and a variety of registers. Registers Registers are high speed storage areas in the CPU. All data must be stored in a register before it can be processed. Arithmetic and Logic Unit (ALU) The ALU allows arithmetic (add, subtract etc) and logic (AND, OR, NOT etc) operations to be carried out. Control Unit (CU) The control unit controls the operation of the computer’s ALU, memory and input/output devices, telling them how to respond to the program instructions it has just read and interpreted from the memory unit. The control unit also provides the timing and control signals required by other computer components. 9
  • 10.
    Computer Organization Six logicalunits in every computer: 1. Input unit ◦ obtains information from input devices (keyboard, mouse) 2. Output unit ◦ outputs information (to screen, to printer, to control other devices) 3. Memory unit ◦ rapid access, low capacity, stores input information 4. Arithmetic and logic unit (ALU) ◦ performs arithmetic calculations and logic decisions 5. Central processing unit (CPU) ◦ supervises and coordinates the other sections of the computer 6. Secondary storage unit ◦ cheap, long-term, high-capacity storage, stores inactive programs 10
  • 11.
    Machine Languages, AssemblyLanguages, and High-level Languages Three types of programming languages 1. Machine languages – strings of numbers giving machine specific instructions – Example: +1300042774 +1400593419 +1200274027 2. Assembly languages – English-like abbreviations representing elementary computer operations (translated via assemblers) – Example: LOAD BASEPAY ADD OVERPAY STORE GROSSPAY 11
  • 12.
    Machine Languages, AssemblyLanguages, and High-level Languages (II) 3. High-level languages ◦ similar to everyday English and use mathematical notations (translated via compilers) ◦ Example: grossPay = basePay + overTimePay 12
  • 13.
    History of Programminglanguages: C and C++ C++ evolved from C, which was developed by Dennis Ritchie at Bell Laboratories. C is available for most computers and is hardware independent. With careful design, it’s possible to write C programs that are portable to most computers. The American National Standards Institute (ANSI) cooperated with the International Organization for Standardization (ISO) to standardize C worldwide; the joint standard document was published in 1990. C++, an extension of C, was developed by Bjarne Stroustrup in 1979 at Bell Laboratories. Originally called “C with Classes”, it was renamed to C++ in the early 1980s. C++ provides a number of features that “spruce up” the C language, but more importantly, it provides capabilities for object-oriented programming. ◦ objects - reuseable software components, model things in the real world ◦ Object-oriented programs are easy to understand, correct and modify 13
  • 14.
    Other High-level Languages Afew other high-level languages have achieved broad acceptance FORTRAN ◦ for scientific and engineering applications COBOL ◦ used to manipulate large amounts of data Pascal ◦ intended for academic use 14
  • 15.
    Basics of aTypical C++ Environment 15 • Phases of C++ Programs: 1. Edit 2. Preprocess 3. Compile 4. Link 5. Load 6. Execute Loader Primary Memory Program is created in the editor and stored on disk. Preprocessor program processes the code. Loader puts program in memory. CPU takes each instruction and executes it, possibly storing new data values as the program executes. Compiler Compiler creates object code and stores it on disk. Linker links the object code with the libraries, creates a.out and stores it on disk Editor Preprocessor Linker CPU Primary Memory . . . . . . . . . . . . Disk Disk Disk Disk Disk
  • 16.
    Integrated Development Environment(IDE) Integrated development environments (IDE) are applications that facilitates the development of other applications. Designed to encompass all programming tasks in one application, one of the main benefits of an IDE is that they offer a central interface with all the tools a developer needs, including: •Code editor: Designed for writing and editing source code, these editors are distinguished from text editors because work to either simplify or enhance the process of writing and editing of code for developers •Compiler: Compilers transform source code that is written in a human readable/writable language in a form that computers can execute. •Debugger: Debuggers are used during testing and can help developers debug their application programs. •Build automation tools: These can help automate developer tasks that are more common to save time. 16
  • 17.
  • 18.
    18 The Concept AndFeatures Of The Algorithm Algorithm is a step-by-step procedure, which defines a set of instructions to be executed in a certain order to get the desired output. Algorithms are generally created independent of underlying languages, i.e. an algorithm can be implemented in more than one programming language. Example: Write an algorithm for making a cup of tea 1. Put the teabag in a cup. 2. Fill the kettle with water. 3. Boil the water in the kettle. 4. Pour some of the boiled water into the cup. 5. Add milk to the cup. 6. Add sugar to the cup. 7. Stir the tea. 8. Drink the tea.
  • 19.
    19 Algorithm Examples Task: Addtwo numbers entered by the user
  • 20.
    20 Algorithm Examples Task: Findthe largest number among three numbers
  • 21.
    21 Ways Of WritingThe Algorithm English language Flowchart Pseudocode: It’s simply an implementation of an algorithm in the form of annotations and informative text written in plain English. It has no syntax like any of the programming language and thus can’t be compiled or interpreted by the computer.
  • 22.
    Evolution of OperatingSystems Batch processing ◦ do only one job or task at a time Operating systems ◦ manage transitions between jobs ◦ increased throughput - amount of work computers process Multiprogramming ◦ many jobs or tasks sharing the computer resources Timesharing ◦ runs a small portion of one user’s job then moves on to service the next user 22
  • 23.
    Personal Computing, DistributedComputing, and Client/Server Computing Personal computers ◦ economical enough for individual Distributed computing ◦ organizations computing is distributed over networks client/server computing ◦ sharing of information, across computer networks, between file servers and clients (personal computers) 23
  • 24.
    24 Introduction to C++Programming The C++ language facilitates a structured and disciplined approach to computer program design Following are several examples that illustrate many important features of C++. Each example is analyzed one statement at a time.
  • 25.
    1.19 Printing aline of text 1 // Fig. 1.2: fig01_02.cpp 2 // A first program in C++ 3 #include <iostream> 4 5 int main() 6 { 7 std::cout << "Welcome to C++!n"; 8 9 return 0; // indicate that program ended successfully 10 } Welcome to C++! preprocessor directive Message to the C++ preprocessor Lines beginning with # are preprocessor directives #include <iostream> tells the preprocessor to include the contents of the file <iostream>, which includes input/output operations (such as printing to the screen). Comments Written between /* and */ or following a // Improve program readability and do not cause the computer to perform any action C++ programs contain one or more functions, exactly one of which must be main Parenthesis used to indicate a function int means that main "returns" an integer value. More in Chapter 3. Left brace { begins the body of every function and a right brace } ends it Prints the string of characters contained between the quotation marks. The entire line, including std::cout, the << operator, the string "Welcome to C++!n" and the semicolon (;), is called a statement. All statements must end with a semicolon. return is one a way to exit a function. return 0, in this case, means that the program terminated normally.
  • 26.
    26 A Simple Program: Printinga Line of Text std::cout ◦ standard output stream object ◦ “connected” to the screen ◦ we need the std:: to specify what "namespace" cout belongs to ◦ we shall remove this prefix with using statements << ◦ stream insertion operator ◦ value to the right of the operator (right operand) inserted into output stream (which is connected to the screen) std::cout << " Welcome to C++!n" ◦ escape character ◦ indicates that a “special” character is to be output
  • 27.
    27 1.19 A SimpleProgram: Printing a Line of Text (II) There are multiple ways to print text ◦ Following are more examples Escape Sequence Description n Newline. Position the screen cursor to the beginning of the next line. t Horizontal tab. Move the screen cursor to the next tab stop. r Carriage return. Position the screen cursor to the beginning of the current line; do not advance to the next line. a Alert. Sound the system bell. Backslash. Used to print a backslash character. " Double quote. Used to print a double quote character.
  • 28.
    1. Load <iostream> 2.main 2.1 Print "Welcome" 2.2 Print "to C++!" 2.3 newline 2.4 exit (return 0) Welcome to C++! 1 // Fig. 1.4: fig01_04.cpp 2 // Printing a line with multiple statements 3 #include <iostream> 4 5 int main() 6 { 7 std::cout << "Welcome "; 8 std::cout << "to C++!n"; 9 10 return 0; // indicate that program ended successfully 11 } Unless new line 'n' is specified, the text continues on the same line.
  • 29.
    1. Load <iostream> 2.main 2.1 Print "Welcome" 2.2 newline 2.3 Print "to" 2.4 newline 2.5 newline 2.6 Print "C++!" 2.7 newline 2.8 exit (return 0) 1 // Fig. 1.5: fig01_05.cpp 2 // Printing multiple lines with a single statement 3 #include <iostream> 4 5 int main() 6 { 7 std::cout << "WelcomentonnC++!n"; 8 9 return 0; // indicate that program ended successfully 10 } Welcome to C++! Multiple lines can be printed with one statement
  • 30.
    30 Another Simple Program: AddingTwo Integers Variables ◦ location in memory where a value can be stored for use by a program ◦ must be declared with a name and a data type before they can be used ◦ Must appear before variable is used ◦ Some common data types are: ◦ int - integer numbers ◦ char - characters ◦ double - floating point numbers ◦ Example: int myVariable; ◦ Declares a variable named myVariable of type int Example: int variable1, variable2; ◦ Declares two variables, each of type int
  • 31.
    31 Another Simple Program: AddingTwo Integers (II) >> (stream extraction operator) ◦ When used with std::cin, waits for user to input a value and stores the value in the variable to the right of the operator. ◦ user types number, then presses the Enter (Return) key to send the data to the computer ◦ Example: int myVariable; std::cin >> myVariable; ◦ waits for user input, then stores input in myVariable = (assignment operator ) ◦ assigns value to a variable ◦ binary operator (has two operands) sum = variable1 + variable2; Addition operator
  • 32.
    1. Load <iostream> 2.main 2.1 Initialize variables integer1, integer2, and sum 2.2 Print "Enter first integer" 2.2.1 Get input 2.3 Print "Enter second integer" 2.3.1 Get input 2.4 Add variables and put result into sum 2.5 Print "Sum is" 2.5.1 Output sum 2.6 exit (return 0) Program Output 1 // Fig. 1.6: fig01_06.cpp 2 // Addition program 3 #include <iostream> 4 5 int main() 6 { 7 int integer1, integer2, sum; // declaration 8 9 std::cout << "Enter first integern"; // prompt 10 std::cin >> integer1; // read an integer 11 std::cout << "Enter second integern"; // prompt 12 std::cin >> integer2; // read an integer 13 sum = integer1 + integer2; // assignment of sum 14 std::cout << "Sum is " << sum << std::endl; // print sum 15 16 return 0; // indicate that program ended successfully 17 } Enter first integer 45 Enter second integer 72 Sum is 117 Notice how std::cin is used to get user input. Variables can be output using std::cout << variableName std::endl flushes the buffer and prints a newline.