1.1K views

Uploaded by HyYiffyPoo

- Pseudocode Examples
- CXC-CSEC Physics - Electricity and Magnetism
- 2014 Guide to Csec Information Technology 1 2
- Csec.information Technology.paper02.Jan2015o
- CSEC Multiple Choice
- IT Revision Questions
- CXC CSEC Information Technology June 2014 P1
- Information Technology csec Jan 2015 p1 with answers
- It Sba
- Csec Physics Manual 2012-15
- CSEC IT MOCK EXAM
- PRE-CSEC Exam 2011 - Solution
- CSEC June 2011 InformationTechnology SBA.ex
- Information Technology Past Papers from 1993 to 1999 with answers
- Pascal Programming
- CSEC Maths Worked Solutions
- May 2012 CSEC Math Exam Solutions
- Cxc Physics June 09 P1
- CSEC Information Technology Paper 2 2014
- CSEC May\June 2011 Information Technology CSEC

You are on page 1of 69

Computer programs finite set of precise instructions

Before program is written we must find a way to solve the

problem

After figuring out how to solve the problem we then

INTRODUCTION

Consider the following: Proceed a mile or so down the

road until you reach the roundabout. Turn left at the roundabout and follow the road until you reach a green house on the right hand side. The Post office is about the 3rd or 4th building on the right after the green house. You cant miss it!

INTRODUCTION

Problem-solving statements/ instructions should be:

Precise Unambiguous Must be in a logical sequence Finite, i.e. terminate after a definite number of steps

what these attributes mean Students should engage students in problem-solving exercises involving everyday problems they can relate to.

Write a recipe for making a cheese sandwich Write instructions to teach your mom how to retrieve voice

Write instructions to give directions to a visitor to get to the

Write instructions to tell a novice how to download music

The design of any computer program involves two phases: The Problem-solving Phase The Implementation Phase Problem-Solving Phase comprises the following steps: 1. Define the problem 2. Find a solution to the problem 3. Evaluate alternative solutions 4. Represent the most efficient solution as an algorithm 5. Test the algorithm for correctness

The problem must first be defined: Ensure that students

Defining the problem is the first step towards finding a

solution

It helps the programmer to understand what is given and

what is required

If the programmer does not fully understand what is

One of the biggest challenges faced in problem-solving is

Defining the program can be accomplished by

1. 2.

What is given (the inputs) The tasks that must be performed (processing)

3.

Define the problem by constructing a defining diagram

A table with three columns which represents the three

E.g. A program is required to read three numbers and

INPUT 3 numbers e.g. Num1, num2, num3 PROCESSING 1. Get 3 numbers 2. Ad numbers together 3. Print total OUTPUT Total

Input refers to the source data provided - easily identified

Output refers to the end result required - keywords are

Processing are the actions must be performed to achieve

the required output - it answers the question: What must I do with the inputs in order to produce the desired result?

In the defining diagram, the actions must be listed in a

All necessary actions must be explicitly stated

Its simply the actions that must be done in order to solve the problem

Note that in some cases the input, processing and output

PROBLEM 2

E.g. of problem not clearly stated to facilitate student

identification of the problem: Given three integers representing the age of three boys respectively, write a solution to find their average age and also determine the age of the oldest boy.

This problem statement could have been stated more

precisely to read: Given three integers A, B, C, representing the age of three boys respectively, write a solution to find and display their average age as well as the age of the eldest boy.

DEFINING DIAGRAM

multiple actions:

INPUT 3 integers Say age1, age2, age3 PROCESSING 1. Read/accept/get 3 integers 2. Find the average of the three integers 3. Find the highest age 4. Print the average, highest age OUTPUT Average-age Highest-age

PROBLEM 3

the local sales tax and the dealers percentage mark-up. Assuming that the dealers mark-up is 10 percent of the wholesale cost and the sales tax is 6 percent, design an algorithm to read a car ID (an integer value) and the

wholesale cost of the car (a real value) and print the car

ID and the cost to the consumer.

PROBLEM 3

Here, input and output data are clearly stated. To

determine the processing steps we may ask What should I do with wholesale cost in order to find the cost to the consumer?

INPUT PROCESSING OUTPUT Car-ID Consumer-Cost

