INTRODUCTION TO C++, Chapter 1
-
Upload
mubarek-kurt -
Category
Engineering
-
view
121 -
download
2
Transcript of INTRODUCTION TO C++, Chapter 1
PROGRAMMING FOR ENGINEERS
By: MUBAREK KURT
INTRODUCTION TO COMPUTER AND PROGRAMMING
Chapter 1:
WHAT IS PROGRAMMING?
• A set of instruction given to computer forexecuting certain tasks
• Using computer language such as C++, Fortran,Cobol etc
• Language comes with rules• A commercial program is called
a software
BASIC STRUCTURE OF A PROGRAM
• 3 main stages: input of data, Processing of dataand producing results.
Data input
Dataprocessing
Producing result
Arithmatic Solution
Logical Operation
WHY PROGRAMMING IS IMPORTANT?
• We give difficult or easy tasks to computer to beexecuted.
• Problem solving in shorter time.• Software may not be available.• It’s money saving if you developed your
ownsoftware.
• To increase your copetency as an engineer.
WHY C++?
• Old language such as C do have its specialty but alsocontain weaknesses.
• Its specialty is as the pioneer language, many softwares are written using this language.
• Its weakness is it uses structural programming.
• C++ is an object oriented programming (OOP).
• Thus C++ has been the main computer language in the world.
COMPUTER COMPONENTS
• HARDWARE• SOFTWARE
COMPUTER LANGUAGES
1. Machine language
2.Assembly language
3. High level language
MACHINE LANGUAGE• Machine language is a combination
of binarydigit 1 and 0.
• Every number, letter and symbols can be translated to binary code.
• In computer programming, number, letterand symbols is called character.
• Main standard of conversion is the American Standard Code for Information Interchange (ASCII).
• In ASCII, there are 128 character, numbeed between 0 to 127 and this number is converted to binary number.
MACHINE LANGUAGEPositions Character Binary number in
ASCIIBinary number in Machine language
0 Null 0000000 00000000
1 SOTT 0000001 00000001
65 A 1000001 01000001
136 { 1111011 01111011
127 DEL 1111111 01111111
ASSEMBLY LANGUAGE
• Assembly language is also called low level language
• Contain pneumonic codes that have special meaning . For example, addition of 2 numbers to become the third number isADD N1, N2, N3
• The meaning of codes is machine dependent.
HIGHER LEVEL LANGUAGE
• Machine language that hss been standardly coded
• The language is like spoken language such as in english, japan and france.
• There are more than 100 higher level language. Eg:1.FORTRAN - FORmula TRANslation2. C3. C++ - Object oriented programming4.BASIC - Beginning All-purpose Symbolic
Instruction Code5. COBOL - Common Business Oriented
Language6.Java- Internet based language
developed by SunMicrosystem7. C#. Similar to Java, developed by
Microsoft Inc.
HIGHER LEVEL LANGUAGE
• Command to computer is easily given.
• For example, in C++, to add 2 numbers and keeping the answer,hasilTambah = no1 + no2;
• However computer will not understand this language. It needs a compiler to translate the language to machine language.
APPLICATION PROCESS IN C++
Source codes
Preprocessor
Modified source-
code
CompilerNo
error
Object codes
Linker
Executable codes
Library
DEVELOPING A PROGRAM
Analyzing the problem
Program Design using
Algorithm
Conversion to Program
Flow-chart Pseudo-code
ANALYZING THE PROBLEM
• At this stage, think about the required:1. Input2. Output3. Process
• Example: To develop a program to calculate a circumference of a circle, give the radius
• Problem analyzing stage:1. Input: Media – Keyboard
Data – a radius2. Output: Media – Screen
Data – Circumference3. Process: Circ = 2 x PAI x Radius
ALGORITHM• Algorithm is a step by step
procedure ofsolving a problem.– In the design stage.– No algorithm No program
Nosolution.
– Independent of computer language (use your own language)
ALGORITHM• What is needed in an
algorithm– input– output– Correct sequence: first
comes first– Simple/easy/non-confusing– In general form-understood
by any readers– Accurate in solving problem– Finite – has an end– Efficient
• Types: Pseudocodes, flow-chart etc
ALGORITHM• 3 forms of algorithm:
1. Sequential2. Control: decision
making3. Control : repeated
solution
ALGORITHM1. Sequential
algorithmStart
Step 1:
Step nEnd
2. Controlled algorithm: making decision
if conditionthen
true partelse
false partendif
ALGORITHM
•3. Controlled algotithm: Repeated solution
• While condition do• Repeated part
• or• Repeat n times
• Repeated part
ALGORITHM-PSEUDOCODES
• Sequential steps written in own language
• Each line is numbered.• Each line represent 1 step,
to beexecuted only one time.
• It can be:– In own language form
totally– In a mixed of own language
and programming language
ALGORITHM-PSEUDOCODES
• Example: Sequential algorithm• Pseudocode in own language
1. Start2. Read (input) the radius3. Circumference=2xxradius4. Write the circumference5. End
• Notice: The pseudocodes is numberedand in sequence.
ALGORITHM-PSEUDOCODES
• Pseudocode in mixed language1. Start2. cin the radius3. Circumference=2xxradius4. cout the circumference5. End
DECISION MAKINGALGORITHM
• Pseudocodes : making decision1. Start2. Read (input) the radius3. if radius < 0 then
3a. Write circumference cannot be calculated 3b. Stop
4. Else4a. Circumference=2xPAIxradius 4b. Write circumference
5. Endif6. End
DECISION MAKINGALGORITHM
• Pseudocodes : repeated solution-torepeat radius input
1. Start2. Read (input) the radius3. Circumference=2xPAIxradius4. Read yes or no to repeat5. While yes to repeat
do 5a. Go to 25. End
FLOW-CHART• Flow-chart contains boxes/symbols
that represent required operations and arrows to show the sequence.
• Symbols:– terminal (start, end)– process (assign value,
arithmatic operation, etc)– Input/ output
FLOW-CHART
– Document printing
– Decision making
– Loop (FOR)
– To continue on the same page
– To continue on different page
– Subrutine/ function
FLOW-CHARTSequential flow-chart Start
Read radius
Calculate Circumference=2xpaixradius
Write circumference
End
FLOW-CHART
Decision making flow- chart
CalculateCircumference=2xpaixradius
false
Start
Read radius
End
true Radius<0
Write circumference
Flow-chart for repeated solution
Start
Calculate Circumference=2xpaixradius
Write circumference
Continue?
noEND
yes
Read radius
Read intention to repeat
QUIZ
The second step before developing a program is
.
ASSIGNMENT 1
What is a flow-chart?