Lecture 2 - Introduction To Programming (Problem Solving)
Lecture 2 - Introduction To Programming (Problem Solving)
Introduction to Programming
(Problem Solving)
• Programming is problem solving activities
• To solve problem , programmers use the software development
method.
PROGRAM
SOFTWARE 6 Documentation
DEVELOPMENT
METHOD 5 Testing and evaluation
4 System implementation
3 System Design
2 System Analysis
1 Requirement Specification
PROBLEM
REQUIREMENT SPECIFICATION
SYSTEM ANALYSIS
• Involves identifying the problem
Inputs
Outputs
Additional requirements or constraints on the solution
• At this stage you should also determine the required format in
which the result should be displayed
• Develop list of formulas that specify relationships between
problem inputs and outputs
SYSTEM DESIGN
• Requires to develop a list of steps called an algorithm.
• Also verify that the algorithm solves the problem as intended
• Use top-down design (divide and conquer) ; list the major step
or sub problems . Solve original problem by solving each
sub problems.
• Desk checking is the important part of system design. It is a step
by step simulation of the computer execution of an algorithm.
Symbols
Input/output Decision
Connecto
Direction of flow
r
Example:
Write a program that will read one value from the keyboard.
Your program will then calculate the square value for the input.
If the square value is greater than 50, your program will assign
"not valid" to a variable. But if otherwise, your program will
assign "valid" to the respective variable. Finally, your program
will display the input value and the variable value on the screen.
Flowchart Pseudocode
A
1. Start
Start
2. Input A
A2 > 50?
Yes 3. Calculate A2
Input A
4. If A2 > 50
No Set “Not Valid “ to Str
else
Str = Str =
“valid” “Not valid” Set “Valid” to Str
Calculate A2 5. Print A , Str
6. Stop
Print A
Print Str
A Input : 10
Output : 10
Stop Not Valid
BASIC CONTROL STRUCTURES
True Statement1
Condition
….
False Statement2
LOOP (repetition) - is used to repeat statements while certain
conditions are met.
False
Condition ….
Tru
e
Statement
SYSTEM IMPLEMENTATION
• Involves writing the algorithm as a program.
• Convert each algorithm step into one /more statements in a
programming language.
DOCUMENTATION
• Continuous process, beginning with the problem definition.
• Involves collecting, organizing, storing, and other-wise maintaining
a complete record of the programs and other documents associated
with the data processing system.
Continue…
Write a program that inputs 2 integers A and B. Calculate and prints the value
of A2 and B3
• REQUIREMENT SPECIFICATION
• SYSTEM ANALYSIS
Input : A and B
Output : result of A2
result of B3
Variables : PA , PB
Formula : A*A
B*B*B
• SYSTEM DESIGN Flowchart
Pseudocode Begin
1. Begin
Input
2. Input A and B
A,B
3. Calculate A2 and B3
4. Print results of A2 and B3
5. End Calculate
A2 , B3
Prints results of
A2 and B3
End
• SYSTEM IMPLEMENTATION • SYSTEM TESTING AND
EVALUATION
# include <iostream>
Output
# include <iomanip>
# include <cmath>
int main( )
{
int A, B, PA, PB;
cin >> A >> B; * Check for any semantic / logic
PA = pow(A,2); errors
PB = pow(B,3);
cout << endl << endl << PA << endl;
cout << PB << endl;
return 0;
}
EXAMPLE OF PROBLEM 2
Write a program that input 1integers Nom1. Print message “BIG” if Nom1
more than 10.
• REQUIREMENT SPECIFICATION
The program should be able to input 1 integer data and print out the
message “BIG” if the data entered is more than 10.
• SYSTEM ANALYSIS
Input : Nom1
Output : Print Nom1
Print Message “BIG”
Variables : Nom1
Formula : IF Nom1 > 10 THEN Print “BIG”
Flowchart
• SYSTEM DESIGN
Begin
Pseudocode
1. Begin Input
2. Input Nom1 Nom1
3. IF Nom1 > 10
4. Print “BIG”
5. end
True
Nom1> 10?
End
• SYSTEM IMPLEMENTATION
# include <iostream>
using namespace std;
/ / The program uses the cin instruction for inputting data
int main( )
{
int Nom1;
cin >> Nom1;
if (Nom1 > 10)
cout <<“BIG”;
cout <<endl;
return 0;
}
• SYSTEM TESTING AND EVALUATION
Your house sits on a plot of land measuring 60 feet long by 50 feet wide.
The length and width of your house are 50 feet by 40 feet. The grass in
your yard is long. After discussing with your father, he agrees to hire a
lawn mower. The lawn mowing rate is 10 cents for every 5 square feet,
while the mowing time rate is 30 seconds for every 5 square feet. Your
father asks you to calculate the cost and time required to mow the lawn.