Car-ID, Wholesale-cost 1. Read/get wholesale-cost 2. Calculate dealers markup 3. Calculate the sales tax 4. Find the sum of the wholesale-cost, the dealers mark-up and the sales tax 5. Print the results

Many real-world programming problems are not always

precise

Initial descriptions are often vague, and ambiguous

Also, some information may be implicit in the problem

statement and therefore should be taken into account when defining the problem

Have students evaluate several problem statements, ranging from simple to complex, some precise, some ambiguous, lacking pertinent information.

Here are some examples of imprecise problem statements:

#4: Write a program to print a list of all the employees

#5: Write a program that reads a file that contains

information on the height, weight and age of 100 children. The program should print the names of all the children who are overweight.

Now that we have defined the problem, we know what we need to do. We must now figure out how to do it.

A problem can have many different solutions

Once a solution is found, it can then be reviewed to see

The first approach in deriving a solution to a problem is to

Problem #6: Find and print the average of three numbers Define the problem

INPUT PROCESSING OUTPUT

average

manually

Having completed a manual solution to the problem, the

next step is to write your solution as a sequence of instructions Initial solution Get the first number, call it num1 Get the second number, call it num2 Get the third number, call it num3 Add num1 + num2 + num3 Divide result by 3 Print result Stop

In our solution to problem #6, we did not tell the computer where to put the result of the add operation. The result must be stored somewhere so it can be accessed later.

Grandmas fluffy pancakes: Method: Sift flour in mixing bowl ... Melt the butter in a frying pan ... Pour batter into a bowl ... Just as we need containers to hold or store ingredients, likewise, in computation, we need something to store or hold the values we manipulate

There are many memory locations, so in order to keep

track of where our values are stored we need to place a label or identifier on a particular memory location.

The label or identifier is called a variable. A variable is a symbolic name assigned to a memory

variable or an identifier for each number, so that we can refer to (access) it later.

We need to tell the computer where to put the result of the

Add num1 + num2 + num3 storing in Sum

Likewise, we must address a similar issue in the last two statements where we stated, Divide result by 3 Print result

Computations are performed by the ALU, part of the CPU

and results are temporarily stored in registers within the cpu These values must be stored in memory locations if they are to be accessed later

The word variable is derived from the verb to vary. This

means that the value stored in a particular location can change from time to time, although the label remains the same.

When new values are placed into previously assigned

Memory locations

Num 1 Variables Num 2 Num 3 5 3 25

We can now revise the initial solution to include the new variables called sum and average

Get three numbers, say num1, num2, num3 Add num1, num2, num3, storing in sum Divide sum by 3, storing in average Print average

Its good practice to choose variable names that reflect the

It helps the programmer as well as the reader to understand

Its important that students grasp the concept of variables

The aim is to arrive at the most efficient solution

The programmer must evaluate all feasible alternatives

Points to consider when developing alternative solutions. Can the result be derived differently?

Can the solution be made more general? Would it work if

Can the solution be used for another problem? E.g. Average

Can the number of steps be reduced and still maintain the

logic? Can it be made more robust? What would happen if incorrect data is entered?

REDUCING THE NUMBER OF STATEMENTS We can reduce the number of statements by combining two arithmetic statements into one: 1. Add num1, num2, num3 can be written as

(the variable sum is assigned the value of num1 plus num2 plus num3)

2.

Divide sum by 3 storing in average can be written Average = sum/3 We can combine the two statements to produce: Average = sum/3

Get num1, num2, num3 Average = (num1 + num2 num3)/3 Print Average Stop Option 1 Get num1, num2, num3 Sum = num1 + num2 + num3 Average = sum/3 Print Average Stop

The most efficient solution should have the following attributes: Should be maintainable Should be memory efficient Should be robust

INITIALIZATION OF VARIABLES

This is called initialization E.g. Count = 0

WHAT IS AN ALGORITHM?

At this time, we can now introduce the term algorithm. An algorithm is a sequence of precise instructions for solving a problem in a finite number of steps. Properties:

Algorithms must: be precise,

be unambiguous,

be logically sequenced, give the correct solution an all cases, and eventually end.

WHAT IS AN ALGORITHM?

Algorithmic structure

Header : Algorithms name or title

Declaration : Brief description of algorithm and variables used. i.e. A statement of purpose as well as the initialization of variables Body : Sequence of steps

ALGORITHMIC STRUCTURE

