an introduction to programming with c++ fifth edition chapter 1 an introduction to programming
TRANSCRIPT
![Page 1: An Introduction to Programming with C++ Fifth Edition Chapter 1 An Introduction to Programming](https://reader036.vdocument.in/reader036/viewer/2022062407/56649d825503460f94a685f5/html5/thumbnails/1.jpg)
An Introduction to Programming with C++
Fifth Edition
Chapter 1An Introduction to Programming
![Page 2: An Introduction to Programming with C++ Fifth Edition Chapter 1 An Introduction to Programming](https://reader036.vdocument.in/reader036/viewer/2022062407/56649d825503460f94a685f5/html5/thumbnails/2.jpg)
An Introduction to Programming with C++, Fifth Edition 2
Objectives
• Explain the history of programming languages
• Explain the sequence, selection, and repetition structures
• Write simple algorithms using the sequence, selection, and repetition structures
![Page 3: An Introduction to Programming with C++ Fifth Edition Chapter 1 An Introduction to Programming](https://reader036.vdocument.in/reader036/viewer/2022062407/56649d825503460f94a685f5/html5/thumbnails/3.jpg)
An Introduction to Programming with C++, Fifth Edition 3
Concept Lesson
• Programmers
• A Brief History of Programming Languages
• Control Structures
• Summary
![Page 4: An Introduction to Programming with C++ Fifth Edition Chapter 1 An Introduction to Programming](https://reader036.vdocument.in/reader036/viewer/2022062407/56649d825503460f94a685f5/html5/thumbnails/4.jpg)
An Introduction to Programming with C++, Fifth Edition 4
Programmers
• Programs are the directions given to computers
• Programmers are the people who write computer programs– Applications programmers write, maintain, and/or
customize programs that handle a specific task– Systems programmers write and maintain
programs that help the computer carry out its basic operating functions
![Page 5: An Introduction to Programming with C++ Fifth Edition Chapter 1 An Introduction to Programming](https://reader036.vdocument.in/reader036/viewer/2022062407/56649d825503460f94a685f5/html5/thumbnails/5.jpg)
An Introduction to Programming with C++, Fifth Edition 5
A Brief History of Programming Languages
• Programming languages are the languages used to communicate with a computer– E.g., C++, C#, Java, Visual Basic, Perl, C, COBOL– Types
• Machine languages
• Assembly languages
• High-level languages
![Page 6: An Introduction to Programming with C++ Fifth Edition Chapter 1 An Introduction to Programming](https://reader036.vdocument.in/reader036/viewer/2022062407/56649d825503460f94a685f5/html5/thumbnails/6.jpg)
An Introduction to Programming with C++, Fifth Edition 6
Machine Languages
• The first programmers had to write the program instructions using only combinations of 0s and 1s– E.g., 00101 10001 10000
• 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 is tedious and error-prone; requires highly trained programmers
![Page 7: An Introduction to Programming with C++ Fifth Edition Chapter 1 An Introduction to Programming](https://reader036.vdocument.in/reader036/viewer/2022062407/56649d825503460f94a685f5/html5/thumbnails/7.jpg)
An Introduction to Programming with C++, Fifth Edition 7
Assembly Languages
• Assembly languages simplify programmer’s job
• Can use mnemonics instead of 0s and 1s– E.g., ADD bx, ax
• 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
![Page 8: An Introduction to Programming with C++ Fifth Edition Chapter 1 An Introduction to Programming](https://reader036.vdocument.in/reader036/viewer/2022062407/56649d825503460f94a685f5/html5/thumbnails/8.jpg)
An Introduction to Programming with C++, Fifth Edition 8
High-Level Languages
• High-level languages allow programmer to use English-like instructions– E.g., grossPay = hours * rate– High-level languages are more machine-independent
• Programs written in a high-level language can be used on many different types of computers
• Compilers convert the instructions into 0s and 1s
• Interpreters translate the program line by line as the program is running
![Page 9: An Introduction to Programming with C++ Fifth Edition Chapter 1 An Introduction to Programming](https://reader036.vdocument.in/reader036/viewer/2022062407/56649d825503460f94a685f5/html5/thumbnails/9.jpg)
An Introduction to Programming with C++, Fifth Edition 9
High-Level Languages (continued)
• 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 programmer to focus on the objects that the program can use to accomplish its goal– Examples: C++, Visual Basic, Java, C#
![Page 10: An Introduction to Programming with C++ Fifth Edition Chapter 1 An Introduction to Programming](https://reader036.vdocument.in/reader036/viewer/2022062407/56649d825503460f94a685f5/html5/thumbnails/10.jpg)
An Introduction to Programming with C++, Fifth Edition 10
Control Structures
• Programs are written using three basic structures– Sequence
• Used in every program you write
– Repetition• Used in most programs you write
– Selection• Used in most programs you write
• Called control structures or logic structures
![Page 11: An Introduction to Programming with C++ Fifth Edition Chapter 1 An Introduction to Programming](https://reader036.vdocument.in/reader036/viewer/2022062407/56649d825503460f94a685f5/html5/thumbnails/11.jpg)
An Introduction to Programming with C++, Fifth Edition 11
The Sequence Structure
• The sequence structure directs the computer to process the program instructions, one after another, in the order listed in the program
![Page 12: An Introduction to Programming with C++ Fifth Edition Chapter 1 An Introduction to Programming](https://reader036.vdocument.in/reader036/viewer/2022062407/56649d825503460f94a685f5/html5/thumbnails/12.jpg)
The Sequence Structure (continued)
An Introduction to Programming with C++, Fifth Edition 12
![Page 13: An Introduction to Programming with C++ Fifth Edition Chapter 1 An Introduction to Programming](https://reader036.vdocument.in/reader036/viewer/2022062407/56649d825503460f94a685f5/html5/thumbnails/13.jpg)
An Introduction to Programming with C++, Fifth Edition 13
The Repetition Structure
• Repetition structure: directs computer to repeat one or more instructions until some condition is met– Also called a loop or iteration
![Page 14: An Introduction to Programming with C++ Fifth Edition Chapter 1 An Introduction to Programming](https://reader036.vdocument.in/reader036/viewer/2022062407/56649d825503460f94a685f5/html5/thumbnails/14.jpg)
The Repetition Structure (continued)
An Introduction to Programming with C++, Fifth Edition 14
![Page 15: An Introduction to Programming with C++ Fifth Edition Chapter 1 An Introduction to Programming](https://reader036.vdocument.in/reader036/viewer/2022062407/56649d825503460f94a685f5/html5/thumbnails/15.jpg)
An Introduction to Programming with C++, Fifth Edition 15
The Repetition Structure (continued)
• What could you do if you don’t know precisely how many steps separate Rob from the chair?
![Page 16: An Introduction to Programming with C++ Fifth Edition Chapter 1 An Introduction to Programming](https://reader036.vdocument.in/reader036/viewer/2022062407/56649d825503460f94a685f5/html5/thumbnails/16.jpg)
The Repetition Structure (continued)
An Introduction to Programming with C++, Fifth Edition 16
![Page 17: An Introduction to Programming with C++ Fifth Edition Chapter 1 An Introduction to Programming](https://reader036.vdocument.in/reader036/viewer/2022062407/56649d825503460f94a685f5/html5/thumbnails/17.jpg)
An Introduction to Programming with C++, Fifth Edition 17
The Selection Structure
• Selection structure: makes a decision and then takes an appropriate action based on that decision– Also called the decision structure
![Page 18: An Introduction to Programming with C++ Fifth Edition Chapter 1 An Introduction to Programming](https://reader036.vdocument.in/reader036/viewer/2022062407/56649d825503460f94a685f5/html5/thumbnails/18.jpg)
The Selection Structure (continued)
An Introduction to Programming with C++, Fifth Edition 18
![Page 19: An Introduction to Programming with C++ Fifth Edition Chapter 1 An Introduction to Programming](https://reader036.vdocument.in/reader036/viewer/2022062407/56649d825503460f94a685f5/html5/thumbnails/19.jpg)
An Introduction to Programming with C++, Fifth Edition 19
The Selection Structure (continued)
![Page 20: An Introduction to Programming with C++ Fifth Edition Chapter 1 An Introduction to Programming](https://reader036.vdocument.in/reader036/viewer/2022062407/56649d825503460f94a685f5/html5/thumbnails/20.jpg)
An Introduction to Programming with C++, Fifth Edition 20
Summary
• Programs: 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 languages– High-level languages can be used to create procedure-
oriented programs or object-oriented programs
• Algorithm: step-by-step instructions that accomplish a task (not written in a programming language)– Algorithms contain one or more of the following control
structures: sequence, selection, and repetition
![Page 21: An Introduction to Programming with C++ Fifth Edition Chapter 1 An Introduction to Programming](https://reader036.vdocument.in/reader036/viewer/2022062407/56649d825503460f94a685f5/html5/thumbnails/21.jpg)
An Introduction to Programming with C++, Fifth Edition 21
Summary (continued)
• Sequence structure: process the instructions, one after another, in the order listed
• Repetition structure: repeat one or more instructions until some condition is met
• Selection structure: directs the computer to make a decision, and then to select an appropriate action based on that decision
![Page 22: An Introduction to Programming with C++ Fifth Edition Chapter 1 An Introduction to Programming](https://reader036.vdocument.in/reader036/viewer/2022062407/56649d825503460f94a685f5/html5/thumbnails/22.jpg)
An Introduction to Programming with C++, Fifth Edition 22
Application Lesson: Using the Control Structures
• Lab 1.1: Stop and Analyze
• Lab 1.2: salespeople selling more than $2,000 receive 3.5% bonus; all others receive 3% bonus
• Lab 1.3: