Presentation on theme: "Andrew C. Samuels, Information Technology Specialist Trainer c/o Ministry of Education Mona High School, Kingston, Jamaica 1 Problem Solving Section 2:"— Presentation transcript:
Andrew C. Samuels, Information Technology Specialist Trainer c/o Ministry of Education Mona High School, Kingston, Jamaica 1 Problem Solving Section 2: Obj. 6 CXC IT Syllabus
CXC IT Syllabus Section 2 Obj 2: identify ways of representing algorithms; 1.Psuedocode - is an algorithm that models or resembles the real programming language of a computer. It cannot be executed by the computer. 2.Flowcharts – consists of a set of symbols that are used to represent programming logics. 2
Use of Input Statements Input statements are used to place data inside the computer for the programmer to use. In Psuedocode Algorithm, Read, is used to enter data. For e.g. Write a psuedocode algorithm to input a number Begin Read N END. Write a statement to accept the day, month and year a person is born. Begin Read Day Read Month Read Year END. 3 Begin Read Day, Month, Year END.
Use of Output Statements Output statements are used to get information out of the computer by the program. In Psuedocode Algorithm, Print, is used to display information. For e.g. Write a psuedocode algorithm to print your name. Begin Read Name Print Your name is Name END. Write a statement to display the time. Begin Read Time Print The time is Time END. 4 Information or instructions entered between quotation marks are printed as is.
Use of Output Statements Output statements may also be used when prompting for information. Similarly, Output statements maybe useful to caption. For e.g. Write a psuedocode algorithm prompt the user to enter their first and last name and provide output. Begin Print Enter your first name. Read FName Print Enter your last name. Read Lname Print Your full name is Fname LName END. Write a psuedocode to request the user to enter their age and print it. Begin Print Enter your age. Read Age Print Your age is Age END 5
Use of Assignment Statements The Assignment Operator is. Assignment statements are used to assist in making calculations inside a program. The Assignment statement is used to give a value to a variable. Assignment statements can be also used to change the value of a variable. The Assignment Operator is. Write a psuedocode algorithm to ask the user to input the name of a student, the marks he/she received in a test and the maximum number of marks in the test. Calculate the percentage mark the student receive. Print the information with suitable labels. 6 Print Enter your name. Read Name Print Enter the marks received. Read Marks Print Enter maximum marks in test. Read MaxMarks Percentage Marks/MaxMarks Print The percentage score is Percentage END. Increasing the value of Salary by 2%. Salary Salary * (.02 * Salary) Mathematical Operators used + (Add), - (Subtract), / (Divide), * Multiplication.
Use of Assignment Statements Write a structured algorithm to prompt the user to input the ages of four students. The algorithm should allow the user to input these ages, find the average and print it with suitable label. Write a psuedocode algorithm to ask the user to input the radius of a circle. Calculate the diameter and print with suitable label. 7 Print Enter the ages of four students. Read Age1, Age2, Age3, Age4 Sum Age 1+Age2+Age3+Age4 AvgAge Sum/4 Print The average age is AvgAge END. Print Enter the radius for the circle. Read Rad Diameter Rad * 2 Print The diameter of the circle is Diameter END.
Assignment Statement (contd) Write a structured algorithm that prompts the user to input the number of days in a month. Calculate and print the number of hours in the month appropriately labelled. 8 MaxHours = 24 Print Enter the number of days. Read Days Hours Days * MaxHours Print The number of hours in the month is Hours END. Note how Constants are used for MaxHours as there are a fixed number of days in the month. Write a structured algorithm to prompt the user to enter the side length of a square. Calculate and print the square with an appropriate label. Print Enter the side of a square. Read Side Area Side * Side Print The area is Area END.