SlideShare a Scribd company logo
1 of 46
1
Chapter 1
Overview of Programming and
Problem Solving
Dale/Weems/Headington
Slides by Sylvia Sorkin, Community College of Baltimore County - Essex
Campus
2
Chapter 1 Topics
 Computer Programming
 Programming Life-Cycle Phases
 Creating an Algorithm
 Machine Language vs. High Level Languages
 Compilation and Execution Processes
 C++ History
 Computer Components
 Computing Profession Ethics
 Problem-Solving Techniques
3
What is Computer Programming?
 It is the process of planning a
sequence of steps (called
instructions) for a computer to
follow.
STEP 1
STEP 2
STEP 3
. . .
4
Programming Life Cycle Phases
1 Problem-Solving
2 Implementation
3 Maintenance
5
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
6
Sample Problem
A programmer needs an algorithm to
determine an employee’s weekly
wages. How would the calculations
be done by hand?
7
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?
40 x $ 24.75 = $ 990.00
12 x 1.5 x $ 24.75 = $ 445.50
___________
$ 1435.50
8
If hours are more than 40.0, then
wages = (40.0 * payRate) + (hours - 40.0) * 1.5
*payRate
otherwise,
wages = hours * payRate
Weekly Wages, in General
RECALL EXAMPLE
( 40 x $ 24.75 ) + ( 12 x 1.5 x $ 24.75 ) = $1435.50
9
An Algorithm is . . .
 a step-by-step procedure for solving
a problem in a finite amount of time.
10
Algorithm to Determine an
Employee’s Weekly Wages
1. Get the employee’s hourly payRate
2. Get the hours worked this week
3. Calculate this week’s regular wages
4. Calculate this week’s overtime wages (if any)
5. Add the regular wages to overtime wages (if any)
to determine total wages for the week
11
What is a
Programming Language?
 It is a language with strict grammar
rules, symbols, and special words
used to construct a computer
program.
12
Implementation Phase:
Program
 translating your algorithm into a
programming language is called
CODING
 with C++, you use
Documentation -- your written comments
Compiler -- translates your program
into machine language
Main Program -- may call subalgorithms
13
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
14
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
15
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
16
A Tempting Shortcut?
GOAL
THINKING
CODE
REVISE
REVISE
REVISE
DEBUG
DEBUG
DEBUG
TEST
CODE
17
Memory Organization
 two circuit states correspond to 0 and 1
 bit (short for binary digit) refers to a single
0 or 1. Bit patterns represent both the
computer instructions and computer data
 1 byte = 8 bits
 1 KB = 1024 bytes
 1 MB = 1024 x 1024 = 1,048,576 bytes
18
How Many Possible Digits?
 binary (base 2) numbers use 2 digits:
JUST 0 and 1
 decimal (base 10) numbers use 10 digits:
0 THROUGH 9
19
Machine Language
 is not portable
 runs only on specific type of computer
 is made up of binary-coded instructions
(strings of 0s and 1s)
 is the language that can be directly used by
the computer
20
High Level Languages
 are portable
 user writes program in language similar to
natural language
 examples -- FORTRAN, COBOL, Pascal,
Ada, Modula-2, C++, Java
 most are standardized by ISO/ANSI to
provide an official description of the
language
21
Three C++ Program Stages
other code
from libraries,
etc.
written in
machine
language
written in
machine
language
written in
C++
via compiler via linker
SOURCE OBJECT EXECUTABLE
myprog.cpp myprog.obj myprog.exe
22
Java Programming Language
 achieves portability by using both a compiler and
an interpreter
 first, a Java compiler translates a Java program into
an intermediate bytecode--not machine language
 then, an interpreter program called the Java Virtual
Machine (JVM) translates a single instruction in the
bytecode program to machine language and
immediately runs it, one at a time
23
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
24
SEQUENCE
Statement Statement Statement . . .
25
SELECTION (branch)
IF Condition THEN Statement1 ELSE Statement2
Statement1
Statement
Statement2
Condition . . .
26
LOOP (repetition)
Statement
Condition
. . .
False
WHILE Condition DO Statement1
27
SUBPROGRAM (function)
SUBPROGRAM1 . . .
SUBPROGRAM1
a meaningful collection
of SEQUENCE,
SELECTION, LOOP,
SUBPROGRAM
28
Computer Components
Arithmetic Logic Unit
Control Unit
Auxiliary
Storage
Device
Memory Unit ( RAM & Registers )
Central Processing Unit ( CPU )
Input Device
Output Device
Peripherals
29
Memory Unit
 is an ordered sequence of storage cells, each
