SlideShare a Scribd company logo
Copyright © 2003 Pearson Education, Inc. Slide 1
Copyright © 2003 Pearson Education, Inc. Slide 2
Chapter 1
Introduction to Computers
and C++ Programming
Copyright © 2003 Pearson Education, Inc. Slide 3
Overview
 Computer Systems (1.1)
 Programming and Problem Solving (1.2)
 Introduction to C++ (1.3)
 Testing and Debugging (1.4)
Copyright © 2003 Pearson Education, Inc. Slide 4
Computer Systems
 A computer program is…
 A set of instructions for a computer to follow
 Computer software is …
 The collection of programs used by a computer

Includes:

Editors

Translators

System Managers
1.1
Copyright © 2003 Pearson Education, Inc. Slide 5
Hardware
 Three main classes of computers
 PCs (Personal Computer)

Relatively small used by one person at a time
 Workstation

Larger and more powerful than a PC
 Mainframe

Still larger

Requires support staff

Shared by multiple users
Copyright © 2003 Pearson Education, Inc. Slide 6
Networks
 A number of computers connected to
share resources
 Share printers and other devices
 Share information
Copyright © 2003 Pearson Education, Inc. Slide 7
Computer Organization
 Five main components

Input devices
 Allows communication to the computer

Output devices
 Allows communication to the user

Processor (CPU)

Main memory
 Memory locations containing the running program

Secondary memory
 Permanent record of data often on a disk Display 1.1
Copyright © 2003 Pearson Education, Inc. Slide 8
Computer Memory
 Main Memory
 Long list of memory locations

Each contains zeros and ones

Can change during program execution
 Binary Digit or Bit

A digit that can only be zero or one
 Byte

Each memory location has eight bits
 Address

Number that identifies a memory location
Copyright © 2003 Pearson Education, Inc. Slide 9
Larger Data Items
 Some data is too large for a single byte
 Most integers and real numbers are too large
 Address refers to the first byte
 Next few consecutive bytes can store the additional
bits for larger data
Display 1.2
Copyright © 2003 Pearson Education, Inc. Slide 10
Data or Code?
 ‘A’ may look like 01000001
 65 may look like 01000001
 An instruction may look like 01000001
 How does the computer know the meaning
of 01000001?

Interpretation depends on the current instruction
 Programmers rarely need to be concerned with
this problem.

Reason as if memory locations contain letters and
numbers rather than zeroes and ones
Copyright © 2003 Pearson Education, Inc. Slide 11
Secondary Memory
 Main memory stores instructions and
data while a program is running.
 Secondary memory
 Stores instructions and data between sessions
 A file stores data or instructions in
secondary memory
Copyright © 2003 Pearson Education, Inc. Slide 12
Secondary Memory Media
 A computer might have any of these
types of secondary memory
 Hard disk

Fast

Fixed in the computer and not normally removed
 Floppy disk

Slow

Easily shared with other computers
 Compact disk

Slower than hard disks

Easily shared with other computers

Can be read only or re-writable
Copyright © 2003 Pearson Education, Inc. Slide 13
Memory Access
 Random Access
 Usually called RAM

Computer can directly access any memory location
 Sequential Access
 Data is generally found by searching through
other items first

More common in secondary memory
Copyright © 2003 Pearson Education, Inc. Slide 14
The Processor
 Typically called the CPU
 Central Processing Unit
 Follows program instructions
 Typical capabilities of CPU include:
add
subtract
multiply
divide
move data from location to location
Copyright © 2003 Pearson Education, Inc. Slide 15
Computer Software
 The operating system
 Allows us to communicate with the computer
 Is a program
 Allocates the computer’s resources
 Responds to user requests to run other programs
 Common operating systems include…
 UNIX Linux DOS
Windows Macintosh VMS
Copyright © 2003 Pearson Education, Inc. Slide 16
Computer Input
 Computer input consists of
 A program
 Some data
Display 1.3
Copyright © 2003 Pearson Education, Inc. Slide 17
High-level Languages
 Common programming languages include …
C C++ Java Pascal Visual Basic FORTRAN
COBOL Lisp Scheme Ada
 These high – level languages
 Resemble human languages

Are designed to be easy to read and write

Use more complicated instructions than
the CPU can follow

Must be translated to zeros and ones for the CPU
to execute a program
Copyright © 2003 Pearson Education, Inc. Slide 18
Low-level Languages
 An assembly language command such as
