0% found this document useful (0 votes)
11 views

Lecture 2 - Introduction To Programming (Problem Solving)

cfgh

Uploaded by

Fatimah Amin
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Lecture 2 - Introduction To Programming (Problem Solving)

cfgh

Uploaded by

Fatimah Amin
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 19

Lecture 2

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

• State the problem clearly and unambiguously and gain a clear


understanding of what is required for its solution.
• Objective is to eliminate unimportant aspects

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.

2 techniques of writing an algorithm will be discussed are :-

1. Pseudocode : A combination of English / Bahasa


phrases and C++ constructs to describe
step by steps execution of a program

2. Flowchart : A diagram that shows the step by step


execution of a program
Flowcharting Symbols

• Each symbol indicates the type of operation to be


performed.
• Flowchart graphically illustrates the sequence in which the
operations are to be performed

Start / Stop program Process

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

SEQUENCE – is a series of statements that execute one after


another

Statement Statement Statement ….

SELECTION (branch) - is used to execute different statements


depending on certain conditions.
IF condition THEN statement1 ELSE stament2

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.

TESTING AND EVALUATION


• Requires testing the completed program to verify that it works
as desired.
• Run the program several times using different sets of data.

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…

•A documentation package should include

1. A definition of the problem. Why was the program written?


What were the objectives? Who requested the program, and
who approved it? These are the types of questions that should
be answered.
2. A description of the system. The system environment (hardware,
software, and organization) in which the program functions should
be described (including systems flowcharts). General systems
specifications outlining the scope of the problem, the form and type
of input data to be used, and the form and type of output required
should be clearly defined.
3. A description of the program. Programming flowcharts, program
listings, program controls, test data and test results, storage dumps-
these and other documents that describe the program and give a
historical record of problems and/or changes should be included.
EXAMPLE OF PROBLEM 1

Write a program that inputs 2 integers A and B. Calculate and prints the value
of A2 and B3

• REQUIREMENT SPECIFICATION

The program should be able to calculate the power of 2 and the


power of 3 of 2 input integer data and print out both values.

• 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>

using namespace std;

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?

False Print “BIG”

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

•Check for any


semantic / logic
errors
# include <iostream>
using namespace std;
User friendly
void main( )
characteristic
{
int Nom1 ;
cout<< “Please enter a number \n";
cin >> Nom1;
if (Nom1 > 10)
cout <<“BIG”;
cout <<endl;
}
Output

Please enter a number


15
BIG
Identify the problem below and provide requirement specifications,
problem analysis, and solution design in the form of Pseudocode and
Flowchart to present the solution to the following problem.

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.

You might also like