charlyn a. malimata. at the end of this lesson, you should be able to: 1. define program and...

54
Charlyn A. Malimata

Upload: bernadette-shaw

Post on 25-Dec-2015

218 views

Category:

Documents


0 download

TRANSCRIPT

Charlyn A. Malimata

At the end of this lesson, you should be able to:

1.Define program and programming2.Give the meaning of algorithm, pseudocode

and flowchart.3.Enumerate the advantages of making an

algorithm, pseudocode and flowchart.4.Design algorithms and pseudocodes.5.Name the flowcharting symbols.

7. Draw the flowcharts.8. Follow the guidelines in creating a

flowchart.9. Develop critical, logical and analytical

thinking in preparing for program writing.

Programming◦Is the process of giving instruction to a computer

Programs◦Are the instructions given to the computer to arrive at a certain result.

Logic formulations and problem-solving are the fundamentals of programming. It requires an intricate process of critical and analytical thinking combined with precision and keenness to details. The planning stage is very important because it serves as the backbone of any program.

NOTE: “ A GOOD PROGRAMMER IS A GOOD

PLANNER”

A logical procedure or set of steps to be followed to arrive at a solution to a problem.

An algorithm is the breaking down of a problem into simple steps in order to find the right answer.

Recipe in a cookbook – a complicated dish is broken down into simple cooking instructions.

Choreography of a dance – a difficult dance is broken down into a succession of basic steps

Word problem in Math – a complex problem in Math is broken down into parts to arrive at a solution.

An algorithm in English statements in an outline form. This is used to conceptualize the flow of the program before encoding it in a programming language.

Pseudocode for Making Soap◦ Step 1: Prepare your workspace◦ Step 2: Cut and weight the soap base.◦ Step 3: Melt the soap base.◦ Step 4: Add the fragrance or essentials oil◦ Step 5: Add color to the melted soap◦ Step 6: Stir the melted soap◦ Step 7: Pour the soap into the mold◦ Step 8: Unmold the soap

Pseudocode for Taking a special quiz◦ Step 1: Talk to the teacher. Tell her your concern◦ Step 2: Give her the excuse letter ◦ Step 3: Ask politely for a schedule to have a quiz◦ Step 4: If you are free on the given schedule, tell her

you will be there to take the quiz.◦ Step 5: If the schedule will be conflicting to another

special quiz ask for another time and date until the schedule is finalized.

◦ Step 6: Go on the scheduled date and time.

Note: Pseudocodes cannot be executed on a real computer

The graphical representation of an algorithm. Flowchart is the pictorial description of sequenced activities and logic to be performed by the computer for carrying out data processing. It uses special symbols which represent a specific function.

Flowcharts are used by programmers before the actual start of any programming activity.

Flowchart is otherwise known as Data Flow Diagram

Flowcharts are used by programmers before the actual start of any programming activity.

Flowchart is otherwise known as Data Flow Diagram

Flowchart is the so called “BLUE PRINT” of a program.

TERMINAL - Represents the beginning and the end of the program. It contains the words “Begin” or “Start” and “End” or “Stop”.PROCESS OR ACTION -Represents a step or an instruction such as comparison or arithmetic operations.

Ex: Gather all materials in a box;

Add 5 and 7INPUT OR OUTPUT - Represents the step wherein information such as letters and numbers are entered byt he user or produced by the process.

Ex: Input 3 numbers; Get A, B, C;

Print A