capable of holding a piece of information
 each cell has its own unique address
 the information held can be input data,
computed values, or your program instructions.
30
Central Processing Unit
 has 2 components to execute program
instructions
 Arithmetic/Logic Unit performs arithmetic
operations, and makes logical comparisons.
 Control Unit controls the order in which
your program instructions are executed.
31
Peripherals
 are input, output, or auxiliary storage devices
attached to a computer
 Input Devices include keyboard and mouse.
 Output Devices include printers, video display,
LCD screens.
 Auxiliary Storage Devices include disk drives,
scanners, CD-ROM and DVD-ROM drives,
modems, sound cards, speakers, and digital
cameras.
32
Some C++ History
 1972 : Dennis Ritchie at Bell Labs designs C
and 90% of UNIX is then written in C
 Late 70’s : OOP becomes popular
 Bjarne Stroustrup at Bell Labs adds features
to C to form “C with Classes”
 1983 : Name C++ first used
 1998 : ISO/ANSI standardization of C++
33
Computing Profession Ethics
 copy software only with permission from the
copyright holder
 give credit to another programmer by name
whenever using his/her code
 use computer resources only with permission
 guard the privacy of confidential data
 use software engineering principles to develop
software free from errors
34
What is Computer Science?
The Computing Curriculum 1991 (ACM/IEEE)
 Algorithms and Data Structures
 Architecture
 Artificial Intelligence and Robotics
 Database and Information Retrieval
 Human-Computer Communication
 Numerical and Symbolic Computation
 Operating Systems
 Programming Languages
 Software Engineering
 Social and Professional Context
35
Problem Solving Techniques
 ASK QUESTIONS -- about the data, the
process, the output, error conditions.
 LOOK FOR FAMILIAR THINGS -- certain
situations arise again and again.
 SOLVE BY ANALOGY -- it may give you a
place to start.
 USE MEANS-ENDS ANALYSIS -- Determine
the I/O and then work out the details.
36
More Problem Solving Techniques
 DIVIDE AND CONQUER -- break up large
problems into manageable units.
 BUILDING-BLOCK APPPROACH -- can you
solve small pieces of the problem?
 MERGE SOLUTIONS -- instead of joining
them end to end to avoid duplicate steps.
 OVERCOME MENTAL BLOCK -- by
rewriting the problem in your own words.
37
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
and data should be saved in a secondary
file.
Display the total wages for the week on
the screen.
38
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?
40 x $ 24.75 = $ 990.00
12 x 1.5 x $ 24.75 = $ 445.50
___________
$ 1435.50
39
Problem-Solving Phase
What information will be used?
INPUT DATA from outside the program
FORMULA CONSTANTS used in program
COMPUTED VALUE produced by program
OUTPUT RESULTS written to file or screen by
program
40
Problem-Solving Phase
INPUT DATA FORMULA
CONSTANTS
OUTPUT
RESULTS
Employee ID
Number
Hourly payRate
Hours worked
Normal work
hours ( 40.0 )
Overtime pay
rate factor (1.5)
Hourly payRate
Hours worked
Wages
COMPUTED VALUE
Wages
41
If hours are more than 40.0, then
wages = (40.0 * payRate) + (hours - 40.0) * 1.5
*payRate
otherwise,
wages = hours * payRate
Week’s Wages, in General
RECALL EXAMPLE
( 40 x $ 24.75 ) + ( 12 x 1.5 x $ 24.75 ) = $1435.50
42
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
6. Write empNum, payRate, hours, wages to file
 write total company payroll on screen
43
// ***************************************************
// Payroll program
// This program computes each employee’s wages and
// the total company payroll
// ***************************************************
#include <iostream> // for keyboard/screen I/O
#include <fstream> // for file I/O
using namespace std;
void CalcPay ( float, float, float& ) ;
const float MAX_HOURS = 40.0; // Maximum normal hours
const float OVERTIME = 1.5; // Overtime pay factor
C++ Program
44
C++ Code Continued
int main( )
{
float payRate; // Employee’s pay rate
float hours; // Hours worked
float wages; // Wages earned
float total; // Total company payroll
int empNum; // Employee ID number
ofstream payFile; // Company payroll file
payFile.open( “payfile.dat” ); // Open file
total = 0.0; // Initialize total
45
cout << “Enter employee number: “; // Prompt
cin >> empNum; // Read ID number
while ( empNum != 0 ) // While not done
{
cout << “Enter pay rate: “;
cin >> payRate ; // Read pay rate
cout << “Enter hours worked: “;
cin >> hours ; // and hours worked
CalcPay(payRate, hours, wages); // Compute wages
total = total + wages; // Add to total
payFile << empNum << payRate
<< hours << wages << endl;
cout << “Enter employee number: “;
cin >> empNum; // Read ID number
} 45
46
cout << “Total payroll is “
<< total << endl;
return 0 ; // Successful completion
}
// ***************************************************
void CalcPay ( /* in */ float payRate ,
/* in */ float hours ,
/* out */ float& wages )
// CalcPay computes wages from the employee’s pay rate
// and the hours worked, taking overtime into account
{
if ( hours > MAX_HOURS )
wages = (MAX_HOURS * payRate ) +
(hours - MAX_HOURS) * payRate * OVER_TIME;
else
wages = hours * payRate;
} 46

More Related Content

What's hot

Algorithmic problem solving
Algorithmic problem solvingAlgorithmic problem solving
Algorithmic problem solvingPrabhakaran V M
 
Unit 1. Problem Solving with Computer
Unit 1. Problem Solving with Computer   Unit 1. Problem Solving with Computer
Unit 1. Problem Solving with Computer Ashim Lamichhane
 
Problem Solving and Programming
Problem Solving and ProgrammingProblem Solving and Programming
Problem Solving and ProgrammingSelvaraj Seerangan
 
Direct memory access
Direct memory accessDirect memory access
Direct memory accessshubham kuwar
 
Fundamentals of the Analysis of Algorithm Efficiency
Fundamentals of the Analysis of Algorithm EfficiencyFundamentals of the Analysis of Algorithm Efficiency
Fundamentals of the Analysis of Algorithm EfficiencySaranya Natarajan
 
Algorithm - Introduction
Algorithm - IntroductionAlgorithm - Introduction
Algorithm - IntroductionMadhu Bala
 
1 introduction to problem solving and programming
1 introduction to problem solving and programming1 introduction to problem solving and programming
1 introduction to problem solving and programmingRheigh Henley Calderon
 
The Art Of Debugging
The Art Of DebuggingThe Art Of Debugging
The Art Of Debuggingsvilen.ivanov
 
Aggrement protocols
Aggrement protocolsAggrement protocols
Aggrement protocolsMayank Jain
 
Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)swapnac12
 
Error detection and correction
Error detection and correctionError detection and correction
Error detection and correctionSiddique Ibrahim
 
Lecture 2 role of algorithms in computing
Lecture 2   role of algorithms in computingLecture 2   role of algorithms in computing
Lecture 2 role of algorithms in computingjayavignesh86
 
Input Output Organization
Input Output OrganizationInput Output Organization
Input Output OrganizationKamal Acharya
 
Matrix chain multiplication
Matrix chain multiplicationMatrix chain multiplication
Matrix chain multiplicationRespa Peter
 
Von Neumann Architecture
Von Neumann ArchitectureVon Neumann Architecture
Von Neumann ArchitectureZahid Rajeel
 
Introduction to theory of computation
Introduction to theory of computationIntroduction to theory of computation
Introduction to theory of computationVinod Tyagi
 

What's hot (20)

Bayesian learning
Bayesian learningBayesian learning
Bayesian learning
 
Algorithmic problem solving
Algorithmic problem solvingAlgorithmic problem solving
Algorithmic problem solving
 