Problem: Write an algorithm that prompts a student to enter his/her name and age, accepts the name and age and then display a welcoming message on the screen such as hello Michael! You are 16 years old!

Write the algorithm identifying the header, declaration, body and terminator.

ALGORITHMIC STRUCTURE

Algorithm Student data This algorithm displays a students name and age on the screen. Start Display Enter your name: Accept Name Display Enter your age: Accept Age Display Hello, Name Display You are, Age, years old Stop {Header} {declaration}

{Body}

{Terminator}

Pseudocode is more concise, closely resembles

programming language

Flowchart gives good view of the structure and flow of

the logic

Beginners tend to follow the logic easier when using

Longer, more complex solutions are better represented

using pseudocode.

Usage is a matter of preference for experienced

programmers

Students should be asked to use both flowcharts as well as

Flowcharts must use special geometrical objects that

Input/Output

Processing/ Assignment

Decision

Start/ Stop

Start

Get num1, num2, num3 Average Stop

Average (num1+num2+num3)/3 Start

Print Average

Print Average

Stop

CONDITIONAL/SELECTION STRUCTURES

Selection (decision) The IFTHEN selection statement Syntax: IF (expression) THEN {Statement (s)}

This construct is used when no action needs to be performed if the expression returns false.

SELECTION STRUCTURES

This requires only that the expression Well done be printed should the student score 50 marks or more. No action is intended should the mark be less than 50

SELECTION STRUCTURES

IF THEN ELSE construct syntax:

IF (expression) THEN

{Statements} executed only if condition is TRUE ELSE {Statements} executed only if condition is FALSE ENDIF

Only one group of statements could be executed each time

SELECTION STRUCTURES

Get Mark IF Mark >= 50 THEN PRINT Well done ELSE PRINT Must do better ENDIF Stop

Well done will be

If the mark is less than 50

SELECTION STRUCTURES

A worker in a clothing factory is paid an additional incentive according to the amount of shirts she folds. The basic salary is $300.00 per week. Should the worker fold 500 or more shirts per week, an additional 15%, is added to her basic salary. If the worker folds less than 500 shirts however, she is paid just the

basic salary.

Write an algorithm to determine and print the salary of the worker.

SELECTION STRUCTURES

numerator and the second the denominator. If the second is equal to zero print Cannot divide by 0. Otherwise

divide the first number by the second and print the answer.

SELECTION STRUCTURES

A teacher has realized an error in his marking of students

scripts. He has therefore decided to credit all students who got 55 marks and under with an additional 10 marks. Those

15 marks. Write an algorithm to accept the mark from a student in a class. Calculate and print the students adjusted mark.

SELECTION STRUCTURES

A store offers customers a discount of 15% if the cost of

any item purchased is equal to or exceeds $200.00. Should the cost be less than $200.00 however, then a 5% discount is applied. Write an algorithm to accept the cost of an item. Apply the relevant discount and

REPETITION STRUCTURES

Repetition or Loop or Iteration structures allow statements

There are three repetition constructs:

1.

FOR Loop

- counted loop

2.

3.

WHILE Loop - conditional loop

REPETITION STRUCTURES

The FOR loop construct syntax: FOR <counter> = <start value> TO <end value> DO {Statements} ENDFOR e.g. FOR X = 1 to 10 DO {Statements to be executed} ENDFOR

REPETITION STRUCTURES

The FOR loop is used when the required number of

The statements are repeated as long as the value of the

identifier specified by the <counter> element does not exceed the value specified by <end>. A comparison is made each time the loop iterates to check whether the <end> is exceeded. If it is not then the counter value is incremented by one (the default step value)

REPETITION STRUCTURES

The 12 workers employed in the folding section of a

clothing factory are each paid a basic salary of $500.00 per week. An incentive is offered according to the amount of shirts folded. Should a worker fold 600 or more shirts per week a bonus of 20%, is added to his/her basic salary. If a worker does not fold as much as 600 shirts however, he/she is paid just the basic salary. Write an algorithm to determine and print the salary of each worker.

REPETITION STRUCTURES

A teacher has realized an error in his marking after having marked all his students scripts. He has therefore decided to credit all students

who got less than 60 with an additional 5 marks. Those who got 60 and

