SlideShare a Scribd company logo
1 of 26
An Introduction to Programming with C++
Eighth Edition
Chapter 1:
An Introduction to Programming
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
Chapter Objectives
• Define the terminology used in programming
• Explain the tasks performed by a programmer
• Understand the employment opportunities for
programmers and software engineers
• Explain the history of programming languages
• Explain the sequence, selection, and repetition
structures
• Write simple algorithms using the sequence, selection,
and repetition structures
An Introduction to Programming with C++, Eighth Edition 2
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
Programming a Computer
It is important to understand the relationship between the
terms programs, programmers, and programming
languages.
Programs - The directions that humans give to computers
Programmers - The people who create these directions
Programming Languages - Special languages used by
programmers to communicate directions to a computer
An Introduction to Programming with C++, Eighth Edition 3
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
The Programmer’s Job
• Programmers help solve computer problems
• Employee or freelance
• Typical steps involved
– Meet with user to determine problem
– Convert the problem into a program
– Test the program
– Provide user manual
An Introduction to Programming with C++, Eighth Edition 4
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
An Introduction to Programming with C++, Eighth Edition 5
What Traits Should a Software Developer
Possess?
• Analytical skills
• Communication skills
• Creativity
• Customer-service skills
• Detail oriented
• Problem-solving skills
• Teamwork
• Technical skills
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
Employment Opportunities
• Computer software engineer: designs an appropriate
solution to a user’s problem
• Computer programmer: codes a computer solution
• Coding is the process of translating a computer solution
into a language a computer can understand
• Some positions call for both engineering and
programming
An Introduction to Programming with C++, Eighth Edition 6
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
A Brief History of Programming Languages
There are many different types of programming
languages. This chapter will discuss:
•Machine languages
•Assembly languages
•High-level procedure-oriented languages
•High-level object-oriented languages
An Introduction to Programming with C++, Eighth Edition 7
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
An Introduction to Programming with C++, Eighth Edition 8
Machine Languages
• The first programmers had to write the program
instructions using only combinations of 0s and 1s
– Example: 0000 0101 1100 0000
• Instructions written in 0s and 1s are called machine
language or machine code
• Each type of machine has its own language
• Machine languages are the only way to communicate
directly with the computer
• Programming in machine language: tedious and error-
prone; requires highly trained programmers
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
An Introduction to Programming with C++, Eighth Edition 9
Assembly Languages
• Assembly languages made writing code simpler than
using only 0s and 1s
• Mnemonics – symbols used to represent the actual
machine language instructions
Example: 00000101 vs. BALR
• Assembly programs require an assembler to convert
instructions into machine code
• Easier to write programs in assembly language
– But still tedious and requires highly trained programmers
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
An Introduction to Programming with C++, Eighth Edition 10
High-Level Languages
• High-level languages allow programmers to use English-
like instructions
Example: taxAmount = total * taxRate
• Each high-level language instruction is equivalent to
more than one machine language instruction
• Compilers translate high-level instructions into 0s and
1s (machine language)
• Interpreters translate the program line by line as the
program is running
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
An Introduction to Programming with C++, Eighth Edition 11
High-Level Languages (cont.)
• When writing a procedure-oriented program, the
programmer concentrates on the major tasks that the
program needs to perform
– Examples: COBOL, BASIC, C
• An object-oriented program requires the programmer
to focus on the objects that the program can use to
accomplish its goal
– Examples: C++, Visual Basic, Java, C#
• Object-oriented programs allow for an object to be
created that can be reused in more than one program
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
An Introduction to Programming with C++, Eighth Edition 12
Control Structures
All computer programs are written using one or more of
three basic control structures: sequence, repetition, and
selection. Another term used for control structures are
logic structures, because they control the logic flow of the
program.
While in every program that is written the sequence
structure will be used, in most all programs all three
control structures will be used.
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
An Introduction to Programming with C++, Eighth Edition 13
The Sequence Structure
• The sequence structure directs the computer to
process the program instructions, one after another, in
the order in which they are listed in the program
• An algorithm is a finite number of step-by-step
instructions that accomplish a task
• Example: steps to pump gas at a self-service pump
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
The Sequence Structure (cont.)
An Introduction to Programming with C++, Eighth Edition 14
Figure 1-1 An example of the sequence structure
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
An Introduction to Programming with C++, Eighth Edition 15
The Selection Structure
• The selection structure directs the computer to make a
decision (evaluate a condition), and then take an
appropriate action based upon that decision
• The selection structure allows the programmer to
evaluate data, therefore properly controlling the logic
flow of the program
• Another name for the selection structure is the decision
structure
• Example: stopping or going at a signal light
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
The Selection Structure (cont.)
An Introduction to Programming with C++, Eighth Edition 16
Figure 1-2 An example of the selection structure
An Introduction to Programming with C++, Eighth Edition 17
The Selection Structure (cont.)
Figure 1-3 Another example of the selection structure
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
An Introduction to Programming with C++, Eighth Edition 18
The Repetition Structure
• The repetition structure, commonly called iteration or
looping, directs the computer to repeat one or more
program instructions until some condition is met
• This condition may be checked at the beginning or end
of the set of instructions to be processed dependent
upon the language being used
• The repetition structure allows the programmer to
repeatedly process a set of instructions, while only
typing them in once
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
The Repetition Structure (cont.)
An Introduction to Programming with C++, Eighth Edition 19
Original algorithm and modified algorithm
showing the repetition structure
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
Summary
• Programs are step-by-step instructions that tell a
computer how to perform a task
• Programmers use programming languages to
communicate with the computer
• First programming languages were machine language
using 0s and 1s
• Assembly languages followed, using mnemonics
• High-level languages can be used to created procedure-
oriented or object-oriented programs
An Introduction to Programming with C++, Eighth Edition 20
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
Summary (cont.)
• An algorithm is a finite number of step-by-step
instructions that accomplish a task
• Algorithms utilize three basic control structures:
sequence, selection, and repetition
• The sequence structure directs the computer to process
the program instructions, one after another, in the
order in which they are listed
• The selection structure directs the computer to make a
decision (evaluate a condition), and then take an
appropriate action based upon that decision
An Introduction to Programming with C++, Eighth Edition 21
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
Summary (cont.)
• The repetition structure, commonly called iteration or
looping, directs the computer to repeat one or more
program instructions until some condition is met
• The sequence structure is used in all programs
• Most programs also contain both the selection and
repetition structures
An Introduction to Programming with C++, Eighth Edition 22
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
Lab 1-1: Stop and Analyze
Study the algorithm below and answer the questions.
• Which control structures are used in the algorithm?
• What will the algorithm print when the price of the TV is $2,100?
• How would you modify the algorithm so that it can be used for only the
first 10 customers buying a TV?
• How would you modify the algorithm so that it allows the user to also
enter the discount rate and then uses that rate to calculate the
discount?
An Introduction to Programming with C++, Eighth Edition 23
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
An Introduction to Programming with C++, Eighth Edition 24
Lab 1-2: Plan and Create
The 10 salespeople at Harkins Company are paid a 10%
bonus when they sell more than $10,000 in product;
otherwise, they receive a 5% bonus. Create an
appropriate algorithm using only the instructions shown
below.
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
An Introduction to Programming with C++, Eighth Edition 25
Lab 1-3: Modify
Modify the algorithm shown below so that it gives a 25%
discount to customers who are also employees of the
store; all other customers receive a 15% discount.
© 2016 Cengage Learning®. May not be scanned, copied or
duplicated, or posted to a publicly accessible website, in
whole or in part.
An Introduction to Programming with C++, Eighth Edition 26
Lab 1-4: What’s Missing?
Harold wants to sit down on the park bench, but his cat Ginger may or may
not be already seated there. Put the instructions shown below in the
proper order, and then determine the one or more missing instructions.

