The Program Development Process and Software Design
Vu Ngoc Thanh Sang
C++ COMPILERS
Online
• [Link]
• [Link]
• [Link]
• [Link]
Offline
• Visual Studio Code (Window), Xcode (Mac), Clion (Window, Mac)
PROBLEM SOLVING
• People solve hundreds of simple problems every day without thinking
about how they do it.
• Complext or unfamiliar problems requires extensive analysis and planning.
• Understanding the thought process involved in solving simple and familiar
problems will make solving complex or unfamiliar ones easier.
PROBLEM SOLVING
PROBLEM SOLVING
CREATING COMPUTER SOLUTIONS TO PROBLEMS
• A similar process to everyday problem solving is used to create computer
programs
• A computer program is a solution implemented on a computer
• There are six steps to creating a computer solution to a problem
CREATING COMPUTER SOLUTIONS TO PROBLEMS
A similar problem-solving process is used to create a computer program.
INPUTS ALGORITHMS OUTPUT(S)
1. Analyze the problem
2. Plan the algorithm
3. Manually check the algorithm
4. Code the algorithm into a program
5. Desk-check the program
6. Evaluate and modify (if necessary) the program
STEP 1 – ANALYZING THE PROBLEM
Addison 'Reilly wants a program that calculates and displays the cost
of a 4K Ultra HD TV, which is finally on sale at one of the stores in her
area. The program should calculate the cost by multiplying the sale
price by the state sales tax rate and then adding the result to the sale
price.
STEP 1 – ANALYZING THE PROBLEM
The output(s) is the goal of solving the problem, and the input(s) is the item
or items needed to achieve the goal.
• Outputs: What does the user want to see displayed on the screen,
printed on paper, or stored in a file?
• Inputs: What information will the computer need to know to display,
print, or store the output items?
STEP 1 – ANALYZING THE PROBLEM
• Some programmers use an IPO chart to organize and summarize the results
of a problem analysis
• IPO: Input, processing, and output
HINTS FOR ANALYZING THE PROBLEM
• Several readings of the problem may be necessary to fully understand the
problem.
• Cross out irrelevant information in the problem description.
Addison 'Reilly wants a program that calculates and displays the cost
of a 4K Ultra HD TV, which is finally on sale at one of the stores in her
area. The program should calculate the cost by multiplying the sale
price by the state sales tax rate and then adding the result to the sale
price.
HINTS FOR ANALYZING THE PROBLEM
• Some problem specifications contain incomplete information
Cintia Johanson earns $11.50 per hour. Last week, she worked 45
hours. Create a program that calculates and displays her weekly gross
pay.
• Distinguish between information that is missing and information that is
implied
Gordon Matthew wants a program that calculates and displays the
area of any rectangle.
STEP 2 – PLAN THE ALGORIHM
Describe the input-output relationship
This program will allow the
user to check the number
whether it's even or odd.
if "1”
print "I am case 1"
if "2"
print "I am case 2"
Natural Language Pseudocode Flowchart
PSEUDOCODE
Pseudocode
• English-like representation of the logical steps it takes to solve a
problem.
• Pseudo-code can be thought of as a simplified form of programming
code.
• The prefix ‘pseudo’ means ‘false’ or ‘not genuine’.
• Writing pseudo code allows us to lay down the logic of a problem in a
“almost like real code” way without having to worry about the actual
strict rules and syntax of a particular language.
PSEUDOCODE
By definition, there are no hard and fast rules for writing pseudo-code, but
certain guidelines will ensure that the algorithm is clear:
• Short English statements
• Describe each step of the algorithm as briefly as possible.
• Use uppercase letters with keywords and other parts of the pseudo-code
which are closer to a programming language.
• Not understandable by a computer
PSEUDOCODE
Inputs: sale price, sales tax rate
Output: cost
Algorithm:
1. Enter the sale price and sales tax rate
2. Calculate the cost by multiplying the sale price by the sales tax rate and
then adding the result to the sale price
3. Display the cost
FLOWCHART
• Create a flowchart
• Draw geometric shapes that contain the individual
statements
• Connect shapes with arrows
• Input symbol
• Indicates input operation
• Parallelogram
• Processing symbol
• Contains processing statements
such as arithmetic
• Rectangle
FLOWCHART
• Output symbol
• Represents output statements
• Parallelogram
• Flowlines
• Arrows that connect steps
• Terminal symbols
• Start/stop symbols
• Shaped like a racetrack
• Also called lozenges
FLOWCHART
STEP 3 – DESK-CHECK THE ALGORITHM
• Desk-checking an algorithm verifies that it is correct
• Refers to checking an algorithm by hand, rather than with a computer
• Choose sample data and manually compute the expected output value
• Creating a desk-check table can be helpful
STEP 3 – DESK-CHECK THE ALGORITHM
• Valid data: data that the algorithm is expecting the user to enter
• Invalid data: data that the algorithm is not expecting the user to enter
• You should test an algorithm with invalid data
• Users may make mistakes when entering data
STEP 4 – CODE AN ALGORITHM TO A PROGRAM
• The fourth step in the problem-solving process is to code algorithm into a
program
• Begin by declaring a memory location for each input, processing, and
output value in IPO chart
• Optionally initialize each value (highly preferred)
• Next, you code the instructions for the algorithm
STEP 4 – CODE AN ALGORITHM TO A PROGRAM
STEP 4 – CODE AN ALGORITHM TO A PROGRAM
• C++ uses stream objects to perform input/output operations
• A stream is a sequence of characters
• The extraction operator (>>) takes information out of cin object and stores
it in internal memory
• Syntax: cin >> variableName;
STEP 4 – CODE AN ALGORITHM TO A PROGRAM
• You use a prompt (message) to let the user know what data is to be entered
• The cout object is used with the insertion operator (<<) to display
information on the screen
• Information can be any combination of literal constants, named constants,
and variables
• Multiple items can be printed in the same statement
• Syntax: cout << item1 [<< item2 << itemN];
• Part in brackets is optional
STEP 4 – CODE AN ALGORITHM TO A PROGRAM
• A stream manipulator is used to manipulate (manage) the characters in an
input or output string
• endl is a stream manipulator that advances the cursor to the next line on
the screen
• Equivalent to pressing the Enter key
STEP 5 – DESK-CHECK THE PROGRAM
• Fifth step is to desk-check the program to make sure instructions were
translated correctly
• You should desk-check the program using sample data used to desk-check
the algorithm
• Results of both desk-checks should be the same
• First, place names of the declared memory locations in a new desk-check
table along with each memory location’s initial value
• Next, desk-check remaining C++ instructions in order, recording any
changes made to the variables
STEP 6 – EVALUATE AND MODIFY THE PROGRAM
• Final step in the problem-solving process
• You evaluate a program by running the program on the computer and
entering the sample data used when desk-checking the program
• If evaluation reveals errors (known as bugs), they must be fixed
• Process of locating and fixing errors is called debugging
• Two types of bugs: syntax errors and logic errors
STEP 6 – EVALUATE AND MODIFY THE PROGRAM
• Syntax errors result from breaking programming language’s rules; cause
compiler errors
• Logic errors don’t cause compiler errors; can be hard to identify
• Example: entering instructions in the wrong order
• Need a text editor to enter C++ instructions
• Instructions are called source code and are saved in source files with
extension .cpp
• Need a compiler to translate source code into machine code (also called
object code)
EXERCISES
• Exercise 1: Complete the C++ instructions column
EXERCISES
• Exercise 2: Complete the C++ instructions column
EXERCISES
• Exercise 3: A local zoo offers three different memberships: an individual
membership for $99 per year, a dual membership for $175 per year, and a family
membership for $225 per year. The membership director wants a program that
displays the total membership revenue for the year, as well as the amount of the
total revenue contributed by each membership type.
a) Use pseudocode and flowchart to describe the problem.
b) Desk-check the algorithm twice. For the first desk-check, use 50, 75, and 150 as
the numbers of individual, dual, and family memberships sold during the year. For
the second desk-check, use 35, 150, and 265. Record the percentages with one
decimal place.
c) Write a complete C++ program for solving the problem.
d) Check the program using the desk-check result in b)
THANK YOU FOR YOUR LISTENING