Unit 1. Problem Solving with Computer
Unit 1. Problem Solving with Computer   Unit 1. Problem Solving with Computer
Unit 1. Problem Solving with Computer
 
Problem Solving and Programming
Problem Solving and ProgrammingProblem Solving and Programming
Problem Solving and Programming
 
Direct memory access
Direct memory accessDirect memory access
Direct memory access
 
Fundamentals of the Analysis of Algorithm Efficiency
Fundamentals of the Analysis of Algorithm EfficiencyFundamentals of the Analysis of Algorithm Efficiency
Fundamentals of the Analysis of Algorithm Efficiency
 
Algorithm - Introduction
Algorithm - IntroductionAlgorithm - Introduction
Algorithm - Introduction
 
Pram model
Pram modelPram model
Pram model
 
1 introduction to problem solving and programming
1 introduction to problem solving and programming1 introduction to problem solving and programming
1 introduction to problem solving and programming
 
Memory hierarchy
Memory hierarchyMemory hierarchy
Memory hierarchy
 
The Art Of Debugging
The Art Of DebuggingThe Art Of Debugging
The Art Of Debugging
 
Aggrement protocols
Aggrement protocolsAggrement protocols
Aggrement protocols
 
Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)
 
Problems, Problem spaces and Search
Problems, Problem spaces and SearchProblems, Problem spaces and Search
Problems, Problem spaces and Search
 
Error detection and correction
Error detection and correctionError detection and correction
Error detection and correction
 
Lecture 2 role of algorithms in computing
Lecture 2   role of algorithms in computingLecture 2   role of algorithms in computing
Lecture 2 role of algorithms in computing
 
Input Output Organization
Input Output OrganizationInput Output Organization
Input Output Organization
 
Matrix chain multiplication
Matrix chain multiplicationMatrix chain multiplication
Matrix chain multiplication
 
Von Neumann Architecture
Von Neumann ArchitectureVon Neumann Architecture
Von Neumann Architecture
 
Introduction to theory of computation
Introduction to theory of computationIntroduction to theory of computation
Introduction to theory of computation
 

Similar to Chapter 01.PPT

Fundamentals of programming with C++
Fundamentals of programming with C++Fundamentals of programming with C++
Fundamentals of programming with C++Seble Nigussie
 
L1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdfL1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdfMMRF2
 
Program design and problem solving techniques
Program design and problem solving techniquesProgram design and problem solving techniques
Program design and problem solving techniquesDokka Srinivasu
 
Stnotes doc 5
Stnotes doc 5Stnotes doc 5
Stnotes doc 5Alok Jain
 
Chapter 2(1)
Chapter 2(1)Chapter 2(1)
Chapter 2(1)TejaswiB4
 
65_96195_CC112_2014_1__1_1_week1.pdf
65_96195_CC112_2014_1__1_1_week1.pdf65_96195_CC112_2014_1__1_1_week1.pdf
65_96195_CC112_2014_1__1_1_week1.pdfAhmedEmadElGhetany
 
Programs_Problem_Solving_Algorithms.ppt
Programs_Problem_Solving_Algorithms.pptPrograms_Problem_Solving_Algorithms.ppt
Programs_Problem_Solving_Algorithms.pptmalik681299
 
PCCF UNIT 1.pptx
PCCF UNIT 1.pptxPCCF UNIT 1.pptx
PCCF UNIT 1.pptxDivyaKS12
 

Similar to Chapter 01.PPT (20)

L1
L1L1
L1
 
Fundamentals of programming with C++
Fundamentals of programming with C++Fundamentals of programming with C++
Fundamentals of programming with C++
 
Comp102 lec 1
Comp102   lec 1Comp102   lec 1
Comp102 lec 1
 
L1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdfL1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdf
 
Program design and problem solving techniques
Program design and problem solving techniquesProgram design and problem solving techniques
Program design and problem solving techniques
 
Stnotes doc 5
Stnotes doc 5Stnotes doc 5
Stnotes doc 5
 
part_1 (1).ppt
part_1 (1).pptpart_1 (1).ppt
part_1 (1).ppt
 
Mcs lec2
Mcs lec2Mcs lec2
Mcs lec2
 
Chapter 2(1)
Chapter 2(1)Chapter 2(1)
Chapter 2(1)
 