ADD X Y Z
might mean add the values found at x and y
in memory, and store the result in location z.
 Assembly language must be translated to
machine language (zeros and ones)
0110 1001 1010 1011
 The CPU can follow machine language
Copyright © 2003 Pearson Education, Inc. Slide 19
Compilers
 Translate high-level language to
machine language
 Source code

the original program in a high level language
 Object code

the translated version in machine language
Display 1.4
Copyright © 2003 Pearson Education, Inc. Slide 20
Linkers
 Some programs we use are already compiled
 Their object code is available for us to use
 For example: Input and output routines
 A Linker combines
 The object code for the programs we write
and
 The object code for the pre-compiled routines
into
The machine language program the CPU can run
Display 1.5
Copyright © 2003 Pearson Education, Inc. Slide 21
Section 1.1 Conclusion
 Can you…
 List the five main components of a computer?
 List the data for a program that adds two numbers?
 Describe the work of a compiler?
 Define source code? Define object code?
 Describe the purpose of the operating system?
Copyright © 2003 Pearson Education, Inc. Slide 22
Programming
and Problem Solving
 Algorithm
 A sequence of precise instructions which
leads to a solution
 Program
 An algorithm expressed in a language the computer
can understand
Display 1.6
1.2
Copyright © 2003 Pearson Education, Inc. Slide 23
Program Design
 Programming is a creative process
 No complete set of rules for creating a program
 Program Design Process
 Problem Solving Phase

Result is an algorithm that solves the problem
 Implementation Phase

Result is the algorithm translated into a programming
language
Copyright © 2003 Pearson Education, Inc. Slide 24
Problem Solving Phase
 Be certain the task is completely specified
 What is the input?
 What information is in the output?
 How is the output organized?
 Develop the algorithm before implementation
 Experience shows this saves time in getting your
program to run.
 Test the algorithm for correctness
Copyright © 2003 Pearson Education, Inc. Slide 25
Implementation Phase
 Translate the algorithm into a programming
language
 Easier as you gain experience with the language
 Compile the source code
 Locates errors in using the programming language
 Run the program on sample data
 Verify correctness of results
 Results may require modification of
the algorithm and program
Display 1.7
Copyright © 2003 Pearson Education, Inc. Slide 26
Object Oriented Programming
 Abbreviated OOP (Future Course): Now, we shall
use “Structured Programming”
 Used for many modern programs
 Program is viewed as interacting objects
 Each object contains algorithms to describe its behavior
 Program design phase involves designing objects and
their algorithms
Copyright © 2003 Pearson Education, Inc. Slide 27
Software Life Cycle
1. Analysis and specification of the task
(problem definition)
2. Design of the software
(algorithm design)
3. Implementation (coding)
4. Maintenance and evolution of the system
5. Obsolescence
Copyright © 2003 Pearson Education, Inc. Slide 28
Section 1.2 Conclusion
 Can you…
 Describe the first step to take when creating a program?
 List the two main phases of the program design process?
 Explain the importance of the problem-solving phase?
 List the steps in the software life cycle?
Copyright © 2003 Pearson Education, Inc. Slide 29
Introduction to C++
 Where did C++ come from?
 Derived from the C language
 C was derived from the B language
 B was derived from the BCPL language
 Why the ‘++’?
 ++ is an operator in C++ and results in a cute pun
1.3
Copyright © 2003 Pearson Education, Inc. Slide 30
C++ History
 C developed by Dennis Ritchie at AT&T
Bell Labs in the 1970s.
 Used to maintain UNIX systems
 Many commercial applications written in c
 C++ developed by Bjarne Stroustrup at AT&T
Bell Labs in the 1980s.
 Overcame several shortcomings of C
 Incorporated object oriented programming
 C remains a subset of C++
Copyright © 2003 Pearson Education, Inc. Slide 31
A Sample C++ Program
 A simple C++ program begins this way
#include <iostream>
using namespace std;
int main()
{
 And ends this way
return 0;
}
Display 1.8
Copyright © 2003 Pearson Education, Inc. Slide 32
Explanation of code (1/5)
 Variable declaration line
int number_of_pods, peas_per_pod, total_peas;
 Identifies names of three variables to name numbers
 int means that the variables represent integers
Copyright © 2003 Pearson Education, Inc. Slide 33
Explanation of code (2/5)
Program statement
cout << “Press return after entering a number.n”;

