CP1020 University of Wolverhampton - Steve Garner and Ian Coulson1 Week 1 - Principles of...
-
date post
21-Dec-2015 -
Category
Documents
-
view
213 -
download
0
Transcript of CP1020 University of Wolverhampton - Steve Garner and Ian Coulson1 Week 1 - Principles of...
CP1020 University of Wolverhampton - Steve Garner and Ian Coulson
1
Week 1 - Principles of programming
Welcome from the Presenters Steve Garner
and Dr Ian Coulson
CP1020 University of Wolverhampton - Steve Garner and Ian Coulson
2
Essential information [1]
The module is a means to learn programming principles
Quick Basic is a language to do this -available on most machines which have DOS, Windows or NT
We assume you know NOTHING about programming a computer
CP1020 University of Wolverhampton - Steve Garner and Ian Coulson
3
Essential Information [2]
Module continually assessed
1 workshop exercises weeks 2 to 11 - 40%
2 Assignment 1 week 5 - 35%Assignment 2 week 12 - 25%
You must PASS BOTH of these components
1 hour lecture, 3 hour workshop
CP1020 University of Wolverhampton - Steve Garner and Ian Coulson
4
Essential information [3]
You must attend ALL lectures, workshops and work in study time
To learn this subject you must actually do the practical work, (like riding a bike)!
You must have the course book - QBasic 2nd ed. - Bauman and Mandell 0314206590
CP1020 University of Wolverhampton - Steve Garner and Ian Coulson
5
Principles of computingComputer hardware consists of several
fundamental parts - monitor, system and keyboard
A Computer programme is set of instructions that tells the computer what to do. Written in English and interpreted into the computers working language (Binary), and then executed.
It is too difficult for humans to work in computer language directly !
CP1020 University of Wolverhampton - Steve Garner and Ian Coulson
6
How to tackle a problem
We will now look at how we will tackle a real problem
we will go through the steps needed to produce a working program
CP1020 University of Wolverhampton - Steve Garner and Ian Coulson
7
Where to startWhy programme ?
All computers require a program in order to work. i.e. Word processing package has been written using a programming language.
First… look at the thing we are trying to get the computer to do.i.e. add two numbers
To produce the program we must follow a series of steps
CP1020 University of Wolverhampton - Steve Garner and Ian Coulson
8
The Steps (it’s all down hill)
Program
Problem
Analysis & Design
Testing
Document
Review Solution
Start
CP1020 University of Wolverhampton - Steve Garner and Ian Coulson
9
Problem - Requirements and Specification
Develop a full understanding of the problemCan be difficult to do:
Users do not know what they want!Users keep changing their minds!
Once the problem is understood, a Program Specification can be produced
This specification will summarise the problem, and act as the agreement of what the developers must produce for the users
CP1020 University of Wolverhampton - Steve Garner and Ian Coulson
10
Analysis & Design [1]
Once we fully understand the problem, then we can attempt to design a solution.
Probably the most important stage of the process as a good design will greatly simplify later steps
Will involve looking at: Input data and corresponding output data What processing is involved
CP1020 University of Wolverhampton - Steve Garner and Ian Coulson
11
Analysis & Design [2]
There are many design techniques used, we will use what is known as pseudo code simply write down the steps in words -
known as pseudo code
CP1020 University of Wolverhampton - Steve Garner and Ian Coulson
12
Testing
We must test the design to ensure it gives the correct answers.
By using sample data and applying the pseudo code steps to it, we can prove the design works.
CP1020 University of Wolverhampton - Steve Garner and Ian Coulson
13
Program or Coding
The design and testing must be complete before this stage
You should know what you want to achieve before beginning to code it!
It should now be quite straightforward to implement our designs in code
CP1020 University of Wolverhampton - Steve Garner and Ian Coulson
14
Document
If anyone else needs to look at or run your program it will need DOCUMENTING
What the problem isHow did you design it?How did you test it?What sort of data does it use?What does each line of code do?How do you run it?
CP1020 University of Wolverhampton - Steve Garner and Ian Coulson
15
An example problem
We wish to design and code a program that will convert a measurement in kilometres to it’s equivalent in miles - write down the steps needed in the program
We will set the constraint that input of the number of Kilometres will be from the keyboard, and the result displayed in miles on the screen
CP1020 University of Wolverhampton - Steve Garner and Ian Coulson
16
Analysis and Design
a. Read the Problemb. Read it again!c. Do it on paper
test datatest algorithmscheck results
d. Produce Design
CP1020 University of Wolverhampton - Steve Garner and Ian Coulson
17
a. Read The Problem
a. Read the Specification - Understandable - OK
b. Read it again Identify the purpose of program :-
To calculate the number of kilometres equivalent to a given number of miles
CP1020 University of Wolverhampton - Steve Garner and Ian Coulson
18
c. Do it on Paper
c. Do it on paper A typical number of kilometres inputted
may be 3. the answer should be 1.86 miles
as 1 mile is equal to 1.61 km
CP1020 University of Wolverhampton - Steve Garner and Ian Coulson
19
Output to be displayed (with suitable instructions ):
Enter the number of miles : 3 Users input
There are 1.86 miles in 3 kilometres
Screen output
CP1020 University of Wolverhampton - Steve Garner and Ian Coulson
20
Prepare Design [1]
The first simple design, in pseudo code, would be: 1. enter number of km. 2. Calculate miles. 3. Display the answer.
These steps can be broken down further
CP1020 University of Wolverhampton - Steve Garner and Ian Coulson
21
Prepare Design [2]
New, more detailed, design:1. Get number of km
1.1 Prompt user to enter the number of km 1.2 Read in the km from the keyboard
2. Calculate miles 2.1 divide km by number of km in one mile
3. Display the number of miles 3.1 Display number of miles with corresponding
message
CP1020 University of Wolverhampton - Steve Garner and Ian Coulson
22
The solution - Prepare code
REM program : to convert miles to kilometresREM written by : Ian CoulsonREM date written: 15/9/98
DIM Km AS SINGLE ‘Create variablesDIM Miles AS SINGLE
CLS ‘this will clear the screenPRINT “This program converts km to miles.” ‘ message
INPUT “Enter the number of km to be converted; “, km
LET Miles = km / 1.61 ‘calculation
PRINT “There are”; Miles; “miles in”; km; “kilometres.” END
CP1020 University of Wolverhampton - Steve Garner and Ian Coulson
23
Using Print statements
Your first steps in learning to programme is usually to display a suitable message on the screen
The keyword PRINT in Qbasic is an instruction to display something on the screen.
Here is the way it works
CP1020 University of Wolverhampton - Steve Garner and Ian Coulson
24
Using the print statement
The Print statement has the format
PRINT “This is the text I want displayed on the screen”
Use the Print keyword
Enclose the text to bedisplayed in quotation marks
This is the text I want displayed on the screen
Resultingoutput on the screen
CP1020 University of Wolverhampton - Steve Garner and Ian Coulson
25
Printing on the screenQbasic divides the screen into 80 columns
and 25 rows.
25 rows
80 columnsQbasic has a number of mechanisms to arrange where on the screen you wish to print informationHave a look at the following examples
CP1020 University of Wolverhampton - Steve Garner and Ian Coulson
26
Print formatting
PRINT “This is the first thing printed ”PRINT “Next thing printed”
This is the first thing printedNext thing printed
Each print statement causes a new row to be used
CP1020 University of Wolverhampton - Steve Garner and Ian Coulson
27
Print formatting - using the ; character
PRINT “This is the first thing printed ”;PRINT “Next thing printed”
This is the first thing printedNext thing printed
The ; causes the next string to be printed starting in the next column on the same line
CP1020 University of Wolverhampton - Steve Garner and Ian Coulson
28
Print formatting using the , character
PRINT “This is the first thing printed ”,PRINT “Next thing printed”
The , causes the next string to be printed in the next available print zone
This is the first thing printed Next thing printed
The screen is divided into 5 print zones each 14columns wide
14 columns
CP1020 University of Wolverhampton - Steve Garner and Ian Coulson
29
Questions
1 Why don’t we program in the computers natural language directly ?
2 Why do we need to go through all the Steps to write a program ?
3 Write the code to display the message Hello World on the screen
Return to view another lecture