Pengenalan algoritma dasar dalam pemrograman

ssuser58c832 37 views 41 slides Sep 25, 2024
Slide 1
Slide 1 of 41
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41

About This Presentation

Pengenalan algoritma dasar pemrograman.


Slide Content

Programming1
Guntur Budi Herwanto
[email protected]

Hello
•Lecturers:
•Guntur Budi H (Before Mid)
•Mhd Reza Pulungan (After Mid)

Google ClassroomCode
7u00v2

Joinin Netacad
ugm.id/cpaprg19

CourseCompanion: CPA C++

BeforeweStart
1563924

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
WRITINGCODE
USINGA
“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

CourseOutcome
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
IntroductionAlgorithm
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
•SocialMedia
•Payment
•Security
•Call
•SMS

PC / Tablet / Workstation
•OperatingSystem
•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
Findthe 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
•Computethe 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
Designan 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;
intmain()
{
cout << "My first C++ program." << endl;
return0;
}
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 compilerto:
•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 veryfast moron exactlywhat 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
Tags