over would be credited with an additional 15 marks. Write an algorithm to accept the initial marks obtained by the 20 students in the class. Calculate and print each students adjusted mark. The teacher would like to determine the class average after the marks are credited. Should the class average exceed 60, Instructions well received should be printed. Otherwise, Reconsider Teaching Methods should be printed.

REPETITION STRUCTURES

A store offers customers a discount of 15% if the total cost of items purchased is equals or exceeds $400.00. Should the total be less than $400.00 then 5% discount

items. Calculate and print the total cost. Apply the relevant discount and calculate and print the net cost (total cost discount).

The WHILE Loop construct syntax: INPUT Value WHILE (expression) Do {statements} executed if Boolean argument in logical expression is true INPUT value to be tested ENDWHILE

REPETITION STRUCTURES

WHILE Loop

If the condition returns true, the statement(s) that follow

DO will be executed.

If the condition returns false, execution of the WHILE

statement is stopped. It is possible for the loop never to be executed if the initial input renders the condition is to be proven false.

REPETITION STRUCTURES

WHILE Loop

condition in the argument expression remains true. It is terminated only when the condition returns false.

integers and find the average of all numbers read. The program should be terminated if the sentinel value 999 is entered.

Write an algorithm to accept an unspecified amount of

integers. Calculate and print the sum of the numbers entered. The algorithm should also determine and print the highest number entered. The process should be terminated if the number entered exceeds 1000.

Write an algorithm to accept the price of items purchased

at a supermarket. The entry of prices should continue as long as the price entered is not $101.00. Calculate and print the total cost of items purchased.

Repeat Loop construct syntax: REPEAT {statements to be executed} UNTIL (Boolean expression)

The repeat loop is used to iterate a sequence of events until

a specific condition becomes true. The statements in the body of a Repeat loop are executed at least once, because the test of the condition takes place at the end of the loop.

TRACE TABLES

State what is printed when the following algorithm is executed.

FOR X = 1 to 3 DO FOR Y = 1 to 3 DO Product = Y * X Print Product ENDFOR ENDFOR

TRACE TABLES

Whats printed by the following Algorithm? AMOUNT = 2 G=4 WHILE AMOUNT < 50 Do G = G*2 AMOUNT = AMOUNT + G Print AMOUNT, G ENDWHILE

TRACE TABLES

INPUT A,B,C A=B+C B=AC C= A+B IF A > B THEN C=AB ELSE C=BA ENDIF Print A,B,C

State what is printed by the algorithm above when the following data is input:

(i) (ii) 5, 7, 9 9, -7, 5

TRACE TABLES

Complete the trace table based on the following algorithm.

B=2 C=4 Total = 3 WHILE B <= 45 Do B=B+C C=C+B Total = Total + C ENDWHILE Print Total

B 2

C 4

TOTAL 3

What is an Array?

Accessing the Elements in an Array Initializing Arrays Reading Values into an Array Displaying Array Values

Traversing Arrays

Manipulating Arrays

What is Top-Down Design? Hierarchy Charts Sub-dividing a Problem into Modules Steps in Modularization Representing Modules in Pseudocode and Flowcharts

Advantages of Top-Down Design Method

Translating Algorithms to Specific Programming Language Structure of a Pascal Program Pascal in a Nutshell

Summary

Types of Errors Debugging

THANK YOU

For your attention

- Pseudocode ExamplesUploaded byMukesh Agarwal
- CXC-CSEC Physics - Electricity and MagnetismUploaded bydela2
- 2014 Guide to Csec Information Technology 1 2Uploaded byDanielEvans
- Csec.information Technology.paper02.Jan2015oUploaded byakintl0
- CSEC Multiple ChoiceUploaded byCrystal D.
- IT Revision QuestionsUploaded byPatricia Ĉutie-Lil Princesŝ Green
- CXC CSEC Information Technology June 2014 P1Uploaded byAnonymous19
- Information Technology csec Jan 2015 p1 with answersUploaded byVishala
- It SbaUploaded byKaheem Koolkidz Whittingham
- Csec Physics Manual 2012-15Uploaded byJerrord Thomas
- CSEC IT MOCK EXAMUploaded byVidur Talreja
- PRE-CSEC Exam 2011 - SolutionUploaded byLatoya Anderson
- CSEC June 2011 InformationTechnology SBA.exUploaded byVeneisiaTomlinson
- Information Technology Past Papers from 1993 to 1999 with answersUploaded bySwaggaMax Hylton
- Pascal ProgrammingUploaded byDorelia Patrascu
- CSEC Maths Worked SolutionsUploaded bySeon Hamer
- May 2012 CSEC Math Exam SolutionsUploaded byCarl Agape Davis
- Cxc Physics June 09 P1Uploaded byJaleel James
- CSEC Information Technology Paper 2 2014Uploaded bysmartkid167
- CSEC May\June 2011 Information Technology CSECUploaded byHarry MP Lee-Quee
- Structure for Writing Sba Labs for PhysicsUploaded byDelson Alexander
- English Revision BookletUploaded byBlack Ink Tutorials & Services
- CSEC Religious EducationUploaded byCrystal D.
- it SBAUploaded byocamp2007
- cxc Physics labUploaded byMiguel Roman Reloaded Kerr
- CXC CSEC Information Technology 2016 June P1Uploaded byAnonymous19
- Physics Csec - Cpo WorkbookUploaded bysourz18
- IT SBA 2016-2017Uploaded byMelvin Salfarlie

