SlideShare a Scribd company logo
Programming 1
Guntur Budi Herwanto
gunturbudi@ugm.ac.id
Hello
•Lecturers:
•Guntur Budi H (Before Mid)
•Mhd Reza Pulungan (After Mid)
Google Classroom Code
7u00v2
Join in Netacad
ugm.id/cpaprg19
Course Companion: CPA C++
Before we Start
1 5 6 3 9 2 4
What is this course about
INTENDED FOR YOU
WITH LITTLE OR NO
“PROGRAMMING”
EXPERIENCE.
01
LEARN “ALGORITHM“
THE ROLE
COMPUTATION CAN
PLAY IN SOLVING
PROBLEMS
02
WRITING CODE
USING A
“PROGRAMMING
LANGUAGE”
03
Why C++ ?
• You can’t learn to program without a programming
language
• The purpose of a programming language is to allow
you to express your ideas in code
• C++ is the language that most directly allows you to
express ideas from the largest number of application
areas
• C++ is the most widely used language in engineering
areas (http://www.stroustrup.com/applications.html)
Why C++
C++ is precisely and
comprehensively
defined by an ISO
standard
C++ is available on
almost all kinds of
computers
Programming concepts
that you learn using C++
can be used fairly
directly in other
languages
Including C, Java, C#, and (less
directly) Fortran
Course Outcome
1. Have knowledge about the importance of algorithms and data structures in
solving problems
2. Have knowledge about components in algorithms and can construct
algorithms to solve simple problems.
3. Have knowledge about data structures and C++ programming language.
4. Have knowledge about data types for array and records / struct and can
implement them in a computer program.
5. Have knowledge about modular programming and can implement it in a
computer program.
6. Be able to explain and competent in how to implement sorting and searching
algorithms.
7. Have knowledge about pointer data type and can implement it in a computer
program.
8. Be able and competent in solving more complex programming problems.
Assesment
CO1: Problem 1 in mid-
term exam (5%) and
exercise 1 (5%) - 10%
CO2: Problem 2 in mid-
term exam (5%) and
exercise 2 (5%) - 10%
CO3: Problem 3 in mid-
term exam (5%); problem 4
in mid-term exam (5%);
assignment 1: make an
algorithm and computer
program (5%); and exercise
3 (5%) - 20%
CO4: Problem 5 in mid-
term exam (5%); problem 1
in final exam (5%) and
exercise 4 (5%) - 15%
CO5: Problem 2 in final
exam (5%); assignment 2:
make a function and
recursive (5%); and
exercise 5 (5%) - 15%
CO6: Problem 3 in final
exam (5%) and exercise 6
(5%) - 10%
CO7: Problem 4 in final
exam (5%) and exercise 7
(5%) - 10%
CO8: Problem 5 in final
exam (5%) and assignment
3: make a program based
on a real-life problem (5%)
- 10%
Main Reference
C++ PROGRAMMING :
FROM PROBLEM ANALYSIS TO
PROGRAM DESIGN
SIXTH EDITION
D.S. MALIK
Course Topics
Introduction Algorithm
Data Type &
Operator
Control
Structure –
Condition
Control
Structure –
Repetition
Array Struct Function
Sorting &
Searching
Pointer
Why programming?
Our civilization runs on
software
Most engineering activities involve software
Note: most programs do not run on things that look like a
PC (a screen, a keyboard, a box under the table)
14
Phones
• Chat
• Social Media
• Payment
• Security
• Call
• SMS
PC / Tablet / Workstation
• Operating System
• Computer
Program
Energy
• Control
• Monitoring
• Analysis
• Design
• Communications
• Visualization
• Manufacturing
Aircraft
• Communication
• Control
• Display
Ships
• Design
• Construction
• Management
19
Just about everywhere
http://www.stroustrup.com/applications.html
Algorithm
• An unambiguous specification of how to solve a class of problems.
Algorithms can perform calculation, data processing and automated
reasoning tasks.
• Algorithms are essential to the way computers process data.
• Algorithms can be expressed in many kinds of notation, including
natural languages, pseudocode, flowcharts, or programming
languages.
Algorithm Design
1. Problem definition
2. Development of a model
3. Specification of algorithm
4. Designing an algorithm
5. Checking the correctness of algorithm
6. Analysis of algorithm
7. Implementation of algorithm
8. Program testing
9. Documentation preparation
Example #1
Find the largest number in a list of numbers of random order
Example #1 – High Level Description
1. If there are no numbers in the set then there is no highest number.
2. Assume the first number in the set is the largest number in the set.
3. For each remaining number in the set: if this number is larger than
the current largest number, consider this number to be the largest
number in the set.
4. When there are no numbers left in the set to iterate over, consider
the current largest number to be the largest number of the set.
Example #1 - Pseudocode
Example #2
• Compute the greatest common divisor (GCD) to two numbers
• Euclid’s Algorithm
• Euclid poses the problem thus: "Given two numbers not prime to one
another, to find their greatest common measure"
Example #2 – Flowchart
Example #2 - Code
Exercise
Design an algorithm that calculates the monthly paycheck of a salesperson
at a local department store
• Every salesperson has a base salary.
• The salesperson also receives a bonus at the end of each month, based on
the following criteria:
• If the salesperson has been with the store for five years or less, the bonus is $ 10 for
each year that he or she has worked there.
• If the salesperson has been with the store for more than five years, the bonus is $ 20
for each year that he or she has worked there.
• The salesperson can earn an additional bonus as follows: If the total sales made by
the salesperson for the month are at least $ 5,000 but less than $ 10,000, he or she
receives a 3% commission on the sale. If the total sales made by the salesperson for
the month are at least $ 10,000, he or she receives a 6% commission on the sale.
First Program:
Hello, world
30
Updated by: Malak Abdullah
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.
31
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)
32
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
33
Processing a C++ Program (cont'd.)
34
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
35
The Problem Analysis–Coding–Execution Cycle
(cont’d.)
36
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
37
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
38
39
So what is programming?
• Conventional definitions
• Telling a very fast moron exactly what to do
• A plan for solving a problem on a computer
• Specifying the order of a program execution
• But modern programs often involve millions of lines of code
• And manipulation of data is central
• Definition from another domain (academia)
• A … program is an organized and directed accumulation of resources to
accomplish specific … objectives …
• Good, but no mention of actually doing anything
• The definition we’ll use
• Specifying the structure and behavior of a program, and testing that the program
performs its task correctly and with acceptable performance
• Never forget to check that “it” works
• Software == one or more programs
40
Programming
• Programming is fundamentally simple
• Just state what the machine is to do
• So why is programming hard?
• We want “the machine” to do complex things
• And computers are nitpicking, unforgiving, dumb beasts
• The world is more complex than we’d like to believe
• So we don’t always know the implications of what we want
• “Programming is understanding”
• When you can program a task, you understand it
• When you program, you spend significant time trying to understand the task you want to
automate
• Programming is part practical, part theory
• If you are just practical, you produce non-scalable unmaintainable hacks
• If you are just theoretical, you produce toys
Reference
• Bjarne Stroustrup, 2015, Texas A&M University
• D.S. Malik, C++ Programming: From Problem Analysis to Program
Design, Fourth Edition

More Related Content

Similar to Pengenalan algoritma dasar dalam pemrograman (20)

DOCX
Lecture1
Andrew Raj
 
PDF
Lecture 7 program development issues (supplementary)
alvin567
 
PPT
Programing Fundamental
Qazi Shahzad Ali
 
PDF
Raising the Bar
Alexandru Bolboaca
 
PPTX
Programming_Lecture_1.pptx
shoaibkhan716300
 
PPTX
Power Point Introduction To Programming 1
FabianDaffa3
 
PPTX
COM1407: Structured Program Development
Hemantha Kulathilake
 
PPT
C++ programming program design including data structures
Ahmad Idrees
 
PPTX
Algorithm and C code related to data structure
Self-Employed
 
PPT
Chapter 01.PPT
JoeBlack136
 
PDF
Algorithmic problem sloving
Mani Kandan
 
PPTX
Introduction to C ++.pptx
VAIBHAVKADAGANCHI
 
PDF
Study Material for Problem Solving Techniques
Bobby Murugesan
 
PPT
Intro. to prog. c++
KurdGul
 
PPTX
Chp-1 DAA (2).pptx design analysis and algoritham presentation
vaishnavbhavna17
 
PPTX
Overview of Software Engineering Principles - SCPS311.pptx
BypassFrp
 
PPT
Programming of c++
Ateeq Sindhu
 
DOCX
Chapter 2(1)
TejaswiB4
 
PPTX
Algorithms and flow charts
Chinnu Edwin
 
PPTX
jhdgqwuysuty1yyd uhudgqwygd ueu1eu2.pptx
Thrisha59
 
Lecture1
Andrew Raj
 
Lecture 7 program development issues (supplementary)
alvin567
 
Programing Fundamental
Qazi Shahzad Ali
 
Raising the Bar
Alexandru Bolboaca
 
Programming_Lecture_1.pptx
shoaibkhan716300
 
Power Point Introduction To Programming 1
FabianDaffa3
 
COM1407: Structured Program Development
Hemantha Kulathilake
 
C++ programming program design including data structures
Ahmad Idrees
 
Algorithm and C code related to data structure
Self-Employed
 
Chapter 01.PPT
JoeBlack136
 
Algorithmic problem sloving
Mani Kandan
 
Introduction to C ++.pptx
VAIBHAVKADAGANCHI
 
Study Material for Problem Solving Techniques
Bobby Murugesan
 
Intro. to prog. c++
KurdGul
 
Chp-1 DAA (2).pptx design analysis and algoritham presentation
vaishnavbhavna17
 
Overview of Software Engineering Principles - SCPS311.pptx
BypassFrp
 
Programming of c++
Ateeq Sindhu
 
Chapter 2(1)
TejaswiB4
 
Algorithms and flow charts
Chinnu Edwin
 
jhdgqwuysuty1yyd uhudgqwygd ueu1eu2.pptx
Thrisha59
 

More from ssuser58c832 (20)

PPTX
Input/Output - Organisasi dan Arsitektur Komputer.pptx
ssuser58c832
 
PPTX
Arithmetic Logic Unit (ALU) - Organisasi Arsitektur Komputer.pptx
ssuser58c832
 
PPTX
Sistem Informasi, Organisasi, dan Strategi.pptx
ssuser58c832
 
PPTX
Enterprise Resource Planning (ERP)).pptx
ssuser58c832
 
