Sei sulla pagina 1di 8 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.

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

END.

Write a statement to accept the day, month and year a person is born.

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.

Information or instructions entered between quotation marks are printed as is.

Write a statement to display the time.

Begin Read Time Print “The time is “ Time END.

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.

Write a psuedocode to request the user to enter their age and print it.

Use of Assignment Statements

Mathematical Operators used + (Add), - (Subtract), / (Divide), * Multiplication. 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

Increasing the value of Salary by

2%.

Salary Salary * (.02 * Salary)

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

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.

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 “The diameter of the circle is “

Diameter

END.

Assignment Statement (cont’d)

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