More Related Content

What's hot

Introduction to computer programming
Introduction to computer programmingIntroduction to computer programming
Introduction to computer programming
NSU-Biliran Campus
 
Program logic and design
Program logic and designProgram logic and design
Program logic and design
Chaffey College
 

What's hot (20)

Computer Programming
Computer ProgrammingComputer Programming
Computer Programming
 
Introduction to computer programming
Introduction to computer programmingIntroduction to computer programming
Introduction to computer programming
 
Types of Programming Errors
Types of Programming ErrorsTypes of Programming Errors
Types of Programming Errors
 
Programming Fundamentals
Programming FundamentalsProgramming Fundamentals
Programming Fundamentals
 
Basic Computer Programming
Basic Computer ProgrammingBasic Computer Programming
Basic Computer Programming
 
Programming paradigm
Programming paradigmProgramming paradigm
Programming paradigm
 
Computer Fundamentals & Intro to C Programming module i
Computer Fundamentals & Intro to C Programming module iComputer Fundamentals & Intro to C Programming module i
Computer Fundamentals & Intro to C Programming module i
 
Programming Fundamental Presentation
Programming Fundamental PresentationProgramming Fundamental Presentation
Programming Fundamental Presentation
 
Programming languages
Programming languagesProgramming languages
Programming languages
 