PPTX
Pertemuan 5 - Penyederhanaan Fungsi Boolean.pptx
ssuser58c832
 
PPTX
Pertemuan 6 - Logika Kombinasionall.pptx
ssuser58c832
 
PPTX
Enhancing Decision Making - Pertemuan 12.pptx
ssuser58c832
 
PPTX
Managing Knowledge (Mengelola Pengetahuan) .pptx
ssuser58c832
 
PPTX
TELEKOMUNIKASI, INTERNET, DAN TEKNOLOGI NIRKABEL.pptx
ssuser58c832
 
PPTX
Mengelola Sumber Data (Pertemuan 6).pptx
ssuser58c832
 
PPTX
Pertemuan 3 - Kondisional dan Perulangan.pptx
ssuser58c832
 
PPTX
Pertemuan 2 - Tipe Data, Variable, Konstanta. pptx
ssuser58c832
 
PPTX
Organisasi dan Arsitektur Komputer Semester 1 - Petemuan 6.pptx
ssuser58c832
 
PPTX
Organisasi dan Arsitektur Komputer Semester 1 - Petemuan 7.pptx
ssuser58c832
 
PPTX
Infrastruktur TI dan Perkembangan Teknologi.pptx
ssuser58c832
 
PPTX
Organisasi Sistem Komputer Semester 2 - Petemuan 10.pptx
ssuser58c832
 
