Presentation is loading. Please wait.

Presentation is loading. Please wait.

CP1020 University of Wolverhampton - Steve Garner and Ian Coulson1 Week 1 - Principles of programming Welcome from the Presenters Steve Garner and Dr Ian.

Similar presentations


Presentation on theme: "CP1020 University of Wolverhampton - Steve Garner and Ian Coulson1 Week 1 - Principles of programming Welcome from the Presenters Steve Garner and Dr Ian."— Presentation transcript:

1 CP1020 University of Wolverhampton - Steve Garner and Ian Coulson1 Week 1 - Principles of programming Welcome from the Presenters Steve Garner and Dr Ian Coulson

2 CP1020 University of Wolverhampton - Steve Garner and Ian Coulson 2 Essential information [1] zThe module is a means to learn programming principles zQuick Basic is a language to do this- available on most machines which have DOS, Windows or NT zWe assume you know NOTHING about programming a computer

3 CP1020 University of Wolverhampton - Steve Garner and Ian Coulson 3 Essential Information [2] zModule continually assessed 1 workshop exercises weeks 2 to 11- 40% 2 Assignment 1 week 5- 35% Assignment 2 week 12- 25% z You must PASS BOTH of these components z 1 hour lecture, 3 hour workshop

4 CP1020 University of Wolverhampton - Steve Garner and Ian Coulson 4 Essential information [3] zYou must attend ALL lectures, workshops and work in study time zTo learn this subject you must actually do the practical work, (like riding a bike)! zYou must have the course book - QBasic 2nd ed. - Bauman and Mandell 0314206590

5 CP1020 University of Wolverhampton - Steve Garner and Ian Coulson 5 Principles of computing zComputer hardware consists of several fundamental parts - monitor, system and keyboard zA 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 !

6 CP1020 University of Wolverhampton - Steve Garner and Ian Coulson 6 How to tackle a problem zWe will now look at how we will tackle a real problem zwe will go through the steps needed to produce a working program

7 CP1020 University of Wolverhampton - Steve Garner and Ian Coulson 7 Where to start zWhy programme ? All computers require a program in order to work. i.e. Word processing package has been written using a programming language. zFirst… look at the thing we are trying to get the computer to do. i.e. add two numbers zTo produce the program we must follow a series of steps

8 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

9 CP1020 University of Wolverhampton - Steve Garner and Ian Coulson 9 Problem - Requirements and Specification zDevelop a full understanding of the problem zCan be difficult to do: Users do not know what they want! Users keep changing their minds! zOnce the problem is understood, a Program Specification can be produced zThis specification will summarise the problem, and act as the agreement of what the developers must produce for the users

10 CP1020 University of Wolverhampton - Steve Garner and Ian Coulson 10 Analysis & Design [1] zOnce we fully understand the problem, then we can attempt to design a solution. zProbably the most important stage of the process as a good design will greatly simplify later steps zWill involve looking at: yInput data and corresponding output data yWhat processing is involved

11 CP1020 University of Wolverhampton - Steve Garner and Ian Coulson 11 Analysis & Design [2] zThere are many design techniques used, we will use what is known as pseudo code ysimply write down the steps in words - known as pseudo code

12 CP1020 University of Wolverhampton - Steve Garner and Ian Coulson 12 Testing zWe must test the design to ensure it gives the correct answers. zBy using sample data and applying the pseudo code steps to it, we can prove the design works.

13 CP1020 University of Wolverhampton - Steve Garner and Ian Coulson 13 Program or Coding zThe design and testing must be complete before this stage zYou should know what you want to achieve before beginning to code it! zIt should now be quite straightforward to implement our designs in code

14 CP1020 University of Wolverhampton - Steve Garner and Ian Coulson 14 Document zIf anyone else needs to look at or run your program it will need DOCUMENTING zWhat the problem is zHow did you design it? zHow did you test it? zWhat sort of data does it use? zWhat does each line of code do? zHow do you run it?

15 CP1020 University of Wolverhampton - Steve Garner and Ian Coulson 15 An example problem zWe 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 zWe 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

16 CP1020 University of Wolverhampton - Steve Garner and Ian Coulson 16 Analysis and Design za.Read the Problem zb.Read it again! zc.Do it on paper xtest data xtest algorithms xcheck results zd.Produce Design

17 CP1020 University of Wolverhampton - Steve Garner and Ian Coulson 17 a. Read The Problem za.Read the Specification - Understandable - OK zb.Read it again yIdentify the purpose of program :- To calculate the number of kilometres equivalent to a given number of miles

18 CP1020 University of Wolverhampton - Steve Garner and Ian Coulson 18 c. Do it on Paper zc.Do it on paper yA typical number of kilometres inputted may be 3. ythe answer should be 1.86 miles as 1 mile is equal to 1.61 km

19 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

20 CP1020 University of Wolverhampton - Steve Garner and Ian Coulson 20 Prepare Design [1] zThe first simple design, in pseudo code, would be: y1.enter number of km. y2.Calculate miles. y3.Display the answer. zThese steps can be broken down further

21 CP1020 University of Wolverhampton - Steve Garner and Ian Coulson 21 Prepare Design [2] zNew, more detailed, design: z1.Get number of km y1.1 Prompt user to enter the number of km y1.2 Read in the km from the keyboard z2.Calculate miles y2.1 divide km by number of km in one mile z3.Display the number of miles y3.1 Display number of miles with corresponding message

22 CP1020 University of Wolverhampton - Steve Garner and Ian Coulson 22 The solution - Prepare code REM program : to convert miles to kilometres REM written by : Ian Coulson REM date written: 15/9/98 DIM Km AS SINGLE‘Create variables DIM Miles AS SINGLE CLS‘this will clear the screen PRINT “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

23 CP1020 University of Wolverhampton - Steve Garner and Ian Coulson 23 Using Print statements zYour first steps in learning to programme is usually to display a suitable message on the screen zThe keyword PRINT in Qbasic is an instruction to display something on the screen. zHere is the way it works

24 CP1020 University of Wolverhampton - Steve Garner and Ian Coulson 24 Using the print statement zThe Print statement has the format PRINT “This is the text I want displayed on the screen” Use the Print keyword Enclose the text to be displayed in quotation marks This is the text I want displayed on the screen Resulting output on the screen

25 CP1020 University of Wolverhampton - Steve Garner and Ian Coulson 25 Printing on the screen zQbasic divides the screen into 80 columns and 25 rows. 25 rows 80 columns zQbasic has a number of mechanisms to arrange where on the screen you wish to print information zHave a look at the following examples

26 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 printed Next thing printed Each print statement causes a new row to be used

27 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

28 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 14 columns wide 14 columns

29 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


Download ppt "CP1020 University of Wolverhampton - Steve Garner and Ian Coulson1 Week 1 - Principles of programming Welcome from the Presenters Steve Garner and Dr Ian."

Similar presentations


Ads by Google