6272 cnote
6272 cnote6272 cnote
6272 cnote
 
C progrmming
C progrmmingC progrmming
C progrmming
 
PROBLEM SOLVING
PROBLEM SOLVINGPROBLEM SOLVING
PROBLEM SOLVING
 
Week10 final
Week10 finalWeek10 final
Week10 final
 
Chapter 1.ppt
Chapter 1.pptChapter 1.ppt
Chapter 1.ppt
 
Savitch Ch 01
Savitch Ch 01Savitch Ch 01
Savitch Ch 01
 
Savitch ch 01
Savitch ch 01Savitch ch 01
Savitch ch 01
 
Savitch ch 01
Savitch ch 01Savitch ch 01
Savitch ch 01
 
65_96195_CC112_2014_1__1_1_week1.pdf
65_96195_CC112_2014_1__1_1_week1.pdf65_96195_CC112_2014_1__1_1_week1.pdf
65_96195_CC112_2014_1__1_1_week1.pdf
 
Programs_Problem_Solving_Algorithms.ppt
Programs_Problem_Solving_Algorithms.pptPrograms_Problem_Solving_Algorithms.ppt
Programs_Problem_Solving_Algorithms.ppt
 
PCCF UNIT 1.pptx
PCCF UNIT 1.pptxPCCF UNIT 1.pptx
PCCF UNIT 1.pptx
 

Recently uploaded

WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...WSO2
 
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of TransformationWSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of TransformationWSO2
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024VictoriaMetrics
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxAnnaArtyushina1
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2
 
WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...
WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...
WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...WSO2
 
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
WSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid EnvironmentsWSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid EnvironmentsWSO2
 
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdfAzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdfryanfarris8
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in sowetomasabamasaba
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...WSO2
 
WSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - KanchanaWSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - KanchanaWSO2
 
WSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
WSO2CON2024 - Why Should You Consider Ballerina for Your Next IntegrationWSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
WSO2CON2024 - Why Should You Consider Ballerina for Your Next IntegrationWSO2
 
WSO2Con2024 - Low-Code Integration Tooling
WSO2Con2024 - Low-Code Integration ToolingWSO2Con2024 - Low-Code Integration Tooling
WSO2Con2024 - Low-Code Integration ToolingWSO2
 

Recently uploaded (20)

WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...
 
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of TransformationWSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...
WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...
WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...
 
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
WSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid EnvironmentsWSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid Environments
 
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdfAzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
 
WSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - KanchanaWSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - Kanchana
 
WSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
WSO2CON2024 - Why Should You Consider Ballerina for Your Next IntegrationWSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
WSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
 
WSO2Con2024 - Low-Code Integration Tooling
WSO2Con2024 - Low-Code Integration ToolingWSO2Con2024 - Low-Code Integration Tooling
WSO2Con2024 - Low-Code Integration Tooling
 

