SlideShare a Scribd company logo
1 of 43
Download to read offline
Lecture 1
Overview of Programming and
Problem Solving
Structured Programming
1
Amr El Maghraby , Ph.D.
Computer and Systems Engineering
Topics
• Computer Programming
• Programming Life-Cycle Phases
• Creating an Algorithm
• Machine Language vs. High Level Languages
• Compilation and Execution Processes
• Computing-Profession Ethics
• Example
2
Computer components
• Input devices
Keyboard, mouse, scanner
• Central processing Unit (CPU)
• Arithmetic-logic unit (ALU)
• Control unit (CU)
• Memory:
• Random access memory (RAM)
• Read only memory(ROM)
• Output devices
Monitor,speakers, printer
• Secondary storage
Floppy Disk, Tape, CD-ROM, DVD, Hard disk
3
Storage Capacities
• Byte B 8 bits
• KiloByte KB 210 Bytes
• MegaByte MB 220 Bytes
• GigaByteGB 230 Bytes
• TeraByteTB 240 Bytes
4
What is Computer Programming?
• It is the process of planning a sequence
of steps (called instructions) for a
computer to follow.
5
STEP 1
STEP 2
STEP 3
. . .
Programming Life Cycle Phases
1 Problem-Solving
2 Implementation
3 Maintenance
6
1.Problem-Solving Phase
• ANALYZE the problem and SPECIFY
what the solution must do
• develop a GENERAL SOLUTION
(ALGORITHM) to solve the problem
• VERIFY that your solution really
solves the problem
7
Sample Problem
A programmer needs an algorithm to
determine an employee’s weekly
wages. How would the calculations
be done by hand?
8
One Employee’s Wages
In one week an employee works 52 hours at
the hourly pay rate of 24.75. Assume a 40.0
hour normal work week and an overtime pay
rate factor of 1.5
What are the employee’s wages?
9
40 x 24.75 = 990.00
12 x 1.5 x 24.75 = 445.50___________
1435.50
Weekly Wages, in General
If hours are more than 40.0, then
wages = (40.0 * payRate) + (hours - 40.0) * 1.5 *payRate
otherwise,
wages = hours * payRate
10
RECALL EXAMPLE
( 40 x 24.75 ) + ( 12 x 1.5 x 24.75 ) = 1435.50
An Algorithm is . . .
• a step-by-step procedure for solving
a problem in a finite amount of time.
11
Structured programming is a programming paradigm aimed at
improving the clarity, quality, and development time of a computer
program by making extensive use of subroutines, block
structures, for and while loops—in contrast to using simple tests
and jumps such as the goto statement which could lead to
"spaghetti code"
Structured programming
Spaghetti code
• describe source code that is
hard to follow and has a
complex and tangled control
structure, especially one using
many GOTO statements. which
is difficult both to follow and
to maintain.
In 1979, Bjarne Stroustrup, a Danish computer scientist, began
work on the predecessor to C++, "C with Classes". The
motivation for creating a new language originated from
Stroustrup's experience in programming for his Ph.D. thesis
C++ is a language that has evolved much over the years, and
these course explain many features added recently to the
language. Therefore, in order to properly follow the course, a
recent compiler is needed. It shall support (even if only
partially) the features introduced by the 2011 standard.
What is a compiler?
Computers understand only one language and that language
consists of sets of instructions made of ones and zeros. This
computer language is appropriately called machine language.
A single instruction to a computer could look like this:
00000 10011110
A particular computer's machine language program that
allows a user to input two numbers, adds the two numbers
together, and displays the total could include these machine
code instructions:
This is a portion of code written in C++ that
accomplishes the exact same purpose:
int a, b, sum;
cin >> a;
cin >> b;
sum = a + b;
cout << sum << endl;
Because a computer can only understand machine language and
humans wish to write in high level languages high level languages
have to be re-written (translated) into machine language at some
point. This is done by special programs called compilers,
interpreters, or assemblers that are built into the various
programming applications.
The easiest way to compile C++ programs is by using an
Integrated Development Environment (IDE). An IDE generally
integrates several development tools, including a text editor and
tools to compile programs directly from it.
20
Flow chart symbols
Flow chart symbols
22
Data object – The Data object, often referred to as the I/O Shape
shows the Inputs to and Outputs from a process.
Rectangle – This is used to represent an event which is controlled
within the process. Typically this will be a step or action which is
taken.
Diamond – Used to represent a decision point in the process.
Typically, the statement in the symbol will require a `yes’ or `no’
response and branch to different parts of the flowchart accordingly.
23
Document – The Document object is a rectangle with a wave-like base.
This shape is used to represent a Document or Report in a process flow.
Rounded box – This is used to represent an event which occurs
automatically. Such an event will trigger a subsequent action, for
example `receive telephone call, or describe a new state of affairs.
Stored data – This is a general data storage object used in the process
flow as opposed to data which could be also stored on a hard drive,
magnetic tape, memory card, of any other storage device
24
Manual input – This object is represented by rectangle with the top
sloping up from left to right. The Manual Input object signifies an
action where the user is prompted for information that must be
manually input into a system.
Direct data – Direct data object in a process flow represents
information stored which can be accessed directly. This object
represents a computer’s hard drive.
25
Circle – Used to represent a point at which the flowchart connects with
another process. The name or reference for the other process should
appear within the symbol
Internal storage – This is an object which is commonly found in
programming flowcharts to illustrate the information stored in
memory, as opposed to on a file.
Predefined process – This allows you to write one subroutine and
call it as often as you like from anywhere in the code
26
27
Some guidelines in flowcharting:
• All necessary requirements should be listed out in logical order.
• The flowchart should be clear and easy to follow.
• The usual direction of the flow of a procedure or system is from
left to right or top to bottom.
• only one flow line is utilized together with a terminal symbol.
• Write within standard symbols briefly
• It is imperative that your flowchart has a logical start and finish.
28
What is a
Programming Language?
• It is a language with strict grammar
rules, symbols, and special words
used to construct a computer
program.
29
2. Implementation Phase:
Program
• Translating your algorithm into a
programming language is called
CODING
30
Implementation Phase: Test
• TESTING your program means running
(executing) your program on the
computer, to see if it produces correct
results
• if it does not, then you must find out
what is wrong with your program or
algorithm and fix it--this is called
debugging
31
3. Maintenance Phase
• USE and MODIFY the program to meet
changing requirements or correct
errors that show up in using it
• maintenance begins when your
program is put into use and accounts
for the majority of effort on most
programs
32
Programming Life Cycle
1 Problem-Solving Phase
Analysis and Specification
General Solution ( Algorithm )
Verify
2 Implementation Phase
Concrete Solution ( Program )
Test
3 Maintenance Phase
Use
Maintain 33
A Tempting Shortcut?
34
GOAL
THINKING
CODE
REVISE
REVISE
REVISE
DEBUG
DEBUG
DEBUG
TEST
CODE
Basic Control Structures
• a sequence is a series of statements that execute
one after another
• selection (branch) is used to execute different
statements depending on certain conditions
• Looping (repetition) is used to repeat statements
while certain conditions are met.
• a subprogram is used to break the program into
smaller units
35
SEQUENCE
36
Statement Statement Statement . . .
SELECTION (branch)
37
IF Condition THEN Statement1 ELSE Statement2
Statement1
Statement
Statement2
Condition . . .
LOOP (repetition)
38
Statement
Condition
. . .
False
WHILE Condition Statement1
SUBPROGRAM (function)
39
PROGRAM1 . . .
SUBPROGRAM1
a meaningful collection
of SEQUENCE,
SELECTION, LOOP,
SUBPROGRAM
Company Payroll Case Study
A small company needs an interactive
program to figure its weekly payroll. The
payroll clerk will input data for each
employee, and each employee’s wages.
Display the total wages for the week on
the screen.
40
One Employee’s Wages
In one week employee ID # 4587 works 52 hours at the
hourly pay rate of 24.75. Assume a 40.0 hour normal
work week and an overtime pay rate factor of 1.5.
What are the employee’s wages?
41
40 x 24.75 = 990.00
12 x 1.5 x 24.75 = 445.50___________
1435.50
Week’s Wages, in General
If hours are more than 40.0, then
wages = (40.0 * payRate) + (hours - 40.0) * 1.5 *payRate
otherwise,
wages = hours * payRate
42
RECALL EXAMPLE
( 40 x 24.75 ) + ( 12 x 1.5 x 24.75 ) = 1435.50
Algorithm for Company Payroll
Program
• initialize total company payroll to 0.0
• repeat this process for each employee:
1. Get the employee’s ID empNum
2. Get the employee’s hourly payRate
3. Get the hours worked this week
4. Calculate this week’s wages
5. Add wages to total company payroll
• write total company payroll on screen
43

More Related Content

What's hot

Program Logic Formulation - Ohio State University
Program Logic Formulation - Ohio State UniversityProgram Logic Formulation - Ohio State University
Program Logic Formulation - Ohio State UniversityReggie Niccolo Santos
 
Introduction to Programming
Introduction to ProgrammingIntroduction to Programming
Introduction to ProgrammingChaffey College
 
Algorithm and c language
Algorithm and c languageAlgorithm and c language
Algorithm and c languagekamalbeydoun
 
Cs1123 2 comp_prog
Cs1123 2 comp_progCs1123 2 comp_prog
Cs1123 2 comp_progTAlha MAlik
 
Unit 1-problem solving with algorithm
Unit 1-problem solving with algorithmUnit 1-problem solving with algorithm
Unit 1-problem solving with algorithmrajkumar1631010038
 
STRUCTURED PROGRAMMING Chap2
STRUCTURED PROGRAMMING Chap2STRUCTURED PROGRAMMING Chap2
STRUCTURED PROGRAMMING Chap2Bro Shola Ajayi
 
Problem solving using Computer
Problem solving using ComputerProblem solving using Computer
Problem solving using ComputerDavid Livingston J
 
Lecture 15 run timeenvironment_2
Lecture 15 run timeenvironment_2Lecture 15 run timeenvironment_2
Lecture 15 run timeenvironment_2Iffat Anjum
 
CIS110 Computer Programming Design Chapter (5)
CIS110 Computer Programming Design Chapter  (5)CIS110 Computer Programming Design Chapter  (5)
CIS110 Computer Programming Design Chapter (5)Dr. Ahmed Al Zaidy
 
Part II: Assembly Fundamentals
Part II: Assembly FundamentalsPart II: Assembly Fundamentals
Part II: Assembly FundamentalsAhmed M. Abed
 
A Crash Course in C Part-1
A Crash Course in C Part-1A Crash Course in C Part-1
A Crash Course in C Part-1MD SAMIR UDDIN
 
Programming process and flowchart
Programming process and flowchartProgramming process and flowchart
Programming process and flowcharthermiraguilar
 
Unit 1 python (2021 r)
Unit 1 python (2021 r)Unit 1 python (2021 r)
Unit 1 python (2021 r)praveena p
 
Peephole optimization techniques in compiler design
Peephole optimization techniques in compiler designPeephole optimization techniques in compiler design
Peephole optimization techniques in compiler designAnul Chaudhary
 
Logic Formulation 1
Logic Formulation 1Logic Formulation 1
Logic Formulation 1deathful
 

What's hot (20)

Code Optimization
Code OptimizationCode Optimization
Code Optimization
 
Unit i
Unit iUnit i
Unit i
 
Program Logic Formulation - Ohio State University
Program Logic Formulation - Ohio State UniversityProgram Logic Formulation - Ohio State University
Program Logic Formulation - Ohio State University
 
Plc part 3
Plc  part 3Plc  part 3
Plc part 3
 
Introduction to Programming
Introduction to ProgrammingIntroduction to Programming
Introduction to Programming
 
Algorithm and c language
Algorithm and c languageAlgorithm and c language
Algorithm and c language
 
Cs1123 2 comp_prog
Cs1123 2 comp_progCs1123 2 comp_prog
Cs1123 2 comp_prog
 
Unit 1-problem solving with algorithm
Unit 1-problem solving with algorithmUnit 1-problem solving with algorithm
Unit 1-problem solving with algorithm
 
STRUCTURED PROGRAMMING Chap2
STRUCTURED PROGRAMMING Chap2STRUCTURED PROGRAMMING Chap2
STRUCTURED PROGRAMMING Chap2
 
Problem solving using Computer
Problem solving using ComputerProblem solving using Computer
Problem solving using Computer
 
Lecture 15 run timeenvironment_2
Lecture 15 run timeenvironment_2Lecture 15 run timeenvironment_2
Lecture 15 run timeenvironment_2
 
CIS110 Computer Programming Design Chapter (5)
CIS110 Computer Programming Design Chapter  (5)CIS110 Computer Programming Design Chapter  (5)
CIS110 Computer Programming Design Chapter (5)
 
Lesson 3.1 variables and constant
Lesson 3.1 variables and constantLesson 3.1 variables and constant
Lesson 3.1 variables and constant
 
Part II: Assembly Fundamentals
Part II: Assembly FundamentalsPart II: Assembly Fundamentals
Part II: Assembly Fundamentals
 
A Crash Course in C Part-1
A Crash Course in C Part-1A Crash Course in C Part-1
A Crash Course in C Part-1
 
Programming process and flowchart
Programming process and flowchartProgramming process and flowchart
Programming process and flowchart
 
Unit 1 python (2021 r)
Unit 1 python (2021 r)Unit 1 python (2021 r)
Unit 1 python (2021 r)
 
Peephole optimization techniques in compiler design
Peephole optimization techniques in compiler designPeephole optimization techniques in compiler design
Peephole optimization techniques in compiler design
 
Algorithms
AlgorithmsAlgorithms
Algorithms
 
Logic Formulation 1
Logic Formulation 1Logic Formulation 1
Logic Formulation 1
 

Viewers also liked

Lecture 2 c programming by umair ansari
Lecture 2 c programming by umair ansari Lecture 2 c programming by umair ansari
Lecture 2 c programming by umair ansari umair ansari
 
Computer programs, flow chart & algorithm
Computer programs, flow chart & algorithmComputer programs, flow chart & algorithm
Computer programs, flow chart & algorithmsamina khan
 
Introduction to computer programming
Introduction to computer programmingIntroduction to computer programming
Introduction to computer programmingSangheethaa Sukumaran
 
Pengenalan kepada pengaturcaraan berstruktur
Pengenalan kepada pengaturcaraan berstrukturPengenalan kepada pengaturcaraan berstruktur
Pengenalan kepada pengaturcaraan berstrukturUnit Kediaman Luar Kampus
 
Steps for Developing a 'C' program
 Steps for Developing a 'C' program Steps for Developing a 'C' program
Steps for Developing a 'C' programSahithi Naraparaju
 
Barrierstocommunication 140505113319-phpapp01
Barrierstocommunication 140505113319-phpapp01Barrierstocommunication 140505113319-phpapp01
Barrierstocommunication 140505113319-phpapp01Majid Ali
 
Prospek ukm dalam perdagangan bebas
Prospek ukm dalam perdagangan bebasProspek ukm dalam perdagangan bebas
Prospek ukm dalam perdagangan bebasachmadseno15
 

Viewers also liked (13)

Lecture 2 c programming by umair ansari
Lecture 2 c programming by umair ansari Lecture 2 c programming by umair ansari
Lecture 2 c programming by umair ansari
 
Computer programs, flow chart & algorithm
Computer programs, flow chart & algorithmComputer programs, flow chart & algorithm
Computer programs, flow chart & algorithm
 
Introduction to computer programming
Introduction to computer programmingIntroduction to computer programming
Introduction to computer programming
 
Pengenalan kepada pengaturcaraan berstruktur
Pengenalan kepada pengaturcaraan berstrukturPengenalan kepada pengaturcaraan berstruktur
Pengenalan kepada pengaturcaraan berstruktur
 
Steps for Developing a 'C' program
 Steps for Developing a 'C' program Steps for Developing a 'C' program
Steps for Developing a 'C' program
 
Programing Fundamental
Programing FundamentalPrograming Fundamental
Programing Fundamental
 
Stephen cv hk(1)
Stephen cv hk(1)Stephen cv hk(1)
Stephen cv hk(1)
 
Evaluation Q1
Evaluation Q1Evaluation Q1
Evaluation Q1
 
Environmental test chamber
Environmental test chamberEnvironmental test chamber
Environmental test chamber
 
Cathleen_Thigpen_Resume
Cathleen_Thigpen_ResumeCathleen_Thigpen_Resume
Cathleen_Thigpen_Resume
 
Barrierstocommunication 140505113319-phpapp01
Barrierstocommunication 140505113319-phpapp01Barrierstocommunication 140505113319-phpapp01
Barrierstocommunication 140505113319-phpapp01
 
Prospek ukm dalam perdagangan bebas
Prospek ukm dalam perdagangan bebasProspek ukm dalam perdagangan bebas
Prospek ukm dalam perdagangan bebas
 
Volta05_0 (3)
Volta05_0 (3)Volta05_0 (3)
Volta05_0 (3)
 

Similar to L1

L1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdfL1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdfMMRF2
 
Problem-solving and design 1.pptx
Problem-solving and design 1.pptxProblem-solving and design 1.pptx
Problem-solving and design 1.pptxTadiwaMawere
 
C programming for Computing Techniques
C programming for Computing TechniquesC programming for Computing Techniques
C programming for Computing TechniquesAppili Vamsi Krishna
 
Fundamentals of programming with C++
Fundamentals of programming with C++Fundamentals of programming with C++
Fundamentals of programming with C++Seble Nigussie
 
PCCF UNIT 1.pptx
PCCF UNIT 1.pptxPCCF UNIT 1.pptx
PCCF UNIT 1.pptxDivyaKS12
 
Programming_Lecture_1.pptx
Programming_Lecture_1.pptxProgramming_Lecture_1.pptx
Programming_Lecture_1.pptxshoaibkhan716300
 
1 Introduction to C Programming.pptx
1 Introduction to C Programming.pptx1 Introduction to C Programming.pptx
1 Introduction to C Programming.pptxaarockiaabinsAPIICSE
 
Pseudo code.pptx
Pseudo code.pptxPseudo code.pptx
Pseudo code.pptxChaya64047
 
GE3151 PSPP _Unit 1 notes and Question bank.pdf
GE3151 PSPP _Unit 1 notes and Question bank.pdfGE3151 PSPP _Unit 1 notes and Question bank.pdf
GE3151 PSPP _Unit 1 notes and Question bank.pdfAsst.prof M.Gokilavani
 
What is algorithm
What is algorithmWhat is algorithm
What is algorithmmshoaib15
 
Jeremiah Yancy | Skills and techniques of the Systems Analyst
Jeremiah Yancy | Skills and techniques of the Systems AnalystJeremiah Yancy | Skills and techniques of the Systems Analyst
Jeremiah Yancy | Skills and techniques of the Systems AnalystJeremiah Yancy
 
COM1407: Structured Program Development
COM1407: Structured Program Development COM1407: Structured Program Development
COM1407: Structured Program Development Hemantha Kulathilake
 

Similar to L1 (20)

Chapter 01.PPT
Chapter 01.PPTChapter 01.PPT
Chapter 01.PPT
 
L1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdfL1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdf
 
Problem-solving and design 1.pptx
Problem-solving and design 1.pptxProblem-solving and design 1.pptx
Problem-solving and design 1.pptx
 
C programming for Computing Techniques
C programming for Computing TechniquesC programming for Computing Techniques
C programming for Computing Techniques
 
Algorithm.pdf
Algorithm.pdfAlgorithm.pdf
Algorithm.pdf
 
Fundamentals of programming with C++
Fundamentals of programming with C++Fundamentals of programming with C++
Fundamentals of programming with C++
 
c programming 1-1.pptx
c programming 1-1.pptxc programming 1-1.pptx
c programming 1-1.pptx
 
PCCF UNIT 1.pptx
PCCF UNIT 1.pptxPCCF UNIT 1.pptx
PCCF UNIT 1.pptx
 
CHAPTER 1
CHAPTER 1CHAPTER 1
CHAPTER 1
 
01CHAP_1.PPT
01CHAP_1.PPT01CHAP_1.PPT
01CHAP_1.PPT
 
Programming_Lecture_1.pptx
Programming_Lecture_1.pptxProgramming_Lecture_1.pptx
Programming_Lecture_1.pptx
 
Comp102 lec 1
Comp102   lec 1Comp102   lec 1
Comp102 lec 1
 
1 Introduction to C Programming.pptx
1 Introduction to C Programming.pptx1 Introduction to C Programming.pptx
1 Introduction to C Programming.pptx
 
Lecture1
Lecture1Lecture1
Lecture1
 
Pseudo code.pptx
Pseudo code.pptxPseudo code.pptx
Pseudo code.pptx
 
GE3151 PSPP _Unit 1 notes and Question bank.pdf
GE3151 PSPP _Unit 1 notes and Question bank.pdfGE3151 PSPP _Unit 1 notes and Question bank.pdf
GE3151 PSPP _Unit 1 notes and Question bank.pdf
 
pccf unit 1 _VP.pptx
pccf unit 1 _VP.pptxpccf unit 1 _VP.pptx
pccf unit 1 _VP.pptx
 
What is algorithm
What is algorithmWhat is algorithm
What is algorithm
 
Jeremiah Yancy | Skills and techniques of the Systems Analyst
Jeremiah Yancy | Skills and techniques of the Systems AnalystJeremiah Yancy | Skills and techniques of the Systems Analyst
Jeremiah Yancy | Skills and techniques of the Systems Analyst
 
COM1407: Structured Program Development
COM1407: Structured Program Development COM1407: Structured Program Development
COM1407: Structured Program Development
 

L1

  • 1. Lecture 1 Overview of Programming and Problem Solving Structured Programming 1 Amr El Maghraby , Ph.D. Computer and Systems Engineering
  • 2. Topics • Computer Programming • Programming Life-Cycle Phases • Creating an Algorithm • Machine Language vs. High Level Languages • Compilation and Execution Processes • Computing-Profession Ethics • Example 2
  • 3. Computer components • Input devices Keyboard, mouse, scanner • Central processing Unit (CPU) • Arithmetic-logic unit (ALU) • Control unit (CU) • Memory: • Random access memory (RAM) • Read only memory(ROM) • Output devices Monitor,speakers, printer • Secondary storage Floppy Disk, Tape, CD-ROM, DVD, Hard disk 3
  • 4. Storage Capacities • Byte B 8 bits • KiloByte KB 210 Bytes • MegaByte MB 220 Bytes • GigaByteGB 230 Bytes • TeraByteTB 240 Bytes 4
  • 5. What is Computer Programming? • It is the process of planning a sequence of steps (called instructions) for a computer to follow. 5 STEP 1 STEP 2 STEP 3 . . .
  • 6. Programming Life Cycle Phases 1 Problem-Solving 2 Implementation 3 Maintenance 6
  • 7. 1.Problem-Solving Phase • ANALYZE the problem and SPECIFY what the solution must do • develop a GENERAL SOLUTION (ALGORITHM) to solve the problem • VERIFY that your solution really solves the problem 7
  • 8. Sample Problem A programmer needs an algorithm to determine an employee’s weekly wages. How would the calculations be done by hand? 8
  • 9. One Employee’s Wages In one week an employee works 52 hours at the hourly pay rate of 24.75. Assume a 40.0 hour normal work week and an overtime pay rate factor of 1.5 What are the employee’s wages? 9 40 x 24.75 = 990.00 12 x 1.5 x 24.75 = 445.50___________ 1435.50
  • 10. Weekly Wages, in General If hours are more than 40.0, then wages = (40.0 * payRate) + (hours - 40.0) * 1.5 *payRate otherwise, wages = hours * payRate 10 RECALL EXAMPLE ( 40 x 24.75 ) + ( 12 x 1.5 x 24.75 ) = 1435.50
  • 11. An Algorithm is . . . • a step-by-step procedure for solving a problem in a finite amount of time. 11
  • 12. Structured programming is a programming paradigm aimed at improving the clarity, quality, and development time of a computer program by making extensive use of subroutines, block structures, for and while loops—in contrast to using simple tests and jumps such as the goto statement which could lead to "spaghetti code" Structured programming
  • 13. Spaghetti code • describe source code that is hard to follow and has a complex and tangled control structure, especially one using many GOTO statements. which is difficult both to follow and to maintain.
  • 14.
  • 15. In 1979, Bjarne Stroustrup, a Danish computer scientist, began work on the predecessor to C++, "C with Classes". The motivation for creating a new language originated from Stroustrup's experience in programming for his Ph.D. thesis
  • 16. C++ is a language that has evolved much over the years, and these course explain many features added recently to the language. Therefore, in order to properly follow the course, a recent compiler is needed. It shall support (even if only partially) the features introduced by the 2011 standard.
  • 17. What is a compiler? Computers understand only one language and that language consists of sets of instructions made of ones and zeros. This computer language is appropriately called machine language. A single instruction to a computer could look like this: 00000 10011110 A particular computer's machine language program that allows a user to input two numbers, adds the two numbers together, and displays the total could include these machine code instructions:
  • 18. This is a portion of code written in C++ that accomplishes the exact same purpose: int a, b, sum; cin >> a; cin >> b; sum = a + b; cout << sum << endl; Because a computer can only understand machine language and humans wish to write in high level languages high level languages have to be re-written (translated) into machine language at some point. This is done by special programs called compilers, interpreters, or assemblers that are built into the various programming applications.
  • 19. The easiest way to compile C++ programs is by using an Integrated Development Environment (IDE). An IDE generally integrates several development tools, including a text editor and tools to compile programs directly from it.
  • 22. 22 Data object – The Data object, often referred to as the I/O Shape shows the Inputs to and Outputs from a process. Rectangle – This is used to represent an event which is controlled within the process. Typically this will be a step or action which is taken. Diamond – Used to represent a decision point in the process. Typically, the statement in the symbol will require a `yes’ or `no’ response and branch to different parts of the flowchart accordingly.
  • 23. 23 Document – The Document object is a rectangle with a wave-like base. This shape is used to represent a Document or Report in a process flow. Rounded box – This is used to represent an event which occurs automatically. Such an event will trigger a subsequent action, for example `receive telephone call, or describe a new state of affairs. Stored data – This is a general data storage object used in the process flow as opposed to data which could be also stored on a hard drive, magnetic tape, memory card, of any other storage device
  • 24. 24 Manual input – This object is represented by rectangle with the top sloping up from left to right. The Manual Input object signifies an action where the user is prompted for information that must be manually input into a system. Direct data – Direct data object in a process flow represents information stored which can be accessed directly. This object represents a computer’s hard drive.
  • 25. 25 Circle – Used to represent a point at which the flowchart connects with another process. The name or reference for the other process should appear within the symbol Internal storage – This is an object which is commonly found in programming flowcharts to illustrate the information stored in memory, as opposed to on a file. Predefined process – This allows you to write one subroutine and call it as often as you like from anywhere in the code
  • 26. 26
  • 27. 27 Some guidelines in flowcharting: • All necessary requirements should be listed out in logical order. • The flowchart should be clear and easy to follow. • The usual direction of the flow of a procedure or system is from left to right or top to bottom. • only one flow line is utilized together with a terminal symbol. • Write within standard symbols briefly • It is imperative that your flowchart has a logical start and finish.
  • 28. 28
  • 29. What is a Programming Language? • It is a language with strict grammar rules, symbols, and special words used to construct a computer program. 29
  • 30. 2. Implementation Phase: Program • Translating your algorithm into a programming language is called CODING 30
  • 31. Implementation Phase: Test • TESTING your program means running (executing) your program on the computer, to see if it produces correct results • if it does not, then you must find out what is wrong with your program or algorithm and fix it--this is called debugging 31
  • 32. 3. Maintenance Phase • USE and MODIFY the program to meet changing requirements or correct errors that show up in using it • maintenance begins when your program is put into use and accounts for the majority of effort on most programs 32
  • 33. Programming Life Cycle 1 Problem-Solving Phase Analysis and Specification General Solution ( Algorithm ) Verify 2 Implementation Phase Concrete Solution ( Program ) Test 3 Maintenance Phase Use Maintain 33
  • 35. Basic Control Structures • a sequence is a series of statements that execute one after another • selection (branch) is used to execute different statements depending on certain conditions • Looping (repetition) is used to repeat statements while certain conditions are met. • a subprogram is used to break the program into smaller units 35
  • 37. SELECTION (branch) 37 IF Condition THEN Statement1 ELSE Statement2 Statement1 Statement Statement2 Condition . . .
  • 38. LOOP (repetition) 38 Statement Condition . . . False WHILE Condition Statement1
  • 39. SUBPROGRAM (function) 39 PROGRAM1 . . . SUBPROGRAM1 a meaningful collection of SEQUENCE, SELECTION, LOOP, SUBPROGRAM
  • 40. Company Payroll Case Study A small company needs an interactive program to figure its weekly payroll. The payroll clerk will input data for each employee, and each employee’s wages. Display the total wages for the week on the screen. 40
  • 41. One Employee’s Wages In one week employee ID # 4587 works 52 hours at the hourly pay rate of 24.75. Assume a 40.0 hour normal work week and an overtime pay rate factor of 1.5. What are the employee’s wages? 41 40 x 24.75 = 990.00 12 x 1.5 x 24.75 = 445.50___________ 1435.50
  • 42. Week’s Wages, in General If hours are more than 40.0, then wages = (40.0 * payRate) + (hours - 40.0) * 1.5 *payRate otherwise, wages = hours * payRate 42 RECALL EXAMPLE ( 40 x 24.75 ) + ( 12 x 1.5 x 24.75 ) = 1435.50
  • 43. Algorithm for Company Payroll Program • initialize total company payroll to 0.0 • repeat this process for each employee: 1. Get the employee’s ID empNum 2. Get the employee’s hourly payRate 3. Get the hours worked this week 4. Calculate this week’s wages 5. Add wages to total company payroll • write total company payroll on screen 43