ARROW OR FLOW DIRECTION INDICATOR – Indicates the flow of direction or the next activity.DECISION –Denotes a decision to be made. It involves 2 courses of action that is answered by either “yes/true” or “no/false” wherein one has to chosen. The symbol represents the “if..then”{, and the “for .. Next statements

PREPARATION – Represents the process that will change the direction of initialization of any value or the execution of a variable.

PREDEFINED PROCESS OR SUBROUTINE – Indicates a submodule or subflowchart embedded within a larger process. It can be described in a detail in a separate flowchart.

ON-PAGE CONNECTORS –Indicates that the process is continued where the matching on page connector is placed (either on the same page or at a different page)

BEGIN

Exercise daily

Give time, effort and commitment

ENDFit and healthy

body

Sleep 8 hours a day

Have a balanced diet

Take vitamins

No

Yes

BEGIN

Correct username

and password

END

Type Internet username and

password

Access the Internet

Create a flowchart for the following lowchart for the following situations/problemssituations/problems◦ FFlowchart to test printerlowchart to test printer◦ Flowchart to get the product of 2 numbersFlowchart to get the product of 2 numbers◦ Flowchart to print the area of a circleFlowchart to print the area of a circle

1. The flow of the program is easiow of the program is easily understood.

2. It determines the validity of the processes involved in the program.

3. Debugging or correcting of errors becomes less complicated.

4. It produces effective program documentation.

1. Determine the following:

Data to be entered Information to be produced The way the data will be entered The point when data will be given The point when information will be produced

1. There should be only be one start/begin and stop/end processes.

2. Concentrate on the logic of the program.3. Choose only the important steps. No need to

represent all the steps in the flowchart.

2 classifications of programming language. These pertains to the ways on how the program are written.

High level programming – resembles human language and corresponds to several machine language instructions

Low level programming – or machine language, describes exactly the procedures to be carried out by the computer’s central processing unit

High level Programming language includes :

1.Visual Basic2.Java3.Visual C++4.BASIC5.Pascal6.COBOL7.FORTRAN

Okay now, start getting busy by doing your first exercise for this module.

Plant and produce carrots Charter change (with decision box) Get the area of a rectangle Input 2 numbers and print the larger

number Get the quotient of 2 numbers and print

the quotient if it is greater than 5 Compute and print for the average of 3

numbers

A program handles different data to be processed by the computer. These data are classified into different types:

Numeric data ◦ Integer - whole◦ Float or Double – numbers with decimal

Alphanumeric Data◦Number – numbers that cannot be used for

mathematical operations

◦Character – a single letter or a special character

◦String – a combination of characters Date and time Logical Data

A variables stores data, It allocates a portion of the memory depending on the type of data a variables holds.

◦It must begin with a letter or an alphabet and may be followed by combinations of alphanumeric characters.

◦The name of the variables should be indicative of the value it holds.

◦Avoid using confusing letters or numbers such as zero and the letter O.

◦Use underscore in replacement of a space.

◦Lessen the number of characters of your variable. The shorter the variable, the better and more efficient the program will be

◦In most cases, uppercase and lowercase letters are read differently A and a may hold different data

Constants are values that do not change during the execution of the program.

Examples:◦ Pi = 3.1416◦ X=100

Classifications of Operators◦ Arithmetic Operators

Addition Subtraction Multiplication Division Exponentiation Modulus NegationEx: 5+(4*2/2) – 3 =6

◦ Relational Operators Greater than > Less than < Equal to = Not equal to <> Greater than or equal to >= Less than or equal to <=

◦ Logical Operators AND OR NOT

Conditions for the logical functions

Input 2 whole numbers. Compute and print the sum of the 2 numbers

When a problem involves the 3 Types of operators, the following order should be followed.

Evaluation of different types of operators◦ The hierarchy is as follows:

1st Arithmetic operators 2nd Comparison operators 3rd logical operators

Evaluation of different types of logical operators ◦ The hierarchy is as follows:

1st NOT 2nd AND 3rd OREx:

5*5+10/5 >40 AND 8<10 OR 7<4

Input 5 numbers. Find the sum, difference and product of the number. Print the answer

Convert a number in degree Fahrenheit (0F) to Celsius (C)

A rectangular table has a length of 60.5 inches and a width of 20.5 inches. Find and print the perimeter.

Conditional statements is one of the vital components in programming. It enables a program to respond in a different manner every time a program is executed depending on the data entered.

The commonly used conditional statements are:◦ If statement◦ If ...then.. Else statements ◦ Select case statements

This is used to evaluate a condition or check a value as “true” or “false”. If the condition is not met, the succeeding statements or set of statements will executed.

SyntaxIf condition

StatementEnd if

Input a color. If the color is blue, display the message “The color is blue”.

Algorithm:

String colorBegin

Input colorIf color= blue

Print “ The color is blue”End If

End

Input a score. If the is 100, display the message “Excellent”

This is used to evaluate a condition or check a value as “true” or “false”. If the condition is not met, the statement or set of statements after will be executed

Syntax:◦ If condition then

Statement 1Else

Statement 2End if

If condition thenStatement(s)

Else if condition 1 thenStatement(s)

Else if condition 2 thenStatement(s)

Else Statement(s)

Input a grade. If the grade is greater than or equal to 75, display the message “You passed the subject”, otherwise display “Study hard”

Input 2 prices and get the total. If the total is more than P500, get 5% of the total, if the total is more than P500 but less than or equal to P1000, get 10% of the total, but if the total is greater than P1000, get 15% of the total. Display the discounted price.

The case statement is similar to the use of the If... Then .. Else statement. It is used when a variable is compared to different values or expressions.

SyntaxSelect Case test expression

Case expressionlist1Statement Block1

Case expressionlist2Statement Block2

End Select

Conduct Grade Equivalent1 – Excellent2 – Very Good3 – Good4 – Satisfactory5 – Needs Improvement

Input a conduct grade and display the equivalent rating

Okay now, start getting busy by doing your first exercise for this module.