Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
8 views

programming and coding2

Uploaded by

mbayiwaiphithule
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

programming and coding2

Uploaded by

mbayiwaiphithule
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Credentials to join network

PROGRAMMING / CODING SIMPLIFIED Network Name : workshop


Password : code2024
Computer programming and coding

- is the composition of sequences/steps of instructions, called programs, that computers can


follow to perform tasks.
- It involves designing and implementing algorithms, step-by-step specifications of procedures,
- the writing of code or program is done using programming languages like Visual Basic (VB), Java,
Python, C++, etc.
- For purposes of our curriculum, we are going to learn how to write computer codes using Visual
Basic (VB), as part of programming
- Coding is a section of programming, because there is more to programming than just writing a
code,

- Programming - Starts with identifying a problem that needs a programming solution, and
identifying steps that can be taken to get a solution for the identified problem.

- There are several other steps that must be taken in carrying out programming, especially for
large commercial programs.

- These steps make up what is called the “Software Development Life Cycle” or “Program
Development Life Cycle” which can be summarised in general as shown by the 3 diagrams below

or or

1
Some of these stages can be combined, or named using different words, or shown using a different
diagram. For purpose of our syllabus expectations we will consider 5 stages which are: analysis, design,
coding, testing and maintenance.

Analysis
- After identifying a problem that requires a solution, the problem is clearly defined to understand
what is needed to get a solution.
- This is called the ‘requirements specification’, where the bigger problem is broken down into
smaller sections to further understand how best to get to a solution.
- Abstraction and decomposition tools are used in this stage.
- Systems Analysis is done by a Systems Analyst, who has trained to do the analysis.

Design

- Systems Design is the process of defining the hardware architecture, components, modules,
interfaces, and data for a system to satisfy requirements specified during the analysis stage.
- This stage is used to show how the program should be developed before the programmer is
engaged.
- all the tasks that need to be completed, how each task is to be performed and how the tasks work
together are shown here.
- This is formally documented using different algorithm options like Structured English, flowcharts
and pseudocode.
- (An algorithm is a set of steps for solving a known problem)

Coding and iterative testing


- This involves the development or creation of a program or a set of programs called modules.
- Each module of the program is written using a suitable programming language e.g Visual Basic
(VB), Java, Python, C++, etc
- After the program or program modules are written, testing is done to see if it works in solving the
identified problem, according to the specified design.
- Iterative testing means that tests for each module are conducted, the code is amended if
necessary, and tests are repeated until the module performs as required.
- Computer Programmers or coders develop the programs or computer codes. They have the
knowledge and experience in one or more of the programming languages.
Testing
- The completed program or set of programs is run many times with different sets of test data.
- This ensures that all the tasks completed work together as specified in the program design.

Maintenance
- After the program passes the testing, it is implemented and put into use.
- During the course of usage, there is often need to continuously carry out some maintenance now
and again to deal with problems that may be encountered with the program.
- Such maintenance may require updates, upgrades or complete overhaul changes, then the whole
SDLC starts all over again

2
Example of an Identified Problem:

Write /Show algorithms for a program that adds two numbers and gives out the answer.

Example of answers for the 3 different algorithm approaches

Flowchart algorithm example for adding two numbers


Structured English algorithm for adding two numbers
1. Start: The beginning of the program.
2. ReadNum1: Read the first number from the user.
3. ReadNum2: Read the second number from the
user.
4. Add: Calculate the sum of the two input
numbers.
5. DisplaySum: Display the calculated sum to the
user.
6. End: The program ends after displaying the
sum.

Pseudocode algorithm example for adding 2 numbers :

Declare variables num1, num2 and sum num1 = Read input from

user num2 = Read input from user sum = num1 + num2 Display sum

3
Flowchart Symbols

4
PROGRAMMING BASICS

There are five basic constructs to use and understand when developing a program: (constructs are ideas
in programming). So programming is centred around these constructs or ideas.

● data use – variables, constants and arrays


● sequence – order of steps in a task
● selection – choosing a path through a program
● iteration – repetition of a sequence of steps in a program
● operator use – arithmetic for calculations, logical and Boolean for decisions.

DATA USE
- Data used in a program can be in the form of a variable or a constant
- There are different types of data that can be used in a program
-
Variables and constants
- In a program, any data used can have a fixed value that does not change while the program is
running.
- A variable in a computer program is a named data store than contains a value - A variable value
may change (vary) during the execution of a program.
- Before variables can be used in any program they have to be declared, (announced or made
known) and the data type for that variable has to be stated.

- A constant in a computer program is a named data store than contains a value that does not
change during the execution of a program. Eg PI = 3.142 declared as ConstPi = 3.142

Basic data types


In order for a computer system to process and store data effectively, different kinds of data are formally
classified as of different types. This enables:

● data to be stored in an appropriate way, for example, as numbers or as characters


● data to be manipulated effectively, for example, numbers with mathematical operators and
characters with concatenation
● automatic validation in some cases.

The basic data types you will need to use for IGCSE Computer Science are:

