Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
C++ Programming: From Problem
Analysis to Program Design,

Fifth Edition

Chapter 1: An Overview of Computers and
Programm...
The Evolution of Programming
Languages (cont'd.)


High-level languages include Basic,
FORTRAN, COBOL, Pascal, C, C++, C#...
Processing a C++ Program
#include <iostream>
using namespace std;
int main()
{
cout << "My first C++ program." << endl;
re...
Processing a C++ Program (cont'd.)


To execute a C++ program:





Use an editor to create a source program in C++
Pr...
Processing a C++ Program (cont'd.)


To execute a C++ program (cont'd.):


Linker:


Combines object program with other...
Processing a C++ Program (cont'd.)

C++ Programming: From Problem Analysis to Program Design, Fifth Edition

Updated by: S...
Programming with the Problem Analysis–Coding–
Execution Cycle


Programming is a process of problem solving



One probl...
The Problem Analysis–Coding–Execution Cycle
(cont’d.)

C++ Programming: From Problem Analysis to Program Design, Fifth Edi...
The Problem Analysis–Coding–Execution Cycle
(cont'd.)



Run code through compiler
If compiler generates errors





...
The Problem Analysis–Coding–Execution Cycle
(cont'd.)





Once compiled and linked, loader can place
program into main...
Example 1-1




Design an algorithm to find the perimeter and
area of a rectangle
The perimeter and area of the rectangl...
Example 1-1 (cont'd.)


Algorithm:


Get length of the rectangle



Get width of the rectangle



Find the perimeter u...
Upcoming SlideShare
Loading in …5
×

C++ Programming Chapter 01

1,851 views

Published on

Study C++ Programming at PTC Siem Reap

Published in: Education
  • Be the first to comment

C++ Programming Chapter 01

  1. 1. C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 1: An Overview of Computers and Programming Languages Updated by: SENG Sourng
  2. 2. The Evolution of Programming Languages (cont'd.)  High-level languages include Basic, FORTRAN, COBOL, Pascal, C, C++, C#, and Java  Compiler: translates a program written in a high-level language machine language C++ Programming: From Problem Analysis to Program Design, Fifth Edition Updated by: SENG Sourng 2
  3. 3. Processing a C++ Program #include <iostream> using namespace std; int main() { cout << "My first C++ program." << endl; return 0; } Sample Run: My first C++ program. C++ Programming: From Problem Analysis to Program Design, Fifth Edition Updated by: SENG Sourng 3
  4. 4. Processing a C++ Program (cont'd.)  To execute a C++ program:    Use an editor to create a source program in C++ Preprocessor directives begin with # and are processed by a the preprocessor Use the compiler to:   Check that the program obeys the rules Translate into machine language (object program) C++ Programming: From Problem Analysis to Program Design, Fifth Edition Updated by: SENG Sourng 4
  5. 5. Processing a C++ Program (cont'd.)  To execute a C++ program (cont'd.):  Linker:  Combines object program with other programs provided by the SDK to create executable code  Loader:   Loads executable program into main memory The last step is to execute the program C++ Programming: From Problem Analysis to Program Design, Fifth Edition Updated by: SENG Sourng 5
  6. 6. Processing a C++ Program (cont'd.) C++ Programming: From Problem Analysis to Program Design, Fifth Edition Updated by: SENG Sourng 6
  7. 7. Programming with the Problem Analysis–Coding– Execution Cycle  Programming is a process of problem solving  One problem-solving technique:   Outline the problem requirements   Analyze the problem Design steps (algorithm) to solve the problem Algorithm:  Step-by-step problem-solving process  Solution achieved in finite amount of time C++ Programming: From Problem Analysis to Program Design, Fifth Edition Updated by: SENG Sourng 7
  8. 8. The Problem Analysis–Coding–Execution Cycle (cont’d.) C++ Programming: From Problem Analysis to Program Design, Fifth Edition Updated by: SENG Sourng 8
  9. 9. The Problem Analysis–Coding–Execution Cycle (cont'd.)   Run code through compiler If compiler generates errors    If there are no syntax errors   Look at code and remove errors Run code again through compiler Compiler generates equivalent machine code Linker links machine code with system resources C++ Programming: From Problem Analysis to Program Design, Fifth Edition Updated by: SENG Sourng 9
  10. 10. The Problem Analysis–Coding–Execution Cycle (cont'd.)    Once compiled and linked, loader can place program into main memory for execution The final step is to execute the program Compiler guarantees that the program follows the rules of the language  Does not guarantee that the program will run correctly C++ Programming: From Problem Analysis to Program Design, Fifth Edition Updated by: SENG Sourng 10
  11. 11. 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 Updated by: SENG Sourng 11
  12. 12. Example 1-1 (cont'd.)  Algorithm:  Get length of the rectangle  Get width of the rectangle  Find the perimeter using the following equation: perimeter = 2 * (length + width)  Find the area using the following equation: area = length * width C++ Programming: From Problem Analysis to Program Design, Fifth Edition Updated by: SENG Sourng 12

×