C++ Programming: From Problem Analysis To Program Design: Chapter 1: An Overview of Computers and Programming Languages
C++ Programming: From Problem Analysis To Program Design: Chapter 1: An Overview of Computers and Programming Languages
Objectives
In this chapter, you will: Learn about different types of computers Explore the hardware and software components of a computer system Learn about the language of a computer Learn about the evolution of programming languages Examine high-level programming languages
C++ Programming: From Problem Analysis to Program Design, Fifth Edition 2
Objectives (cont'd.)
Discover what a compiler is and what it does Examine a C++ program Explore how a C++ program is processed Learn what an algorithm is and explore problem-solving techniques Become aware of structured design and object-oriented design programming methodologies Become aware of Standard C++ and ANSI/ISO Standard C++
C++ Programming: From Problem Analysis to Program Design, Fifth Edition 3
Introduction
Without software, the computer is useless Software developed with programming languages
C++ is a programming language
C++ suited for a wide variety of programming tasks Before programming, it is useful to understand terminology and computer components
C++ Programming: From Problem Analysis to Program Design, Fifth Edition 4
Hardware
CPU Main memory: RAM Input/output devices Secondary storage
10
11
Secondary Storage
Secondary storage: device that stores information permanently Examples of secondary storage:
Hard disks Flash drives Floppy disks Zip disks CD-ROMs Tapes
C++ Programming: From Problem Analysis to Program Design, Fifth Edition 13
Input/Output Devices
Input devices feed data and programs into computers
Keyboard Mouse Secondary storage
Software
Software: programs that do specific tasks System programs take control of the computer, such as an operating system Application programs perform a specific task
Word processors Spreadsheets Games
C++ Programming: From Problem Analysis to Program Design, Fifth Edition 15
Binary code:
A sequence of 0s and 1s
Byte:
C++ Programming: From Problem Analysis to Program Design, Fifth Edition
16
17
18
Unicode
65536 characters Two bytes are needed to store a character
19
21
22
Sample Run:
My first C++ program.
24
25
Loader:
Loads executable program into main memory
26
27
Algorithm:
Step-by-step problem-solving process
Solution achieved in finite amount of time
C++ Programming: From Problem Analysis to Program Design, Fifth Edition 28
Step 3: Maintenance
Use and modify the program if the problem domain changes
C++ Programming: From Problem Analysis to Program Design, Fifth Edition 29
30
32
33
Example 1-1
Design an algorithm to find the perimeter and area of a rectangle The perimeter and area of the rectangle are given by the following formulas: perimeter = 2 * (length + width) area = length * width
C++ Programming: From Problem Analysis to Program Design, Fifth Edition 36
Example 1-3
Every salesperson has a base salary Salesperson receives $10 bonus at the end of the month for each year worked if he or she has been with the store for five or less years The bonus is $20 for each year that he or she has worked there if over 5 years
38
39
Get noOfServiceYears
Calculate bonus using the following formula:
if (noOfServiceYears is less than or equal to five) bonus = 10 * noOfServiceYears
otherwise
bonus = 20 * noOfServiceYears
Get totalSales
C++ Programming: From Problem Analysis to Program Design, Fifth Edition 40
41
42
Example 1-5
10 students in a class Each student has taken five tests and each test is worth 100 points Design an algorithm to calculate the grade for each student as well as the class average
Design an algorithm to find the average test score Design an algorithm to determine the grade
45
Programming Methodologies
Two popular approaches to programming design
Structured
Object-oriented
47
Structured Programming
Structured design:
Dividing a problem into smaller subproblems
Structured programming:
Implementing a structured design
Object-Oriented Programming
Identify components called objects Specify relevant data and possible operations to be performed on that data Each object consists of data and operations on that data An object combines data and operations on the data into a single unit
49
51
52
Summary
Computer: electronic device that can perform arithmetic and logical operations Computer system has hardware and software Central processing unit (CPU): brain Primary storage (MM) is volatile; secondary storage (e.g., disk) is permanent Operating system monitors the overall activity of the computer and provides services
53
Summary (cont'd.)
Various kinds of languages, such as machine language, assembly, high-level Algorithm: step-by-step problem-solving process; solution in finite amount of time Problem-solving process has three steps:
Analyze problem and design an algorithm Implement the algorithm in code Maintain the program
C++ Programming: From Problem Analysis to Program Design, Fifth Edition 54
Summary (cont'd.)
Structured design:
Problem is divided into smaller subproblems Each subproblem is solved Combine solutions to all subproblems
55