PPTX
Organisasi Sistem Komputer Semester 2 - Petemuan 3.pptx
ssuser58c832
 
PPTX
Organisasi Sistem Komputer Semester 2 - Petemuan 3.pptx
ssuser58c832
 
PPTX
HCI - 4 - Persona & Scenario Human Computer Interaction.pptx
ssuser58c832
 
PPTX
HCI - 5-6 -Design Process Interaksi Manusi Komputer.pptx
ssuser58c832
 
Input/Output - Organisasi dan Arsitektur Komputer.pptx
ssuser58c832
 
Arithmetic Logic Unit (ALU) - Organisasi Arsitektur Komputer.pptx
ssuser58c832
 
Sistem Informasi, Organisasi, dan Strategi.pptx
ssuser58c832
 
Enterprise Resource Planning (ERP)).pptx
ssuser58c832
 
Pertemuan 5 - Penyederhanaan Fungsi Boolean.pptx
ssuser58c832
 
Pertemuan 6 - Logika Kombinasionall.pptx
ssuser58c832
 
Enhancing Decision Making - Pertemuan 12.pptx
ssuser58c832
 
Managing Knowledge (Mengelola Pengetahuan) .pptx
ssuser58c832
 
TELEKOMUNIKASI, INTERNET, DAN TEKNOLOGI NIRKABEL.pptx
ssuser58c832
 