Introduction to Coding
Introduction to CodingIntroduction to Coding
Introduction to Coding
 
introduction to programming languages
introduction to programming languagesintroduction to programming languages
introduction to programming languages
 
COMPUTER PROGRAMMING
COMPUTER PROGRAMMINGCOMPUTER PROGRAMMING
COMPUTER PROGRAMMING
 
Introduction to basic programming
Introduction to basic programmingIntroduction to basic programming
Introduction to basic programming
 
Compilers
CompilersCompilers
Compilers
 
Integrated Development Environments (IDE)
Integrated Development Environments (IDE) Integrated Development Environments (IDE)
Integrated Development Environments (IDE)
 
C language ppt
C language pptC language ppt
C language ppt
 
Program logic and design
Program logic and designProgram logic and design
Program logic and design
 
Programming in c
Programming in cProgramming in c
Programming in c
 
Computer programming concepts
Computer programming conceptsComputer programming concepts
Computer programming concepts
 
What is an algorithm?
What is an algorithm?What is an algorithm?
What is an algorithm?
 

Viewers also liked

Flowchart symbols
Flowchart symbolsFlowchart symbols
Flowchart symbols
giz82
 
Data com chapter 1 introduction
Data com chapter 1   introductionData com chapter 1   introduction
Data com chapter 1 introduction
Abdul-Hamid Donde
 
ICTCoreCh11
ICTCoreCh11ICTCoreCh11
ICTCoreCh11
garcons0
 
11. Computer Systems Hardware 1
11. Computer Systems   Hardware 111. Computer Systems   Hardware 1
11. Computer Systems Hardware 1
New Era University
 
Presentation on data communication
Presentation on data communicationPresentation on data communication
Presentation on data communication
Harpreet Dhaliwal
 

Viewers also liked (19)

Chapter 6 - More on the Selection Structure
Chapter 6 - More on the Selection StructureChapter 6 - More on the Selection Structure
Chapter 6 - More on the Selection Structure
 
Chapter 3 - Variables and Constants
Chapter 3 - Variables and ConstantsChapter 3 - Variables and Constants
Chapter 3 - Variables and Constants
 
Chapter 2 - Beginning the Problem-Solving Process
Chapter 2 - Beginning the Problem-Solving ProcessChapter 2 - Beginning the Problem-Solving Process
Chapter 2 - Beginning the Problem-Solving Process
 
Flowchart symbols
Flowchart symbolsFlowchart symbols
Flowchart symbols
 
1. c or c++ programming course out line
1. c or c++ programming course out line1. c or c++ programming course out line
1. c or c++ programming course out line
 
Operation engine ii session iv operations scheduling
Operation engine  ii session iv  operations schedulingOperation engine  ii session iv  operations scheduling
Operation engine ii session iv operations scheduling
 
2 the visible pc
2 the visible pc2 the visible pc
2 the visible pc
 
Data com chapter 1 introduction
Data com chapter 1   introductionData com chapter 1   introduction
Data com chapter 1 introduction
 
ICTCoreCh11
ICTCoreCh11ICTCoreCh11
ICTCoreCh11
 
11. Computer Systems Hardware 1
11. Computer Systems   Hardware 111. Computer Systems   Hardware 1
11. Computer Systems Hardware 1
 
Learning C++ - Introduction to c++ programming 1
Learning C++ - Introduction to c++ programming 1Learning C++ - Introduction to c++ programming 1
Learning C++ - Introduction to c++ programming 1
 
