[go: up one dir, main page]

0% found this document useful (0 votes)
59 views12 pages

C++ Programming: From Problem Analysis To Program Design: Chapter 1: An Overview of Computers and Programming Languages

This document discusses an overview of C++ programming. It covers the evolution of programming languages from low-level machine languages to high-level languages like C++. It then explains the process of compiling, linking, and executing a C++ program. This involves writing code with an editor, preprocessing, compiling to machine code, linking with libraries, loading into memory, and running the program. It emphasizes that programming involves analyzing problems, designing algorithms to solve them, coding solutions, and executing the code in a cycle to debug and refine programs.

Uploaded by

Tarif Cemay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views12 pages

C++ Programming: From Problem Analysis To Program Design: Chapter 1: An Overview of Computers and Programming Languages

This document discusses an overview of C++ programming. It covers the evolution of programming languages from low-level machine languages to high-level languages like C++. It then explains the process of compiling, linking, and executing a C++ program. This involves writing code with an editor, preprocessing, compiling to machine code, linking with libraries, loading into memory, and running the program. It emphasizes that programming involves analyzing problems, designing algorithms to solve them, coding solutions, and executing the code in a cycle to debug and refine programs.

Uploaded by

Tarif Cemay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 12

C++ Programming: From Problem

Analysis to Program Design, Fifth Edition


Chapter 1: An Overview of
Computers and Programming
Languages

Updated by: Malak


Abdullah
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

Updated by: Malak


C++ Programming: From Problem Analysis to Program Design, Fifth Edition Abdullah 2
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.

Updated by: Malak


C++ Programming: From Problem Analysis to Program Design, Fifth Edition Abdullah 3
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)

Updated by: Malak


C++ Programming: From Problem Analysis to Program Design, Fifth Edition Abdullah 4
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

Updated by: Malak


C++ Programming: From Problem Analysis to Program Design, Fifth Edition Abdullah 5
Processing a C++ Program (cont'd.)

Updated by: Malak


C++ Programming: From Problem Analysis to Program Design, Fifth Edition Abdullah 6
Programming with the Problem
Analysis–Coding–Execution Cycle
 Programming is a process of problem solving
 One problem-solving technique:
 Analyze the problem
 Outline the problem requirements
 Design steps (algorithm) to solve the problem
 Algorithm:
 Step-by-step problem-solving process
 Solution achieved in finite amount of time

Updated by: Malak


C++ Programming: From Problem Analysis to Program Design, Fifth Edition Abdullah 7
The Problem Analysis–Coding–Execution
Cycle (cont’d.)

Updated by: Malak


C++ Programming: From Problem Analysis to Program Design, Fifth Edition Abdullah 8
The Problem Analysis–Coding–
Execution Cycle (cont'd.)
 Run code through compiler
 If compiler generates errors
 Look at code and remove errors
 Run code again through compiler
 If there are no syntax errors
 Compiler generates equivalent machine code
 Linker links machine code with system
resources

Updated by: Malak


C++ Programming: From Problem Analysis to Program Design, Fifth Edition Abdullah 9
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

Updated by: Malak


C++ Programming: From Problem Analysis to Program Design, Fifth Edition Abdullah 10
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

Updated by: Malak


C++ Programming: From Problem Analysis to Program Design, Fifth Edition Abdullah 11
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

Updated by: Malak


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

You might also like