Mengelola Sumber Data (Pertemuan 6).pptx
ssuser58c832
 
Pertemuan 3 - Kondisional dan Perulangan.pptx
ssuser58c832
 
Pertemuan 2 - Tipe Data, Variable, Konstanta. pptx
ssuser58c832
 
Organisasi dan Arsitektur Komputer Semester 1 - Petemuan 6.pptx
ssuser58c832
 
Organisasi dan Arsitektur Komputer Semester 1 - Petemuan 7.pptx
ssuser58c832
 
Infrastruktur TI dan Perkembangan Teknologi.pptx
ssuser58c832
 
Organisasi Sistem Komputer Semester 2 - Petemuan 10.pptx
ssuser58c832
 
Organisasi Sistem Komputer Semester 2 - Petemuan 3.pptx
ssuser58c832
 
Organisasi Sistem Komputer Semester 2 - Petemuan 3.pptx
ssuser58c832
 
HCI - 4 - Persona & Scenario Human Computer Interaction.pptx
ssuser58c832
 
HCI - 5-6 -Design Process Interaksi Manusi Komputer.pptx
ssuser58c832
 
Ad

Recently uploaded (20)

PPTX
FSE_LLM4SE1_A Tool for In-depth Analysis of Code Execution Reasoning of Large...
cl144
 
PDF
June 2025 - Top 10 Read Articles in Network Security and Its Applications
IJNSA Journal
 
