introduction to c++, chapter 1
TRANSCRIPT
![Page 1: INTRODUCTION TO C++, Chapter 1](https://reader036.vdocuments.us/reader036/viewer/2022062522/5886d4111a28ab776a8b4f23/html5/thumbnails/1.jpg)
PROGRAMMING FOR ENGINEERS
By: MUBAREK KURT
![Page 2: INTRODUCTION TO C++, Chapter 1](https://reader036.vdocuments.us/reader036/viewer/2022062522/5886d4111a28ab776a8b4f23/html5/thumbnails/2.jpg)
INTRODUCTION TO COMPUTER AND PROGRAMMING
Chapter 1:
![Page 3: INTRODUCTION TO C++, Chapter 1](https://reader036.vdocuments.us/reader036/viewer/2022062522/5886d4111a28ab776a8b4f23/html5/thumbnails/3.jpg)
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
![Page 4: INTRODUCTION TO C++, Chapter 1](https://reader036.vdocuments.us/reader036/viewer/2022062522/5886d4111a28ab776a8b4f23/html5/thumbnails/4.jpg)
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
![Page 5: INTRODUCTION TO C++, Chapter 1](https://reader036.vdocuments.us/reader036/viewer/2022062522/5886d4111a28ab776a8b4f23/html5/thumbnails/5.jpg)
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.
![Page 6: INTRODUCTION TO C++, Chapter 1](https://reader036.vdocuments.us/reader036/viewer/2022062522/5886d4111a28ab776a8b4f23/html5/thumbnails/6.jpg)
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.
![Page 7: INTRODUCTION TO C++, Chapter 1](https://reader036.vdocuments.us/reader036/viewer/2022062522/5886d4111a28ab776a8b4f23/html5/thumbnails/7.jpg)
COMPUTER COMPONENTS
• HARDWARE• SOFTWARE
![Page 8: INTRODUCTION TO C++, Chapter 1](https://reader036.vdocuments.us/reader036/viewer/2022062522/5886d4111a28ab776a8b4f23/html5/thumbnails/8.jpg)
COMPUTER LANGUAGES
1. Machine language
2.Assembly language
3. High level language
![Page 9: INTRODUCTION TO C++, Chapter 1](https://reader036.vdocuments.us/reader036/viewer/2022062522/5886d4111a28ab776a8b4f23/html5/thumbnails/9.jpg)
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.
![Page 10: INTRODUCTION TO C++, Chapter 1](https://reader036.vdocuments.us/reader036/viewer/2022062522/5886d4111a28ab776a8b4f23/html5/thumbnails/10.jpg)
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
![Page 11: INTRODUCTION TO C++, Chapter 1](https://reader036.vdocuments.us/reader036/viewer/2022062522/5886d4111a28ab776a8b4f23/html5/thumbnails/11.jpg)
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.
![Page 12: INTRODUCTION TO C++, Chapter 1](https://reader036.vdocuments.us/reader036/viewer/2022062522/5886d4111a28ab776a8b4f23/html5/thumbnails/12.jpg)
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.
![Page 13: INTRODUCTION TO C++, Chapter 1](https://reader036.vdocuments.us/reader036/viewer/2022062522/5886d4111a28ab776a8b4f23/html5/thumbnails/13.jpg)
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.
![Page 14: INTRODUCTION TO C++, Chapter 1](https://reader036.vdocuments.us/reader036/viewer/2022062522/5886d4111a28ab776a8b4f23/html5/thumbnails/14.jpg)
APPLICATION PROCESS IN C++
Source codes
Preprocessor
Modified source-
code
CompilerNo
error
Object codes
Linker
Executable codes
Library
![Page 15: INTRODUCTION TO C++, Chapter 1](https://reader036.vdocuments.us/reader036/viewer/2022062522/5886d4111a28ab776a8b4f23/html5/thumbnails/15.jpg)
DEVELOPING A PROGRAM
Analyzing the problem
Program Design using
Algorithm
Conversion to Program
Flow-chart Pseudo-code
![Page 16: INTRODUCTION TO C++, Chapter 1](https://reader036.vdocuments.us/reader036/viewer/2022062522/5886d4111a28ab776a8b4f23/html5/thumbnails/16.jpg)
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
![Page 17: INTRODUCTION TO C++, Chapter 1](https://reader036.vdocuments.us/reader036/viewer/2022062522/5886d4111a28ab776a8b4f23/html5/thumbnails/17.jpg)
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)
![Page 18: INTRODUCTION TO C++, Chapter 1](https://reader036.vdocuments.us/reader036/viewer/2022062522/5886d4111a28ab776a8b4f23/html5/thumbnails/18.jpg)
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
![Page 19: INTRODUCTION TO C++, Chapter 1](https://reader036.vdocuments.us/reader036/viewer/2022062522/5886d4111a28ab776a8b4f23/html5/thumbnails/19.jpg)
ALGORITHM• 3 forms of algorithm:
1. Sequential2. Control: decision
making3. Control : repeated
solution
![Page 20: INTRODUCTION TO C++, Chapter 1](https://reader036.vdocuments.us/reader036/viewer/2022062522/5886d4111a28ab776a8b4f23/html5/thumbnails/20.jpg)
ALGORITHM1. Sequential
algorithmStart
Step 1:
Step nEnd
2. Controlled algorithm: making decision
if conditionthen
true partelse
false partendif
![Page 21: INTRODUCTION TO C++, Chapter 1](https://reader036.vdocuments.us/reader036/viewer/2022062522/5886d4111a28ab776a8b4f23/html5/thumbnails/21.jpg)
ALGORITHM
•3. Controlled algotithm: Repeated solution
• While condition do• Repeated part
• or• Repeat n times
• Repeated part
![Page 22: INTRODUCTION TO C++, Chapter 1](https://reader036.vdocuments.us/reader036/viewer/2022062522/5886d4111a28ab776a8b4f23/html5/thumbnails/22.jpg)
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
![Page 23: INTRODUCTION TO C++, Chapter 1](https://reader036.vdocuments.us/reader036/viewer/2022062522/5886d4111a28ab776a8b4f23/html5/thumbnails/23.jpg)
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.
![Page 24: INTRODUCTION TO C++, Chapter 1](https://reader036.vdocuments.us/reader036/viewer/2022062522/5886d4111a28ab776a8b4f23/html5/thumbnails/24.jpg)
ALGORITHM-PSEUDOCODES
• Pseudocode in mixed language1. Start2. cin the radius3. Circumference=2xxradius4. cout the circumference5. End
![Page 25: INTRODUCTION TO C++, Chapter 1](https://reader036.vdocuments.us/reader036/viewer/2022062522/5886d4111a28ab776a8b4f23/html5/thumbnails/25.jpg)
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
![Page 26: INTRODUCTION TO C++, Chapter 1](https://reader036.vdocuments.us/reader036/viewer/2022062522/5886d4111a28ab776a8b4f23/html5/thumbnails/26.jpg)
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
![Page 27: INTRODUCTION TO C++, Chapter 1](https://reader036.vdocuments.us/reader036/viewer/2022062522/5886d4111a28ab776a8b4f23/html5/thumbnails/27.jpg)
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
![Page 28: INTRODUCTION TO C++, Chapter 1](https://reader036.vdocuments.us/reader036/viewer/2022062522/5886d4111a28ab776a8b4f23/html5/thumbnails/28.jpg)
FLOW-CHART
– Document printing
– Decision making
– Loop (FOR)
– To continue on the same page
– To continue on different page
– Subrutine/ function
![Page 29: INTRODUCTION TO C++, Chapter 1](https://reader036.vdocuments.us/reader036/viewer/2022062522/5886d4111a28ab776a8b4f23/html5/thumbnails/29.jpg)
FLOW-CHARTSequential flow-chart Start
Read radius
Calculate Circumference=2xpaixradius
Write circumference
End
![Page 30: INTRODUCTION TO C++, Chapter 1](https://reader036.vdocuments.us/reader036/viewer/2022062522/5886d4111a28ab776a8b4f23/html5/thumbnails/30.jpg)
FLOW-CHART
Decision making flow- chart
CalculateCircumference=2xpaixradius
false
Start
Read radius
End
true Radius<0
Write circumference
![Page 31: INTRODUCTION TO C++, Chapter 1](https://reader036.vdocuments.us/reader036/viewer/2022062522/5886d4111a28ab776a8b4f23/html5/thumbnails/31.jpg)
Flow-chart for repeated solution
Start
Calculate Circumference=2xpaixradius
Write circumference
Continue?
noEND
yes
Read radius
Read intention to repeat
![Page 32: INTRODUCTION TO C++, Chapter 1](https://reader036.vdocuments.us/reader036/viewer/2022062522/5886d4111a28ab776a8b4f23/html5/thumbnails/32.jpg)
QUIZ
The second step before developing a program is
.
![Page 33: INTRODUCTION TO C++, Chapter 1](https://reader036.vdocuments.us/reader036/viewer/2022062522/5886d4111a28ab776a8b4f23/html5/thumbnails/33.jpg)
ASSIGNMENT 1
What is a flow-chart?