Chapter 01.PPT

  • 1. 1 Chapter 1 Overview of Programming and Problem Solving Dale/Weems/Headington Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus
  • 2. 2 Chapter 1 Topics  Computer Programming  Programming Life-Cycle Phases  Creating an Algorithm  Machine Language vs. High Level Languages  Compilation and Execution Processes  C++ History  Computer Components  Computing Profession Ethics  Problem-Solving Techniques
  • 3. 3 What is Computer Programming?  It is the process of planning a sequence of steps (called instructions) for a computer to follow. STEP 1 STEP 2 STEP 3 . . .
  • 4. 4 Programming Life Cycle Phases 1 Problem-Solving 2 Implementation 3 Maintenance
  • 5. 5 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
  • 6. 6 Sample Problem A programmer needs an algorithm to determine an employee’s weekly wages. How would the calculations be done by hand?
  • 7. 7 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? 40 x $ 24.75 = $ 990.00 12 x 1.5 x $ 24.75 = $ 445.50 ___________ $ 1435.50
  • 8. 8 If hours are more than 40.0, then wages = (40.0 * payRate) + (hours - 40.0) * 1.5 *payRate otherwise, wages = hours * payRate Weekly Wages, in General RECALL EXAMPLE ( 40 x $ 24.75 ) + ( 12 x 1.5 x $ 24.75 ) = $1435.50
  • 9. 9 An Algorithm is . . .  a step-by-step procedure for solving a problem in a finite amount of time.
  • 10. 10 Algorithm to Determine an Employee’s Weekly Wages 1. Get the employee’s hourly payRate 2. Get the hours worked this week 3. Calculate this week’s regular wages 4. Calculate this week’s overtime wages (if any) 5. Add the regular wages to overtime wages (if any) to determine total wages for the week
  • 11. 11 What is a Programming Language?  It is a language with strict grammar rules, symbols, and special words used to construct a computer program.
  • 12. 12 Implementation Phase: Program  translating your algorithm into a programming language is called CODING  with C++, you use Documentation -- your written comments Compiler -- translates your program into machine language Main Program -- may call subalgorithms
  • 13. 13 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
  • 14. 14 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
  • 15. 15 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
  • 17. 17 Memory Organization  two circuit states correspond to 0 and 1  bit (short for binary digit) refers to a single 0 or 1. Bit patterns represent both the computer instructions and computer data  1 byte = 8 bits  1 KB = 1024 bytes  1 MB = 1024 x 1024 = 1,048,576 bytes
  • 18. 18 How Many Possible Digits?  binary (base 2) numbers use 2 digits: JUST 0 and 1  decimal (base 10) numbers use 10 digits: 0 THROUGH 9
  • 19. 19 Machine Language  is not portable  runs only on specific type of computer  is made up of binary-coded instructions (strings of 0s and 1s)  is the language that can be directly used by the computer
  • 20. 20 High Level Languages  are portable  user writes program in language similar to natural language  examples -- FORTRAN, COBOL, Pascal, Ada, Modula-2, C++, Java  most are standardized by ISO/ANSI to provide an official description of the language
  • 21. 21 Three C++ Program Stages other code from libraries, etc. written in machine language written in machine language written in C++ via compiler via linker SOURCE OBJECT EXECUTABLE myprog.cpp myprog.obj myprog.exe
  • 22. 22 Java Programming Language  achieves portability by using both a compiler and an interpreter  first, a Java compiler translates a Java program into an intermediate bytecode--not machine language  then, an interpreter program called the Java Virtual Machine (JVM) translates a single instruction in the bytecode program to machine language and immediately runs it, one at a time
  • 23. 23 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
  • 25. 25 SELECTION (branch) IF Condition THEN Statement1 ELSE Statement2 Statement1 Statement Statement2 Condition . . .
  • 26. 26 LOOP (repetition) Statement Condition . . . False WHILE Condition DO Statement1
  • 27. 27 SUBPROGRAM (function) SUBPROGRAM1 . . . SUBPROGRAM1 a meaningful collection of SEQUENCE, SELECTION, LOOP, SUBPROGRAM
  • 28. 28 Computer Components Arithmetic Logic Unit Control Unit Auxiliary Storage Device Memory Unit ( RAM & Registers ) Central Processing Unit ( CPU ) Input Device Output Device Peripherals
  • 29. 29 Memory Unit  is an ordered sequence of storage cells, each capable of holding a piece of information  each cell has its own unique address  the information held can be input data, computed values, or your program instructions.
  • 30. 30 Central Processing Unit  has 2 components to execute program instructions  Arithmetic/Logic Unit performs arithmetic operations, and makes logical comparisons.  Control Unit controls the order in which your program instructions are executed.
  • 31. 31 Peripherals  are input, output, or auxiliary storage devices attached to a computer  Input Devices include keyboard and mouse.  Output Devices include printers, video display, LCD screens.  Auxiliary Storage Devices include disk drives, scanners, CD-ROM and DVD-ROM drives, modems, sound cards, speakers, and digital cameras.
  • 32. 32 Some C++ History  1972 : Dennis Ritchie at Bell Labs designs C and 90% of UNIX is then written in C  Late 70’s : OOP becomes popular  Bjarne Stroustrup at Bell Labs adds features to C to form “C with Classes”  1983 : Name C++ first used  1998 : ISO/ANSI standardization of C++
  • 33. 33 Computing Profession Ethics  copy software only with permission from the copyright holder  give credit to another programmer by name whenever using his/her code  use computer resources only with permission  guard the privacy of confidential data  use software engineering principles to develop software free from errors
  • 34. 34 What is Computer Science? The Computing Curriculum 1991 (ACM/IEEE)  Algorithms and Data Structures  Architecture  Artificial Intelligence and Robotics  Database and Information Retrieval  Human-Computer Communication  Numerical and Symbolic Computation  Operating Systems  Programming Languages  Software Engineering  Social and Professional Context
  • 35. 35 Problem Solving Techniques  ASK QUESTIONS -- about the data, the process, the output, error conditions.  LOOK FOR FAMILIAR THINGS -- certain situations arise again and again.  SOLVE BY ANALOGY -- it may give you a place to start.  USE MEANS-ENDS ANALYSIS -- Determine the I/O and then work out the details.
  • 36. 36 More Problem Solving Techniques  DIVIDE AND CONQUER -- break up large problems into manageable units.  BUILDING-BLOCK APPPROACH -- can you solve small pieces of the problem?  MERGE SOLUTIONS -- instead of joining them end to end to avoid duplicate steps.  OVERCOME MENTAL BLOCK -- by rewriting the problem in your own words.
  • 37. 37 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 and data should be saved in a secondary file. Display the total wages for the week on the screen.
  • 38. 38 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? 40 x $ 24.75 = $ 990.00 12 x 1.5 x $ 24.75 = $ 445.50 ___________ $ 1435.50
  • 39. 39 Problem-Solving Phase What information will be used? INPUT DATA from outside the program FORMULA CONSTANTS used in program COMPUTED VALUE produced by program OUTPUT RESULTS written to file or screen by program
  • 40. 40 Problem-Solving Phase INPUT DATA FORMULA CONSTANTS OUTPUT RESULTS Employee ID Number Hourly payRate Hours worked Normal work hours ( 40.0 ) Overtime pay rate factor (1.5) Hourly payRate Hours worked Wages COMPUTED VALUE Wages
  • 41. 41 If hours are more than 40.0, then wages = (40.0 * payRate) + (hours - 40.0) * 1.5 *payRate otherwise, wages = hours * payRate Week’s Wages, in General RECALL EXAMPLE ( 40 x $ 24.75 ) + ( 12 x 1.5 x $ 24.75 ) = $1435.50
  • 42. 42 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 6. Write empNum, payRate, hours, wages to file  write total company payroll on screen
  • 43. 43 // *************************************************** // Payroll program // This program computes each employee’s wages and // the total company payroll // *************************************************** #include <iostream> // for keyboard/screen I/O #include <fstream> // for file I/O using namespace std; void CalcPay ( float, float, float& ) ; const float MAX_HOURS = 40.0; // Maximum normal hours const float OVERTIME = 1.5; // Overtime pay factor C++ Program
  • 44. 44 C++ Code Continued int main( ) { float payRate; // Employee’s pay rate float hours; // Hours worked float wages; // Wages earned float total; // Total company payroll int empNum; // Employee ID number ofstream payFile; // Company payroll file payFile.open( “payfile.dat” ); // Open file total = 0.0; // Initialize total
  • 45. 45 cout << “Enter employee number: “; // Prompt cin >> empNum; // Read ID number while ( empNum != 0 ) // While not done { cout << “Enter pay rate: “; cin >> payRate ; // Read pay rate cout << “Enter hours worked: “; cin >> hours ; // and hours worked CalcPay(payRate, hours, wages); // Compute wages total = total + wages; // Add to total payFile << empNum << payRate << hours << wages << endl; cout << “Enter employee number: “; cin >> empNum; // Read ID number } 45
  • 46. 46 cout << “Total payroll is “ << total << endl; return 0 ; // Successful completion } // *************************************************** void CalcPay ( /* in */ float payRate , /* in */ float hours , /* out */ float& wages ) // CalcPay computes wages from the employee’s pay rate // and the hours worked, taking overtime into account { if ( hours > MAX_HOURS ) wages = (MAX_HOURS * payRate ) + (hours - MAX_HOURS) * payRate * OVER_TIME; else wages = hours * payRate; } 46