cout (see-out) used for output to the monitor

“<<“ inserts “Press…a number.n” in the data
bound for the monitor

Think of cout as a name for the monitor

“<<“ points to where the data is to end up

‘n’ causes a new line to be started on the monitor
Copyright © 2003 Pearson Education, Inc. Slide 34
Explanation of code (3/5)
 Program statement
cin >> number_of_pods;
 cin (see-in) used for input from the keyboard
 “>>” extracts data from the keyboard
 Think of cin as a name for the keyboard

“>>” points from the keyboard to a variable where the data is stored
Copyright © 2003 Pearson Education, Inc. Slide 35
Explanation of code (4/5)
 Program statement
total_peas = number_of_pods * peas_per_pod;
 Performs a computation
 ‘*’ is used for multiplication
 ‘=‘ causes total_peas to get a new value based on
the calculation shown on the right of the equal sign
Copyright © 2003 Pearson Education, Inc. Slide 36
Explanation of code (5/5)
 Program statement
cout << number_of_pods;
 Sends the value of variable number_of_pods to
the monitor
Copyright © 2003 Pearson Education, Inc. Slide 37
Program Layout (1/3)
 Compiler accepts almost any pattern of line
breaks and indentation
 Programmers format programs so they
are easy to read
 Place opening brace ‘{‘ and closing brace ‘}’
on a line by themselves
 Indent statements
 Use only one statement per line
Copyright © 2003 Pearson Education, Inc. Slide 38
Program Layout (2/3)
 Variables are declared before they are used
 Typically variables are declared at the beginning of
the program
 Statements (not always lines) end with a semi-colon
 Include Directives
#include <iostream>
 Tells compiler where to find information about items
used in the program
 iostream is a library containing definitions of cin and cout
Copyright © 2003 Pearson Education, Inc. Slide 39
Program Layout (3/3)
using namespace std;
 Tells the compiler to use names in iostream in
a “standard” way
 To begin the main function of the program
int main()
{
 To end the main function
return 0;
}
 Main function ends with a return statement
Copyright © 2003 Pearson Education, Inc. Slide 40
Running a C++ Program
 C++ source code is written with a text
editor
 The compiler on your system converts
source code to object code.
 The linker combines all the object code
into an executable program.
Copyright © 2003 Pearson Education, Inc. Slide 41
Run a Program
 Obtain code in Display 1.10
 Compile the code
 Fix any errors the compiler indicates and
re-compile the code
 Run the program
 Now you know how to run a program on
your system
Display 1.10
Copyright © 2003 Pearson Education, Inc. Slide 42
Section 1.3 Conclusion
 Can you…
 Describe the output of this line?
cout << “C++ is easy to understand.”;
 Explain what this line does?
cin >> peas_per_pod;
 Explain this? #include <iostream>
Copyright © 2003 Pearson Education, Inc. Slide 43
Testing and Debugging
 Bug
 A mistake in a program
 Debugging
 Eliminating mistakes in programs
 Term used when a moth caused a failed relay
on the Harvard Mark 1 computer. Grace Hopper
and other programmers taped the moth in logbook
stating:
“First actual case of a bug being found.”
1.4
Copyright © 2003 Pearson Education, Inc. Slide 44
Program Errors
 Syntax errors
 Violation of the grammar rules of the language
 Discovered by the compiler

Error messages may not always show correct location of
errors
 Run-time errors
 Error conditions detected by the computer at run-time
 Logic errors
 Errors in the program’s algorithm
 Most difficult to diagnose
 Computer does not recognize an error
Copyright © 2003 Pearson Education, Inc. Slide 45
Section 1-4 Conclusion
 Can you…
 Describe the three kinds of program errors?
 Tell what kind of errors the compiler catches?
 What kind of error is produced if you forget a
punctuation symbol such as a semi-colon?
 Tell what type of error is produced when a program