a+ ptc
a+ ptca+ ptc
a+ ptc
 
data communication
data communicationdata communication
data communication
 
C++ Programming Language
C++ Programming Language C++ Programming Language
C++ Programming Language
 
Data communications Class notes
Data communications  Class notesData communications  Class notes
Data communications Class notes
 
Powerpoint for data communication
Powerpoint for data communication Powerpoint for data communication
Powerpoint for data communication
 
Presentation on data communication
Presentation on data communicationPresentation on data communication
Presentation on data communication
 
Data communication and network Chapter -1
Data communication and network Chapter -1Data communication and network Chapter -1
Data communication and network Chapter -1
 
Chapter 1: Introduction to Data Communication and Networks
Chapter 1: Introduction to Data Communication and NetworksChapter 1: Introduction to Data Communication and Networks
Chapter 1: Introduction to Data Communication and Networks
 

Similar to Chapter 1 - An Introduction to Programming

Computing withBusiness Applications 1 Programming Log
Computing withBusiness Applications 1 Programming LogComputing withBusiness Applications 1 Programming Log
Computing withBusiness Applications 1 Programming Log
LynellBull52
 

Similar to Chapter 1 - An Introduction to Programming (20)

Lecture 1 programming fundamentals (PF)
Lecture 1 programming fundamentals (PF)Lecture 1 programming fundamentals (PF)
Lecture 1 programming fundamentals (PF)
 
Lesson 1 introduction to programming
Lesson 1 introduction to programmingLesson 1 introduction to programming
Lesson 1 introduction to programming
 
Lesson 9.2 guessing the game program
Lesson 9.2 guessing the game programLesson 9.2 guessing the game program
Lesson 9.2 guessing the game program
 
Chapter 9 Value-Returning Functions
Chapter 9 Value-Returning FunctionsChapter 9 Value-Returning Functions
Chapter 9 Value-Returning Functions
 
Chapter 4 - Completing the Problem-Solving Process
Chapter 4 - Completing the Problem-Solving ProcessChapter 4 - Completing the Problem-Solving Process
Chapter 4 - Completing the Problem-Solving Process
 
Chapter 5 - The Selection Structure
Chapter 5 - The Selection StructureChapter 5 - The Selection Structure
Chapter 5 - The Selection Structure
 
Chapter 8 - More on the Repetition Structure
Chapter 8 - More on the Repetition StructureChapter 8 - More on the Repetition Structure
Chapter 8 - More on the Repetition Structure
 
Introduction C Programming
Introduction C Programming Introduction C Programming
Introduction C Programming
 
Lesson 6.2 logic error
Lesson  6.2 logic errorLesson  6.2 logic error
Lesson 6.2 logic error
 
Lesson 9.1 value returning
Lesson 9.1 value returningLesson 9.1 value returning
Lesson 9.1 value returning
 
First draft programming c++
First draft programming c++First draft programming c++
First draft programming c++
 
Introduction to Compiler design
Introduction to Compiler design Introduction to Compiler design
Introduction to Compiler design
 
Lesson 8 more on repitition structure
Lesson 8 more on repitition structureLesson 8 more on repitition structure
Lesson 8 more on repitition structure
 
C.pdf
C.pdfC.pdf
C.pdf
 
Beekman5 std ppt_13
Beekman5 std ppt_13Beekman5 std ppt_13
Beekman5 std ppt_13
 
Computing withBusiness Applications 1 Programming Log
Computing withBusiness Applications 1 Programming LogComputing withBusiness Applications 1 Programming Log
Computing withBusiness Applications 1 Programming Log
 
Programming in c
Programming in cProgramming in c
Programming in c
 
Programming in C
Programming in CProgramming in C
Programming in C
 
Embedded c c++ programming fundamentals master
Embedded c c++ programming fundamentals masterEmbedded c c++ programming fundamentals master
Embedded c c++ programming fundamentals master
 
How to Become a Front-End Developer? Step-by-Step Guide by Careervira
How to Become a Front-End Developer? Step-by-Step Guide by CareerviraHow to Become a Front-End Developer? Step-by-Step Guide by Careervira
How to Become a Front-End Developer? Step-by-Step Guide by Careervira
 