PDF
13th International Conference of Security, Privacy and Trust Management (SPTM...
ijcisjournal
 
PPTX
Engineering Quiz ShowEngineering Quiz Show
CalvinLabial
 
PPTX
Functions in Python Programming Language
BeulahS2
 
PDF
June 2025 Top 10 Sites -Electrical and Electronics Engineering: An Internatio...
elelijjournal653
 
PPTX
Computer network Computer network Computer network Computer network
Shrikant317689
 
PDF
PROGRAMMING REQUESTS/RESPONSES WITH GREATFREE IN THE CLOUD ENVIRONMENT
samueljackson3773
 
PDF
How to Buy Verified CashApp Accounts IN 2025
Buy Verified CashApp Accounts
 
PPTX
darshai cross section and river section analysis
muk7971
 
PDF
CLIP_Internals_and_Architecture.pdf sdvsdv sdv
JoseLuisCahuanaRamos3
 
PPTX
template.pptxr4t5y67yrttttttttttttttttttttttttttttttttttt
SithamparanaathanPir
 
PDF
A Brief Introduction About Robert Paul Hardee
Robert Paul Hardee
 
DOCX
Engineering Geology Field Report to Malekhu .docx
justprashant567
 
PDF
FSE-Journal-First-Automated code editing with search-generate-modify.pdf
cl144
 
PDF
Clustering Algorithms - Kmeans,Min ALgorithm
Sharmila Chidaravalli
 
PPT
FINAL plumbing code for board exam passer
MattKristopherDiaz
 
PDF
LLC CM NCP1399 SIMPLIS MODEL MANUAL.PDF
ssuser1be9ce
 
PPTX
Alan Turing - life and importance for all of us now
Pedro Concejero
 
PPSX
OOPS Concepts in Python and Exception Handling
Dr. A. B. Shinde
 
FSE_LLM4SE1_A Tool for In-depth Analysis of Code Execution Reasoning of Large...
cl144
 
June 2025 - Top 10 Read Articles in Network Security and Its Applications
IJNSA Journal
 
13th International Conference of Security, Privacy and Trust Management (SPTM...
ijcisjournal
 
Engineering Quiz ShowEngineering Quiz Show
CalvinLabial
 
Functions in Python Programming Language
BeulahS2
 
June 2025 Top 10 Sites -Electrical and Electronics Engineering: An Internatio...
elelijjournal653
 
Computer network Computer network Computer network Computer network
Shrikant317689
 
PROGRAMMING REQUESTS/RESPONSES WITH GREATFREE IN THE CLOUD ENVIRONMENT
samueljackson3773
 
How to Buy Verified CashApp Accounts IN 2025
Buy Verified CashApp Accounts
 
darshai cross section and river section analysis
muk7971
 
CLIP_Internals_and_Architecture.pdf sdvsdv sdv
JoseLuisCahuanaRamos3
 
template.pptxr4t5y67yrttttttttttttttttttttttttttttttttttt
SithamparanaathanPir
 
A Brief Introduction About Robert Paul Hardee
Robert Paul Hardee
 
Engineering Geology Field Report to Malekhu .docx
justprashant567
 
FSE-Journal-First-Automated code editing with search-generate-modify.pdf
cl144
 
Clustering Algorithms - Kmeans,Min ALgorithm
Sharmila Chidaravalli
 
FINAL plumbing code for board exam passer
MattKristopherDiaz
 
LLC CM NCP1399 SIMPLIS MODEL MANUAL.PDF
ssuser1be9ce
 
Alan Turing - life and importance for all of us now
Pedro Concejero
 
OOPS Concepts in Python and Exception Handling
Dr. A. B. Shinde
 
Ad

Pengenalan algoritma dasar dalam pemrograman

  • 2. Hello •Lecturers: •Guntur Budi H (Before Mid) •Mhd Reza Pulungan (After Mid)
  • 6. Before we Start 1 5 6 3 9 2 4
  • 7. What is this course about INTENDED FOR YOU WITH LITTLE OR NO “PROGRAMMING” EXPERIENCE. 01 LEARN “ALGORITHM“ THE ROLE COMPUTATION CAN PLAY IN SOLVING PROBLEMS 02 WRITING CODE USING A “PROGRAMMING LANGUAGE” 03
  • 8. Why C++ ? • You can’t learn to program without a programming language • The purpose of a programming language is to allow you to express your ideas in code • C++ is the language that most directly allows you to express ideas from the largest number of application areas • C++ is the most widely used language in engineering areas (http://www.stroustrup.com/applications.html)
  • 9. Why C++ C++ is precisely and comprehensively defined by an ISO standard C++ is available on almost all kinds of computers Programming concepts that you learn using C++ can be used fairly directly in other languages Including C, Java, C#, and (less directly) Fortran
  • 10. Course Outcome 1. Have knowledge about the importance of algorithms and data structures in solving problems 2. Have knowledge about components in algorithms and can construct algorithms to solve simple problems. 3. Have knowledge about data structures and C++ programming language. 4. Have knowledge about data types for array and records / struct and can implement them in a computer program. 5. Have knowledge about modular programming and can implement it in a computer program. 6. Be able to explain and competent in how to implement sorting and searching algorithms. 7. Have knowledge about pointer data type and can implement it in a computer program. 8. Be able and competent in solving more complex programming problems.
  • 11. Assesment CO1: Problem 1 in mid- term exam (5%) and exercise 1 (5%) - 10% CO2: Problem 2 in mid- term exam (5%) and exercise 2 (5%) - 10% CO3: Problem 3 in mid- term exam (5%); problem 4 in mid-term exam (5%); assignment 1: make an algorithm and computer program (5%); and exercise 3 (5%) - 20% CO4: Problem 5 in mid- term exam (5%); problem 1 in final exam (5%) and exercise 4 (5%) - 15% CO5: Problem 2 in final exam (5%); assignment 2: make a function and recursive (5%); and exercise 5 (5%) - 15% CO6: Problem 3 in final exam (5%) and exercise 6 (5%) - 10% CO7: Problem 4 in final exam (5%) and exercise 7 (5%) - 10% CO8: Problem 5 in final exam (5%) and assignment 3: make a program based on a real-life problem (5%) - 10%
  • 12. Main Reference C++ PROGRAMMING : FROM PROBLEM ANALYSIS TO PROGRAM DESIGN SIXTH EDITION D.S. MALIK
  • 13. Course Topics Introduction Algorithm Data Type & Operator Control Structure – Condition Control Structure – Repetition Array Struct Function Sorting & Searching Pointer
  • 14. Why programming? Our civilization runs on software Most engineering activities involve software Note: most programs do not run on things that look like a PC (a screen, a keyboard, a box under the table) 14
  • 15. Phones • Chat • Social Media • Payment • Security • Call • SMS
  • 16. PC / Tablet / Workstation • Operating System • Computer Program
  • 17. Energy • Control • Monitoring • Analysis • Design • Communications • Visualization • Manufacturing
  • 21. Algorithm • An unambiguous specification of how to solve a class of problems. Algorithms can perform calculation, data processing and automated reasoning tasks. • Algorithms are essential to the way computers process data. • Algorithms can be expressed in many kinds of notation, including natural languages, pseudocode, flowcharts, or programming languages.
  • 22. Algorithm Design 1. Problem definition 2. Development of a model 3. Specification of algorithm 4. Designing an algorithm 5. Checking the correctness of algorithm 6. Analysis of algorithm 7. Implementation of algorithm 8. Program testing 9. Documentation preparation
  • 23. Example #1 Find the largest number in a list of numbers of random order
  • 24. Example #1 – High Level Description 1. If there are no numbers in the set then there is no highest number. 2. Assume the first number in the set is the largest number in the set. 3. For each remaining number in the set: if this number is larger than the current largest number, consider this number to be the largest number in the set. 4. When there are no numbers left in the set to iterate over, consider the current largest number to be the largest number of the set.
  • 25. Example #1 - Pseudocode
  • 26. Example #2 • Compute the greatest common divisor (GCD) to two numbers • Euclid’s Algorithm • Euclid poses the problem thus: "Given two numbers not prime to one another, to find their greatest common measure"
  • 27. Example #2 – Flowchart
  • 28. Example #2 - Code
  • 29. Exercise Design an algorithm that calculates the monthly paycheck of a salesperson at a local department store • Every salesperson has a base salary. • The salesperson also receives a bonus at the end of each month, based on the following criteria: • If the salesperson has been with the store for five years or less, the bonus is $ 10 for each year that he or she has worked there. • If the salesperson has been with the store for more than five years, the bonus is $ 20 for each year that he or she has worked there. • The salesperson can earn an additional bonus as follows: If the total sales made by the salesperson for the month are at least $ 5,000 but less than $ 10,000, he or she receives a 3% commission on the sale. If the total sales made by the salesperson for the month are at least $ 10,000, he or she receives a 6% commission on the sale.
  • 31. Updated by: Malak Abdullah 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. 31
  • 32. 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) 32
  • 33. 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 33
  • 34. Processing a C++ Program (cont'd.) 34
  • 35. 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 35
  • 37. 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 37
  • 38. 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 38
  • 39. 39 So what is programming? • Conventional definitions • Telling a very fast moron exactly what to do • A plan for solving a problem on a computer • Specifying the order of a program execution • But modern programs often involve millions of lines of code • And manipulation of data is central • Definition from another domain (academia) • A … program is an organized and directed accumulation of resources to accomplish specific … objectives … • Good, but no mention of actually doing anything • The definition we’ll use • Specifying the structure and behavior of a program, and testing that the program performs its task correctly and with acceptable performance • Never forget to check that “it” works • Software == one or more programs
  • 40. 40 Programming • Programming is fundamentally simple • Just state what the machine is to do • So why is programming hard? • We want “the machine” to do complex things • And computers are nitpicking, unforgiving, dumb beasts • The world is more complex than we’d like to believe • So we don’t always know the implications of what we want • “Programming is understanding” • When you can program a task, you understand it • When you program, you spend significant time trying to understand the task you want to automate • Programming is part practical, part theory • If you are just practical, you produce non-scalable unmaintainable hacks • If you are just theoretical, you produce toys
  • 41. Reference • Bjarne Stroustrup, 2015, Texas A&M University • D.S. Malik, C++ Programming: From Problem Analysis to Program Design, Fourth Edition