starting out with c++, 3 rd edition 1 chapter 1. introduction to computers and programming
TRANSCRIPT
![Page 1: Starting Out with C++, 3 rd Edition 1 Chapter 1. Introduction to Computers and Programming](https://reader035.vdocument.in/reader035/viewer/2022062320/56649d0c5503460f949e0f8b/html5/thumbnails/1.jpg)
1
Starting Out with C++, 3rd Edition
Chapter 1. Introduction to Computers and Programming
![Page 2: Starting Out with C++, 3 rd Edition 1 Chapter 1. Introduction to Computers and Programming](https://reader035.vdocument.in/reader035/viewer/2022062320/56649d0c5503460f949e0f8b/html5/thumbnails/2.jpg)
2
Starting Out with C++, 3rd Edition
1.1 Why Program?
• Computers can do many different jobs because they are programmable.
![Page 3: Starting Out with C++, 3 rd Edition 1 Chapter 1. Introduction to Computers and Programming](https://reader035.vdocument.in/reader035/viewer/2022062320/56649d0c5503460f949e0f8b/html5/thumbnails/3.jpg)
3
Starting Out with C++, 3rd Edition
1.2 Computer Systems: Hardware and Software
• All computer systems consist of similar hardware devices and software components. This section provides an overview of standard computer hardware and software organization.
![Page 4: Starting Out with C++, 3 rd Edition 1 Chapter 1. Introduction to Computers and Programming](https://reader035.vdocument.in/reader035/viewer/2022062320/56649d0c5503460f949e0f8b/html5/thumbnails/4.jpg)
4
Starting Out with C++, 3rd Edition
Hardware
1. The CPU
2. Main Memory
3. Secondary Storage
4. Input Devices
5. Output Devices
![Page 5: Starting Out with C++, 3 rd Edition 1 Chapter 1. Introduction to Computers and Programming](https://reader035.vdocument.in/reader035/viewer/2022062320/56649d0c5503460f949e0f8b/html5/thumbnails/5.jpg)
5
Starting Out with C++, 3rd Edition
InputDevice
CentralProcessing
Unit
MainMemory
OutputDevice
OutputDevice
Figure 1.1
![Page 6: Starting Out with C++, 3 rd Edition 1 Chapter 1. Introduction to Computers and Programming](https://reader035.vdocument.in/reader035/viewer/2022062320/56649d0c5503460f949e0f8b/html5/thumbnails/6.jpg)
6
Starting Out with C++, 3rd Edition
Figure 1.2
Arithmetic and Logic
Unit
Control Unit
Instruction(Input)
Result(Output)
![Page 7: Starting Out with C++, 3 rd Edition 1 Chapter 1. Introduction to Computers and Programming](https://reader035.vdocument.in/reader035/viewer/2022062320/56649d0c5503460f949e0f8b/html5/thumbnails/7.jpg)
7
Starting Out with C++, 3rd Edition
Software
– Operating Systems• Single tasking
• Multi-tasking
– Application Software
![Page 8: Starting Out with C++, 3 rd Edition 1 Chapter 1. Introduction to Computers and Programming](https://reader035.vdocument.in/reader035/viewer/2022062320/56649d0c5503460f949e0f8b/html5/thumbnails/8.jpg)
8
Starting Out with C++, 3rd Edition
1.3 Programs and Programming Languages
• What is a program?– A set of instructions a computer follows in
order to perform a task. A programming language is a special language used to write computer programs.
![Page 9: Starting Out with C++, 3 rd Edition 1 Chapter 1. Introduction to Computers and Programming](https://reader035.vdocument.in/reader035/viewer/2022062320/56649d0c5503460f949e0f8b/html5/thumbnails/9.jpg)
9
Starting Out with C++, 3rd Edition
Program 1-1
// This program calculates the user’s pay.
#include <iostream.h>
void main(void)
{
float hours, rate, pay;
cout << “How many hours did you work? ”;
cin >> hours;
cout << “How much do you get paid per hour? ”;
cin >> rate;
pay = hours * rate;
cout << “You have earned $” << pay << endl;
}
![Page 10: Starting Out with C++, 3 rd Edition 1 Chapter 1. Introduction to Computers and Programming](https://reader035.vdocument.in/reader035/viewer/2022062320/56649d0c5503460f949e0f8b/html5/thumbnails/10.jpg)
10
Starting Out with C++, 3rd Edition
Program Output
How many hours did you work? 10How much do you get paid per hour? 15You have earned $150
![Page 11: Starting Out with C++, 3 rd Edition 1 Chapter 1. Introduction to Computers and Programming](https://reader035.vdocument.in/reader035/viewer/2022062320/56649d0c5503460f949e0f8b/html5/thumbnails/11.jpg)
11
Starting Out with C++, 3rd Edition
Programming Languages
High level(Close to Human
Language)
Low level(Machine Language)
• Figure 1-4
![Page 12: Starting Out with C++, 3 rd Edition 1 Chapter 1. Introduction to Computers and Programming](https://reader035.vdocument.in/reader035/viewer/2022062320/56649d0c5503460f949e0f8b/html5/thumbnails/12.jpg)
12
Starting Out with C++, 3rd Edition
Table 1-1Language DescriptionBASIC Beginners All-purpose Symbolic Instruction Code.
A general programming language originallydesigned to be simple enough for beginners to learn.
FORTRAN Formula Translator. A language designed forprogramming complex mathematical algorithms.
COBOL Common Business-Oriented Language. A languagedesigned for business applications.
Pascal A structured, general purpose language designedprimarily for teaching programming.
C A structured, general purpose language developed atBell Labs. C offers both high-level and low-levelfeatures.
C++ Based on the C language, C++ offers object-orientedfeatures not found in C. Also invented at BellLaboratories.
Java An object-oriented language invented at SunMicrosystems. Java may be used to developprograms that run over the Internet, in a webbrowser.
![Page 13: Starting Out with C++, 3 rd Edition 1 Chapter 1. Introduction to Computers and Programming](https://reader035.vdocument.in/reader035/viewer/2022062320/56649d0c5503460f949e0f8b/html5/thumbnails/13.jpg)
13
Starting Out with C++, 3rd Edition
1.4 What is a Program Made of?• There are certain elements that are common
to all programming languages.– Key Words– Programmer-Defined Symbols– Operators– Punctuation
![Page 14: Starting Out with C++, 3 rd Edition 1 Chapter 1. Introduction to Computers and Programming](https://reader035.vdocument.in/reader035/viewer/2022062320/56649d0c5503460f949e0f8b/html5/thumbnails/14.jpg)
14
Starting Out with C++, 3rd Edition
Language Elements, Table 1-2LanguageElement
Description
Key Words Words that have a special meaning. Keywords may only be used for their intendedpurpose.
Programmer-DefinedSymbols
Words or names defined by the programmer.They are symbolic names that refer tovariables or programming routines.
Operators Operators perform operations on one or moreoperands. An operand is usually a piece ofdata, like a number.
Punctuation Punctuation characters that mark thebeginning or ending of a statement, orseparate items in a list.
Syntax Rules that must be followed whenconstruction a program. Syntax dictates howkey words and operators may be used, andwhere punctuation symbols must appear.
![Page 15: Starting Out with C++, 3 rd Edition 1 Chapter 1. Introduction to Computers and Programming](https://reader035.vdocument.in/reader035/viewer/2022062320/56649d0c5503460f949e0f8b/html5/thumbnails/15.jpg)
15
Starting Out with C++, 3rd Edition
Lines and Statements
cout << “How many hours did you work?”;
![Page 16: Starting Out with C++, 3 rd Edition 1 Chapter 1. Introduction to Computers and Programming](https://reader035.vdocument.in/reader035/viewer/2022062320/56649d0c5503460f949e0f8b/html5/thumbnails/16.jpg)
16
Starting Out with C++, 3rd Edition
Variables
• A storage location in the computer’s memory for holding a piece of information.
• Symbolic names that represent locations in the computer’s random-access memory.
![Page 17: Starting Out with C++, 3 rd Edition 1 Chapter 1. Introduction to Computers and Programming](https://reader035.vdocument.in/reader035/viewer/2022062320/56649d0c5503460f949e0f8b/html5/thumbnails/17.jpg)
17
Starting Out with C++, 3rd Edition
Variable Declarations
• Two types of information: numbers and characters
• Numbers may be integers or floating-point numbers
• The statement below creates three variables in memory named hours, rate, and pay that each can store a floating point number
float hours, rate, pay;
![Page 18: Starting Out with C++, 3 rd Edition 1 Chapter 1. Introduction to Computers and Programming](https://reader035.vdocument.in/reader035/viewer/2022062320/56649d0c5503460f949e0f8b/html5/thumbnails/18.jpg)
18
Starting Out with C++, 3rd Edition
1.5 Input, Processing, and Output
• Input:cin >> hours;
• Processing:pay = hours * rate;
• Outputcout<<“You have earned $”<<pay;
![Page 19: Starting Out with C++, 3 rd Edition 1 Chapter 1. Introduction to Computers and Programming](https://reader035.vdocument.in/reader035/viewer/2022062320/56649d0c5503460f949e0f8b/html5/thumbnails/19.jpg)
19
Starting Out with C++, 3rd Edition
1.6 The Programming Process
• The programming process consists of several steps, which include design, creation, testing and debugging activities.
![Page 20: Starting Out with C++, 3 rd Edition 1 Chapter 1. Introduction to Computers and Programming](https://reader035.vdocument.in/reader035/viewer/2022062320/56649d0c5503460f949e0f8b/html5/thumbnails/20.jpg)
20
Starting Out with C++, 3rd Edition
Designing and Creating a Program
1. Clearly define what the program is to do
2. Visualize the program running on the computer.
3. Design a flowchart or hierarchy chart
4. Check the flowchart or hierarchy chart for logical errors.
![Page 21: Starting Out with C++, 3 rd Edition 1 Chapter 1. Introduction to Computers and Programming](https://reader035.vdocument.in/reader035/viewer/2022062320/56649d0c5503460f949e0f8b/html5/thumbnails/21.jpg)
21
Starting Out with C++, 3rd Edition
5. Write a pseudocode version of the program.
6. Check the pseudocode for errors.
7. Write the actual program on paper.
8. Desk-check the program for errors.
9. Enter the code and compile it.
10. Correct any errors found during compilation. Repeat steps 9 and 10 as many times as necessary.
![Page 22: Starting Out with C++, 3 rd Edition 1 Chapter 1. Introduction to Computers and Programming](https://reader035.vdocument.in/reader035/viewer/2022062320/56649d0c5503460f949e0f8b/html5/thumbnails/22.jpg)
22
Starting Out with C++, 3rd Edition
11. Run the program with test data for input.
12. Correct any errors found while running the program. Repeat steps 9 through 12 as many times as necessary.
13. Validate the results of the program.
![Page 23: Starting Out with C++, 3 rd Edition 1 Chapter 1. Introduction to Computers and Programming](https://reader035.vdocument.in/reader035/viewer/2022062320/56649d0c5503460f949e0f8b/html5/thumbnails/23.jpg)
23
Starting Out with C++, 3rd Edition
1.7 Procedural and Object-Oriented Programming
• Procedural programming and object-oriented programming are two ways of thinking about software development and program design.