runs but produces incorrect results?
Copyright © 2003 Pearson Education, Inc. Slide 46
Chapter 1 -- End
Copyright © 2003 Pearson Education, Inc. Slide 47
Display 1.1 Back Next
Copyright © 2003 Pearson Education, Inc. Slide 48
Display 1.2 Back Next
Copyright © 2003 Pearson Education, Inc. Slide 49
Display 1.3 Back Next
Copyright © 2003 Pearson Education, Inc. Slide 50
Display 1.4 Back Next
Copyright © 2003 Pearson Education, Inc. Slide 51
Display 1.5 Back Next
Copyright © 2003 Pearson Education, Inc. Slide 52
Display 1.6 Back Next
Copyright © 2003 Pearson Education, Inc. Slide 53
Display 1.7 Back Next
Copyright © 2003 Pearson Education, Inc. Slide 54
Display 1.8 Next
Back
Copyright © 2003 Pearson Education, Inc. Slide 55
Display 1.9 Back Next
Copyright © 2003 Pearson Education, Inc. Slide 56
Display 1.10 Next
Back

More Related Content

PPT
Savitch Ch 01
PPT
Savitch ch 01
PPT
Savitch ch 01
PPT
Chapter 1.ppt
PPT
Savitch_ch_01.ppt
PPT
C++ Problem solving
PPTX
Lecture 1-2_Programming fundamentals.pptx
PDF
Chap 1 Introduction to Computers, the Internet and the WebFile.pdf
Savitch Ch 01
Savitch ch 01
Savitch ch 01
Chapter 1.ppt
Savitch_ch_01.ppt
C++ Problem solving
Lecture 1-2_Programming fundamentals.pptx
Chap 1 Introduction to Computers, the Internet and the WebFile.pdf

Similar to Chapter-1_c++_programming_course_PBM Solving.pptx (20)

PPT
CHTP5e_01.ppt bbbbbbbbb bbbb
PPT
Cpp htp5e 01
PPT
Lecture 1.ppt
PPT
មេរៀនៈ Data Structure and Algorithm in C/C++
PPTX
lecture Slides - Week 1.programming fundamentals
PPTX
lec 1.pptx
PPT
01CHAP_1.PPT
PPT
C++ programming program design including data structures
PPTX
Whole c++ lectures ITM1 Th
PDF
Introduction to Computers and Programming
PDF
C progrmming
PDF
6272 cnote
PDF
Chap 1 c++
PPT
Introduction to computers and programing.pptx
PPT
programing fundamentals by dr. wheedh khan
PPTX
Programming Lecture 01 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqq
PDF
Introduction to Programming Fundamentals
PPT
01 introduction to cpp
PPTX
introductiontocomputerprogramming.pptx
PPT
Introduction to Java and computers
CHTP5e_01.ppt bbbbbbbbb bbbb
Cpp htp5e 01
Lecture 1.ppt
មេរៀនៈ Data Structure and Algorithm in C/C++
lecture Slides - Week 1.programming fundamentals
lec 1.pptx
01CHAP_1.PPT
C++ programming program design including data structures
Whole c++ lectures ITM1 Th
Introduction to Computers and Programming
C progrmming
6272 cnote
Chap 1 c++
Introduction to computers and programing.pptx
programing fundamentals by dr. wheedh khan
Programming Lecture 01 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqq
Introduction to Programming Fundamentals
01 introduction to cpp
introductiontocomputerprogramming.pptx
Introduction to Java and computers
Ad

Recently uploaded (20)

PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PDF
Digital Logic Computer Design lecture notes
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PPTX
Construction Project Organization Group 2.pptx
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PDF
composite construction of structures.pdf
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPTX
Internet of Things (IOT) - A guide to understanding
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPT
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PPTX
additive manufacturing of ss316l using mig welding
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
CYBER-CRIMES AND SECURITY A guide to understanding
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
Digital Logic Computer Design lecture notes
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Construction Project Organization Group 2.pptx
Embodied AI: Ushering in the Next Era of Intelligent Systems
composite construction of structures.pdf
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
Model Code of Practice - Construction Work - 21102022 .pdf
Internet of Things (IOT) - A guide to understanding
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
additive manufacturing of ss316l using mig welding
Ad

