programming and coding2
programming and coding2
- 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)
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.
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
- 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
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
Take Note: A declaration statement always starts with the reserved word DECLARE for
Pseudocode and Dim for Visual basic
Sub Main
End Sub
Console.ReadLine - INPUT
Console.WriteLine - OUTPUT
Example:
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
8
Pseudocode
VB
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
End Sub
Sub Main()
Dim sname As String
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
Arithmetic operators
Sub Main()
Dim num1 As Integer
Dim num2 As Integer
Dim answer As Integer
End Sub
10
A program to find area of a rectangle
Sub Main()
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
11