Cambridge IGCSE & O Level Computer Science Programming Book for Microsoft Visual Basic Sample

Page 47

We are working with Cambridge Assessment International Education towards endorsement of this title. Any references or material related to answers, grades, papers or examinations are based on the opinion of the author(s). 2  Programming constructs

Pseudocode follows a number of underlying principles: •

Use capital letters for keywords close to those used in programming languages.

Use lowercase letters for natural language descriptions.

Use indentation to show the start and end of code statements, primarily when using selection and iteration.

Pseudocode should always include comments to explain the logic of the algorithm. A comment in pseudocode is defined by starting with the symbol //

Pseudocode example

LE

One advantage of learning to program using Visual Basic is that the actual coding language is structured in a similar way to natural language and therefore closely resembles pseudocode. Visual Basic also automatically indents instructions where appropriate similar to the approach that should be adopted when writing pseudocode.

P

This pseudocode is for an algorithm that accepts the input of two numbers. These values are added together and the result is stored in a memory area called Answer. The value in Answer is then displayed to the user. (In Chapter 3, you will learn that this memory area is known as a variable.)

M

// Entering the values INPUT Number1 INPUT Number2 // Calculate the addition and store in Answer Answer  Number1 + Number2 // Output the value in Answer OUTPUT Answer

NOTE: Observe the use of ← to show the passing of values. This is distinct from the use of the equals symbol (=), which is used to indicate a comparison of two values. (Visual Basic does not have the ← symbol and uses the = symbol in both situations.)

A

2.5 Use of flowcharts and pseudocode in programming

S

Because of the universal nature of flowcharts and pseudocode, they are used extensively in the design of computer programs. The aim of this book is to help you to learn to design effective systems using the programming language Visual Basic. The following chapters make use of flowcharts and pseudocode to define the logic of systems, before moving on to specific Visual Basic-coded solutions. Learning how to detail the logic of programs through the use of these design techniques will be a crucial step in your preparation for using the languages of the future. Language syntax is likely to change in the future but the need for effective logical and computational thinking will remain a constant.

35 Original material © Cambridge University Press 2021. This material is not final and is subject to further changes prior to publication.


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.