- Factors Leading to Eutrophication.Uploaded byHyYiffyPoo
- Factors Leading to Eutrophication.Uploaded byHyYiffyPoo
- Factors Leading to Eutrophication.Uploaded byHyYiffyPoo
- RheumatismUploaded byHyYiffyPoo
- RheumatismUploaded byHyYiffyPoo
- RheumatismUploaded byHyYiffyPoo
- Academic Writing Sentence OutlineUploaded byHyYiffyPoo
- RheumatismUploaded byHyYiffyPoo
- RheumatismUploaded byHyYiffyPoo
- RheumatismUploaded byHyYiffyPoo
- Facial BonesUploaded byHyYiffyPoo

- Prophetic Revelation Discerning and InterpretingUploaded bySky Sage
- Law. Sources of Modern LawUploaded byzelvero
- Aleister Crowley the Soul of the DesertUploaded byCristian Terran
- 3304166 International HRM and TraininggDevelopmentUploaded byHungor22
- The Cambridge Companion to Weber - Stephen TurnerUploaded bybeatrichess
- Darren Ambrose - Levinas, Illeity and the Persistence of SkepticismUploaded byDarren Ambrose
- Scale of Community ArchitectureUploaded byKathlynJoySalazar
- Djinn, Dawoud, And RitualsUploaded bysalineday1604
- Manhattan music curriculum projectUploaded byDaniel Torres Beltran
- Communicative ApproachUploaded byapi-9711295
- USHUL Madzhab MalikiUploaded byabdul rohman
- 657186Uploaded byVignesh Ramakrishnan
- Tafsir Surah Al Alaq- Tayseer al-Kareem ar-Rahman - Shaykh 'Abdur Rahman as Sa'diUploaded byMountainofknowledge
- 03 5 Desperate Zindeeq - MADkhalis [Saudi Salafi] (Notes) - AuthenticTauheed PublicationsUploaded byAuthenticTauheed Publications
- wetteric_QFT1Uploaded bySourav Sen Choudhury
- Francesco Saverio SalfiUploaded byManuel
- The Benefits, Obstacles and Problems of Practical Bim ImplementationUploaded byEleazar Mendez
- Ancient Egyptian Concept of the SoulUploaded by文光
- 3D Virtual Treatment Planning of Orthognathic Surgery a Step-By-Step Approach for Orthodontists and SurgeonsUploaded byAbad Salcedo
- Primarily Obsessional OCDUploaded byRalphie_Ball
- Albert C. Sundberg, Jr. - 'Canon Muratori' a Fourth Century ListUploaded byVetusta Maiestas
- Vastu Purusha Space GridUploaded byGaurav Pahuja
- Collaborative Research in Economics the Wisdom of Working TogetherUploaded byMario Mari
- Ayn Rand Objectivist EpistemologyUploaded bycalirby
- Values DefinedUploaded byRian Natoza Grande
- Corey Chapter 9Uploaded byCandice Ramoudh
- Functional Morphology and Feeding Mechanics of BillfishesUploaded byplaness
- Philippine Poems.pdfUploaded bywebdmdrleo
- A Word is Worth a Thousand Pictures A Systemic Functional and MuUploaded bym_linguist
- Lecture 1 Introduction to Business EthicsUploaded byShehroon Ahmad