Chapter-1_c++_programming_course_PBM Solving.pptx

  • 1. Copyright © 2003 Pearson Education, Inc. Slide 1
  • 2. Copyright © 2003 Pearson Education, Inc. Slide 2 Chapter 1 Introduction to Computers and C++ Programming
  • 3. Copyright © 2003 Pearson Education, Inc. Slide 3 Overview  Computer Systems (1.1)  Programming and Problem Solving (1.2)  Introduction to C++ (1.3)  Testing and Debugging (1.4)
  • 4. Copyright © 2003 Pearson Education, Inc. Slide 4 Computer Systems  A computer program is…  A set of instructions for a computer to follow  Computer software is …  The collection of programs used by a computer  Includes:  Editors  Translators  System Managers 1.1
  • 5. Copyright © 2003 Pearson Education, Inc. Slide 5 Hardware  Three main classes of computers  PCs (Personal Computer)  Relatively small used by one person at a time  Workstation  Larger and more powerful than a PC  Mainframe  Still larger  Requires support staff  Shared by multiple users
  • 6. Copyright © 2003 Pearson Education, Inc. Slide 6 Networks  A number of computers connected to share resources  Share printers and other devices  Share information
  • 7. Copyright © 2003 Pearson Education, Inc. Slide 7 Computer Organization  Five main components  Input devices  Allows communication to the computer  Output devices  Allows communication to the user  Processor (CPU)  Main memory  Memory locations containing the running program  Secondary memory  Permanent record of data often on a disk Display 1.1
  • 8. Copyright © 2003 Pearson Education, Inc. Slide 8 Computer Memory  Main Memory  Long list of memory locations  Each contains zeros and ones  Can change during program execution  Binary Digit or Bit  A digit that can only be zero or one  Byte  Each memory location has eight bits  Address  Number that identifies a memory location
  • 9. Copyright © 2003 Pearson Education, Inc. Slide 9 Larger Data Items  Some data is too large for a single byte  Most integers and real numbers are too large  Address refers to the first byte  Next few consecutive bytes can store the additional bits for larger data Display 1.2
  • 10. Copyright © 2003 Pearson Education, Inc. Slide 10 Data or Code?  ‘A’ may look like 01000001  65 may look like 01000001  An instruction may look like 01000001  How does the computer know the meaning of 01000001?  Interpretation depends on the current instruction  Programmers rarely need to be concerned with this problem.  Reason as if memory locations contain letters and numbers rather than zeroes and ones
  • 11. Copyright © 2003 Pearson Education, Inc. Slide 11 Secondary Memory  Main memory stores instructions and data while a program is running.  Secondary memory  Stores instructions and data between sessions  A file stores data or instructions in secondary memory
  • 12. Copyright © 2003 Pearson Education, Inc. Slide 12 Secondary Memory Media  A computer might have any of these types of secondary memory  Hard disk  Fast  Fixed in the computer and not normally removed  Floppy disk  Slow  Easily shared with other computers  Compact disk  Slower than hard disks  Easily shared with other computers  Can be read only or re-writable
  • 13. Copyright © 2003 Pearson Education, Inc. Slide 13 Memory Access  Random Access  Usually called RAM  Computer can directly access any memory location  Sequential Access  Data is generally found by searching through other items first  More common in secondary memory
  • 14. Copyright © 2003 Pearson Education, Inc. Slide 14 The Processor  Typically called the CPU  Central Processing Unit  Follows program instructions  Typical capabilities of CPU include: add subtract multiply divide move data from location to location
  • 15. Copyright © 2003 Pearson Education, Inc. Slide 15 Computer Software  The operating system  Allows us to communicate with the computer  Is a program  Allocates the computer’s resources  Responds to user requests to run other programs  Common operating systems include…  UNIX Linux DOS Windows Macintosh VMS
  • 16. Copyright © 2003 Pearson Education, Inc. Slide 16 Computer Input  Computer input consists of  A program  Some data Display 1.3
  • 17. Copyright © 2003 Pearson Education, Inc. Slide 17 High-level Languages  Common programming languages include … C C++ Java Pascal Visual Basic FORTRAN COBOL Lisp Scheme Ada  These high – level languages  Resemble human languages  Are designed to be easy to read and write  Use more complicated instructions than the CPU can follow  Must be translated to zeros and ones for the CPU to execute a program
  • 18. Copyright © 2003 Pearson Education, Inc. Slide 18 Low-level Languages  An assembly language command such as ADD X Y Z might mean add the values found at x and y in memory, and store the result in location z.  Assembly language must be translated to machine language (zeros and ones) 0110 1001 1010 1011  The CPU can follow machine language
  • 19. Copyright © 2003 Pearson Education, Inc. Slide 19 Compilers  Translate high-level language to machine language  Source code  the original program in a high level language  Object code  the translated version in machine language Display 1.4
  • 20. Copyright © 2003 Pearson Education, Inc. Slide 20 Linkers  Some programs we use are already compiled  Their object code is available for us to use  For example: Input and output routines  A Linker combines  The object code for the programs we write and  The object code for the pre-compiled routines into The machine language program the CPU can run Display 1.5
  • 21. Copyright © 2003 Pearson Education, Inc. Slide 21 Section 1.1 Conclusion  Can you…  List the five main components of a computer?  List the data for a program that adds two numbers?  Describe the work of a compiler?  Define source code? Define object code?  Describe the purpose of the operating system?
  • 22. Copyright © 2003 Pearson Education, Inc. Slide 22 Programming and Problem Solving  Algorithm  A sequence of precise instructions which leads to a solution  Program  An algorithm expressed in a language the computer can understand Display 1.6 1.2
  • 23. Copyright © 2003 Pearson Education, Inc. Slide 23 Program Design  Programming is a creative process  No complete set of rules for creating a program  Program Design Process  Problem Solving Phase  Result is an algorithm that solves the problem  Implementation Phase  Result is the algorithm translated into a programming language
  • 24. Copyright © 2003 Pearson Education, Inc. Slide 24 Problem Solving Phase  Be certain the task is completely specified  What is the input?  What information is in the output?  How is the output organized?  Develop the algorithm before implementation  Experience shows this saves time in getting your program to run.  Test the algorithm for correctness
  • 25. Copyright © 2003 Pearson Education, Inc. Slide 25 Implementation Phase  Translate the algorithm into a programming language  Easier as you gain experience with the language  Compile the source code  Locates errors in using the programming language  Run the program on sample data  Verify correctness of results  Results may require modification of the algorithm and program Display 1.7
  • 26. Copyright © 2003 Pearson Education, Inc. Slide 26 Object Oriented Programming  Abbreviated OOP (Future Course): Now, we shall use “Structured Programming”  Used for many modern programs  Program is viewed as interacting objects  Each object contains algorithms to describe its behavior  Program design phase involves designing objects and their algorithms
  • 27. Copyright © 2003 Pearson Education, Inc. Slide 27 Software Life Cycle 1. Analysis and specification of the task (problem definition) 2. Design of the software (algorithm design) 3. Implementation (coding) 4. Maintenance and evolution of the system 5. Obsolescence
  • 28. Copyright © 2003 Pearson Education, Inc. Slide 28 Section 1.2 Conclusion  Can you…  Describe the first step to take when creating a program?  List the two main phases of the program design process?  Explain the importance of the problem-solving phase?  List the steps in the software life cycle?
  • 29. Copyright © 2003 Pearson Education, Inc. Slide 29 Introduction to C++  Where did C++ come from?  Derived from the C language  C was derived from the B language  B was derived from the BCPL language  Why the ‘++’?  ++ is an operator in C++ and results in a cute pun 1.3
  • 30. Copyright © 2003 Pearson Education, Inc. Slide 30 C++ History  C developed by Dennis Ritchie at AT&T Bell Labs in the 1970s.  Used to maintain UNIX systems  Many commercial applications written in c  C++ developed by Bjarne Stroustrup at AT&T Bell Labs in the 1980s.  Overcame several shortcomings of C  Incorporated object oriented programming  C remains a subset of C++
  • 31. Copyright © 2003 Pearson Education, Inc. Slide 31 A Sample C++ Program  A simple C++ program begins this way #include <iostream> using namespace std; int main() {  And ends this way return 0; } Display 1.8
  • 32. Copyright © 2003 Pearson Education, Inc. Slide 32 Explanation of code (1/5)  Variable declaration line int number_of_pods, peas_per_pod, total_peas;  Identifies names of three variables to name numbers  int means that the variables represent integers
  • 33. Copyright © 2003 Pearson Education, Inc. Slide 33 Explanation of code (2/5) Program statement cout << “Press return after entering a number.n”;  cout (see-out) used for output to the monitor  “<<“ inserts “Press…a number.n” in the data bound for the monitor  Think of cout as a name for the monitor  “<<“ points to where the data is to end up  ‘n’ causes a new line to be started on the monitor
  • 34. Copyright © 2003 Pearson Education, Inc. Slide 34 Explanation of code (3/5)  Program statement cin >> number_of_pods;  cin (see-in) used for input from the keyboard  “>>” extracts data from the keyboard  Think of cin as a name for the keyboard  “>>” points from the keyboard to a variable where the data is stored
  • 35. Copyright © 2003 Pearson Education, Inc. Slide 35 Explanation of code (4/5)  Program statement total_peas = number_of_pods * peas_per_pod;  Performs a computation  ‘*’ is used for multiplication  ‘=‘ causes total_peas to get a new value based on the calculation shown on the right of the equal sign
  • 36. Copyright © 2003 Pearson Education, Inc. Slide 36 Explanation of code (5/5)  Program statement cout << number_of_pods;  Sends the value of variable number_of_pods to the monitor
  • 37. Copyright © 2003 Pearson Education, Inc. Slide 37 Program Layout (1/3)  Compiler accepts almost any pattern of line breaks and indentation  Programmers format programs so they are easy to read  Place opening brace ‘{‘ and closing brace ‘}’ on a line by themselves  Indent statements  Use only one statement per line
  • 38. Copyright © 2003 Pearson Education, Inc. Slide 38 Program Layout (2/3)  Variables are declared before they are used  Typically variables are declared at the beginning of the program  Statements (not always lines) end with a semi-colon  Include Directives #include <iostream>  Tells compiler where to find information about items used in the program  iostream is a library containing definitions of cin and cout
  • 39. Copyright © 2003 Pearson Education, Inc. Slide 39 Program Layout (3/3) using namespace std;  Tells the compiler to use names in iostream in a “standard” way  To begin the main function of the program int main() {  To end the main function return 0; }  Main function ends with a return statement
  • 40. Copyright © 2003 Pearson Education, Inc. Slide 40 Running a C++ Program  C++ source code is written with a text editor  The compiler on your system converts source code to object code.  The linker combines all the object code into an executable program.
  • 41. Copyright © 2003 Pearson Education, Inc. Slide 41 Run a Program  Obtain code in Display 1.10  Compile the code  Fix any errors the compiler indicates and re-compile the code  Run the program  Now you know how to run a program on your system Display 1.10
  • 42. Copyright © 2003 Pearson Education, Inc. Slide 42 Section 1.3 Conclusion  Can you…  Describe the output of this line? cout << “C++ is easy to understand.”;  Explain what this line does? cin >> peas_per_pod;  Explain this? #include <iostream>
  • 43. Copyright © 2003 Pearson Education, Inc. Slide 43 Testing and Debugging  Bug  A mistake in a program  Debugging  Eliminating mistakes in programs  Term used when a moth caused a failed relay on the Harvard Mark 1 computer. Grace Hopper and other programmers taped the moth in logbook stating: “First actual case of a bug being found.” 1.4
  • 44. Copyright © 2003 Pearson Education, Inc. Slide 44 Program Errors  Syntax errors  Violation of the grammar rules of the language  Discovered by the compiler  Error messages may not always show correct location of errors  Run-time errors  Error conditions detected by the computer at run-time  Logic errors  Errors in the program’s algorithm  Most difficult to diagnose  Computer does not recognize an error
  • 45. Copyright © 2003 Pearson Education, Inc. Slide 45 Section 1-4 Conclusion  Can you…  Describe the three kinds of program errors?  Tell what kind of errors the compiler catches?  What kind of error is produced if you forget a punctuation symbol such as a semi-colon?  Tell what type of error is produced when a program runs but produces incorrect results?
  • 46. Copyright © 2003 Pearson Education, Inc. Slide 46 Chapter 1 -- End
  • 47. Copyright © 2003 Pearson Education, Inc. Slide 47 Display 1.1 Back Next
  • 48. Copyright © 2003 Pearson Education, Inc. Slide 48 Display 1.2 Back Next
  • 49. Copyright © 2003 Pearson Education, Inc. Slide 49 Display 1.3 Back Next
  • 50. Copyright © 2003 Pearson Education, Inc. Slide 50 Display 1.4 Back Next
  • 51. Copyright © 2003 Pearson Education, Inc. Slide 51 Display 1.5 Back Next
  • 52. Copyright © 2003 Pearson Education, Inc. Slide 52 Display 1.6 Back Next
  • 53. Copyright © 2003 Pearson Education, Inc. Slide 53 Display 1.7 Back Next
  • 54. Copyright © 2003 Pearson Education, Inc. Slide 54 Display 1.8 Next Back
  • 55. Copyright © 2003 Pearson Education, Inc. Slide 55 Display 1.9 Back Next
  • 56. Copyright © 2003 Pearson Education, Inc. Slide 56 Display 1.10 Next Back