Recently uploaded

Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
AnaAcapella
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
httgc7rh9c
 

Recently uploaded (20)

Our Environment Class 10 Science Notes pdf
Our Environment Class 10 Science Notes pdfOur Environment Class 10 Science Notes pdf
Our Environment Class 10 Science Notes pdf
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf arts
 
Economic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food AdditivesEconomic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food Additives
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdfUGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
Play hard learn harder: The Serious Business of Play
Play hard learn harder:  The Serious Business of PlayPlay hard learn harder:  The Serious Business of Play
Play hard learn harder: The Serious Business of Play
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learning
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111
 
Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17
 

Chapter 1 - An Introduction to Programming

  • 1. An Introduction to Programming with C++ Eighth Edition Chapter 1: An Introduction to Programming
  • 2. © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Chapter Objectives • Define the terminology used in programming • Explain the tasks performed by a programmer • Understand the employment opportunities for programmers and software engineers • Explain the history of programming languages • Explain the sequence, selection, and repetition structures • Write simple algorithms using the sequence, selection, and repetition structures An Introduction to Programming with C++, Eighth Edition 2
  • 3. © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Programming a Computer It is important to understand the relationship between the terms programs, programmers, and programming languages. Programs - The directions that humans give to computers Programmers - The people who create these directions Programming Languages - Special languages used by programmers to communicate directions to a computer An Introduction to Programming with C++, Eighth Edition 3
  • 4. © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. The Programmer’s Job • Programmers help solve computer problems • Employee or freelance • Typical steps involved – Meet with user to determine problem – Convert the problem into a program – Test the program – Provide user manual An Introduction to Programming with C++, Eighth Edition 4
  • 5. © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. An Introduction to Programming with C++, Eighth Edition 5 What Traits Should a Software Developer Possess? • Analytical skills • Communication skills • Creativity • Customer-service skills • Detail oriented • Problem-solving skills • Teamwork • Technical skills
  • 6. © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Employment Opportunities • Computer software engineer: designs an appropriate solution to a user’s problem • Computer programmer: codes a computer solution • Coding is the process of translating a computer solution into a language a computer can understand • Some positions call for both engineering and programming An Introduction to Programming with C++, Eighth Edition 6
  • 7. © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. A Brief History of Programming Languages There are many different types of programming languages. This chapter will discuss: •Machine languages •Assembly languages •High-level procedure-oriented languages •High-level object-oriented languages An Introduction to Programming with C++, Eighth Edition 7
  • 8. © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. An Introduction to Programming with C++, Eighth Edition 8 Machine Languages • The first programmers had to write the program instructions using only combinations of 0s and 1s – Example: 0000 0101 1100 0000 • Instructions written in 0s and 1s are called machine language or machine code • Each type of machine has its own language • Machine languages are the only way to communicate directly with the computer • Programming in machine language: tedious and error- prone; requires highly trained programmers
  • 9. © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. An Introduction to Programming with C++, Eighth Edition 9 Assembly Languages • Assembly languages made writing code simpler than using only 0s and 1s • Mnemonics – symbols used to represent the actual machine language instructions Example: 00000101 vs. BALR • Assembly programs require an assembler to convert instructions into machine code • Easier to write programs in assembly language – But still tedious and requires highly trained programmers
  • 10. © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. An Introduction to Programming with C++, Eighth Edition 10 High-Level Languages • High-level languages allow programmers to use English- like instructions Example: taxAmount = total * taxRate • Each high-level language instruction is equivalent to more than one machine language instruction • Compilers translate high-level instructions into 0s and 1s (machine language) • Interpreters translate the program line by line as the program is running
  • 11. © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. An Introduction to Programming with C++, Eighth Edition 11 High-Level Languages (cont.) • When writing a procedure-oriented program, the programmer concentrates on the major tasks that the program needs to perform – Examples: COBOL, BASIC, C • An object-oriented program requires the programmer to focus on the objects that the program can use to accomplish its goal – Examples: C++, Visual Basic, Java, C# • Object-oriented programs allow for an object to be created that can be reused in more than one program
  • 12. © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. An Introduction to Programming with C++, Eighth Edition 12 Control Structures All computer programs are written using one or more of three basic control structures: sequence, repetition, and selection. Another term used for control structures are logic structures, because they control the logic flow of the program. While in every program that is written the sequence structure will be used, in most all programs all three control structures will be used.
  • 13. © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. An Introduction to Programming with C++, Eighth Edition 13 The Sequence Structure • The sequence structure directs the computer to process the program instructions, one after another, in the order in which they are listed in the program • An algorithm is a finite number of step-by-step instructions that accomplish a task • Example: steps to pump gas at a self-service pump
  • 14. © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. The Sequence Structure (cont.) An Introduction to Programming with C++, Eighth Edition 14 Figure 1-1 An example of the sequence structure
  • 15. © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. An Introduction to Programming with C++, Eighth Edition 15 The Selection Structure • The selection structure directs the computer to make a decision (evaluate a condition), and then take an appropriate action based upon that decision • The selection structure allows the programmer to evaluate data, therefore properly controlling the logic flow of the program • Another name for the selection structure is the decision structure • Example: stopping or going at a signal light
  • 16. © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. The Selection Structure (cont.) An Introduction to Programming with C++, Eighth Edition 16 Figure 1-2 An example of the selection structure
  • 17. An Introduction to Programming with C++, Eighth Edition 17 The Selection Structure (cont.) Figure 1-3 Another example of the selection structure
  • 18. © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. An Introduction to Programming with C++, Eighth Edition 18 The Repetition Structure • The repetition structure, commonly called iteration or looping, directs the computer to repeat one or more program instructions until some condition is met • This condition may be checked at the beginning or end of the set of instructions to be processed dependent upon the language being used • The repetition structure allows the programmer to repeatedly process a set of instructions, while only typing them in once
  • 19. © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. The Repetition Structure (cont.) An Introduction to Programming with C++, Eighth Edition 19 Original algorithm and modified algorithm showing the repetition structure
  • 20. © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Summary • Programs are step-by-step instructions that tell a computer how to perform a task • Programmers use programming languages to communicate with the computer • First programming languages were machine language using 0s and 1s • Assembly languages followed, using mnemonics • High-level languages can be used to created procedure- oriented or object-oriented programs An Introduction to Programming with C++, Eighth Edition 20
  • 21. © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Summary (cont.) • An algorithm is a finite number of step-by-step instructions that accomplish a task • Algorithms utilize three basic control structures: sequence, selection, and repetition • The sequence structure directs the computer to process the program instructions, one after another, in the order in which they are listed • The selection structure directs the computer to make a decision (evaluate a condition), and then take an appropriate action based upon that decision An Introduction to Programming with C++, Eighth Edition 21
  • 22. © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Summary (cont.) • The repetition structure, commonly called iteration or looping, directs the computer to repeat one or more program instructions until some condition is met • The sequence structure is used in all programs • Most programs also contain both the selection and repetition structures An Introduction to Programming with C++, Eighth Edition 22
  • 23. © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Lab 1-1: Stop and Analyze Study the algorithm below and answer the questions. • Which control structures are used in the algorithm? • What will the algorithm print when the price of the TV is $2,100? • How would you modify the algorithm so that it can be used for only the first 10 customers buying a TV? • How would you modify the algorithm so that it allows the user to also enter the discount rate and then uses that rate to calculate the discount? An Introduction to Programming with C++, Eighth Edition 23
  • 24. © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. An Introduction to Programming with C++, Eighth Edition 24 Lab 1-2: Plan and Create The 10 salespeople at Harkins Company are paid a 10% bonus when they sell more than $10,000 in product; otherwise, they receive a 5% bonus. Create an appropriate algorithm using only the instructions shown below.
  • 25. © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. An Introduction to Programming with C++, Eighth Edition 25 Lab 1-3: Modify Modify the algorithm shown below so that it gives a 25% discount to customers who are also employees of the store; all other customers receive a 15% discount.
  • 26. © 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. An Introduction to Programming with C++, Eighth Edition 26 Lab 1-4: What’s Missing? Harold wants to sit down on the park bench, but his cat Ginger may or may not be already seated there. Put the instructions shown below in the proper order, and then determine the one or more missing instructions.