● integer – a positive or negative whole number that can be used with mathematical operators
● real – a positive or negative number with a fractional part. Real numbers can be used with
mathematical operators
● char – a variable or constant that is a single character
● string – a variable or constant that is several characters in length. Strings vary in length and may
even have no characters (known as an empty string);
○ the characters can be letters and/or digits and/or any other printable symbol
○ A string character is shown inside quotation marks e.g. “mary”, “125”, “ $$#%&”, “ ”
○ (If a number is stored as a string then it cannot be used in calculations.)
● Boolean – a variable or constant that can have only two possible values e.g TRUE or FALSE.

5
Exercise 1 : Data Types
State the data type for the following set of data
a) Yes or No b) 5.25 c) mary$$$ d) 151 e) twenty f) z g) -15

Here are some guidelines (Dos and don’ts for naming variables)
- Variable names are more meaningful if they use sensible text or words.
- Use variable names that are meaningful and close to what is being mentioned in the program,
even if they are abbreviations try to have them meaningful e.g Num1, Num2, instead of
Number1, Number1
- Do not use numbers only in figure form for a variable name, or at the start of a variable name,
but a number can be added at the end of a variable nam, eg or Num1
- Do not use spaces in variable naming
- If two words make up a chosen variable name, then the first letter for each work can be
capitalised eg. StudentName
- Do not use any special characters like $, !, # at the start of variable names.

6
Accessing VB compiler online

click

buttons

Sample

Program

Editor

CLICK
RUNNING A CODE RUN

7
Results
window

IF YOUR SCREEN IS SMALL SCROLL BELOW *


NAMING AND DECLARATION OF VARIABLES

Take Note: A declaration statement always starts with the reserved word DECLARE for
Pseudocode and Dim for Visual basic

Sub Main

End Sub

Dim – Declaration of variables

Console.ReadLine - INPUT

Console.WriteLine - OUTPUT

Example:

1. Declare a variable called number of integer type Answer:


Pseudocode: DECLARE Num: Integer
Visual basic: Dim num as integer

2. Declare 3 variable names called student of string type


Answer:
Pseudocode: DECLARE Student1, Student2, Student3: string
Visual basic: Dim student1, student2, student3 as string

Exercise 2 : Declaring Variables

1. A programmer used the following variable names state whether they are correct or not by
stating valid or invalid, giving a reason.

a) 44Age b) Studentname
c) Car number d) Color
e) $money f) 123

2. Write a statement using Visual Basic to accomplish the following.


a) Declare a variable called number of integer data type
b) Declare a variable called name of string data type
c) Declare a variable called fees of real data type

8
Pseudocode

VB

Input and output

For a program to be useful, the user needs to know what they are expected to input, so each input needs
to be accompanied by a prompt stating the input required. A prompt is a message or text displayed to
the user asking for an input.

Example

Example 1 for input / output


Sub Main()

Console.WriteLine("WELCOME TO DOMINICAN CONVENT")


Console.WriteLine("A GOOD SCHOOL")
Console.ReadKey()

End Sub

Sub Main()
Dim sname As String

Console.WriteLine("WELCOME TO DOMINICAN CONVENT")


Console.WriteLine("A GOOD SCHOOL")
Console.WriteLine("Please enter your name") sname
= Console.ReadLine
Console.WriteLine("Your name is " & sname)
Console.ReadKey()

End Sub

9
Example 2 for input/output
Sub Main()
Dim sname As String
Dim age As Integer
Console.WriteLine("WELCOME TO DOMINICAN CONVENT")
Console.WriteLine("A GOOD SCHOOL")
Console.WriteLine("Please enter your name") sname
= Console.ReadLine
Console.WriteLine("Please enter your age")
age = Console.ReadLine
Console.WriteLine("Your name is " & sname)
Console.WriteLine("Your age is " & age)
Console.ReadKey()

End Sub

Practice Exercise 3 : Input / Output

1. a) Write a program that will


i) display the words “Programming is Fun”
ii) ask you to enter your name iii) Ask
you to enter your class iv) display
your name and class
v) Display the words “Have Fun” Yourname

b) Draw a flowchart for the program above

Arithmetic operators

Examples of programs using arithmetic operators:

1. A program to add two numbers

Sub Main()
Dim num1 As Integer
Dim num2 As Integer
Dim answer As Integer

Console.WriteLine("enter first number")


num1 = Console.ReadLine
Console.WriteLine("enter second number")
num2 = Console.ReadLine answer = num1 +
num2
Console.WriteLine("Your answer is " & answer)
Console.ReadKey()

End Sub

10
A program to find area of a rectangle

Sub Main()

Dim length As Integer


Dim width As Integer
Dim area As Integer

Console.WriteLine("enter length")
length = Console.ReadLine
Console.WriteLine("enter width")
width = Console.ReadLine area =
length * width
Console.WriteLine("Your area is " & area)
Console.ReadKey()

End Sub

Practice Exercises

a) Write a program to find volume of a rectangular prism


b) Write a program to find area of triangle
c) Write a program to find area of Square
d) Write a program to find the product of 3 numbers entered by the user

11

You might also like