Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Science and an introduction to Pascal

Similar presentations


Presentation on theme: "Computer Science and an introduction to Pascal"— Presentation transcript:

1 Computer Science and an introduction to Pascal
Introduce self. Find out programming experience of new students plus what they did for GCSE CS (If at all). A Level Computing – Mr Sheehan (MSH)

2 Logging in (To be completed for helping external students log in)
(We are liaising with IT support how to get round this) Ensure everyone can log on.

3 Virtual Machine: Start -> All programs -> Subject Resources -> ICT -> Programming What is a virtual machine? Why do you think we use a virtual machine for programming in school? Ensure all can open the virtual machine. Mini discussion on virtual machines.

4 IDE and Programming Language
The programming language we will be using in class is Pascal. Most would of you would have used Python for GCSE and so this will give you the experience of another language. The IDE we currently use in lessons is Lazarus version This can be downloaded for free here: What is an IDE? Let students know they can potentially use other languages for their project. Briefly explain why we use Pascal as many students may consider it an odd choice.

5 Key words and terms Term Explanation Statement any individual step/instruction in the code Identifier A name for your variables, functions etc. Reserved words Words which are reserved for a specific purpose in the programming language and so can’t be used as an identifier . e.g. IF… WHILE… DO… Subroutines a sub-program, a set of statements written to perform a given task as part of solving the main problem. It can be called by using its identifier. Procedure a subroutine which performs a task but has no return value Function specifically a subroutine which returns a single value and can therefore be used in expressions. Give students a short amount of time to discuss or look up some of these. Ask random pairs for their responses. Give model answers – usually would be added to their programming glossary but this can be done next year. With the person next to you, discuss the definitions of these words in relation to programming.

6 The Basic Form At its simplest, a Pascal program has the form
Identifiers can only contain letters, underscores or numbers and must start with a letter. PROGRAM, BEGIN and END are reserved words. PROGRAM n; BEGIN {statements} END. Where n is a program name Emphasise rules and how reserved words can not be used as an identifier. In Pascal indentations and spacing is not mandatory so explain the importance of good programming practice and how it will help themselves and teacher find problems with their code when it doesn’t work.

7 Getting Started Lazarus opens automatically when opening the virtual machine. Ensure you have it on screen. Click Start -> New -> Program The first line of the program is called the program heading. The rest of the program is the program body. At least one space or end-of-line must appear between adjacent identifiers, reserved words and numbers. Very briefly explain difference between program and application. (Make sure I also have virtual machine on in the background to use as example if necessary).

8 First Program: Hello World!
To see the effect of a program there must be some output. A single line of output can be produced using the writeln statement. The text to be output must always appear within apostrophes or string quotes. Statements must always end with a semi-colon. Copy this code. Run the program. What is the problem with it? Add readln() under writeln(‘Hello World!’); to fix this. PROGRAM helloworld; BEGIN writeln(‘Hello World!’); END. Students copy code. Should notice that the output flashes up too briefly to read properly before program ends. Introduce readln() – explain it waits for a user input before continuing.

9 What is wrong with the code?
PROGRAM while; BEGIN writeln(‘Hello World!’); END. PROGRAM helloworld; BEGIN writeln(‘Hello World!’) END. PROGRAM helloworld; BEGIN writeln(Hello World!); END. PROGRAM 2_helloworld; BEGIN writeln(‘Hello World!’); END. Will pick random students to identify errors in these code snippets. Open up to whole class if student struggles (Although all have been mentioned early in the lesson)

10 Try the following Output Examples
PROGRAM helloworld; BEGIN writeln(‘Hello’); Writeln(‘World!’); readln(); END. PROGRAM helloworld; BEGIN writeln(‘Hello’, ’World!’); readln(); END. PROGRAM helloworld; BEGIN writeln(‘Hello’); writeln(); writeln(‘World!’); readln(); END. PROGRAM helloworld; BEGIN write(‘Hello’); writeln(‘World!’); readln(); END. Ask class for each one before revealing answers. Ask class difference between write and writeln at the end.

11 Output Spaces and end-of-line make no difference to the compiler. To the human reader, however, their inclusion is very important; neat layout is a major contributory factor towards program transparency. Comments are helpful to identify what is happening in a particular part of the program, not only for you but anyone else who reads the code. PROGRAM helloworld; BEGIN //Prints “Hello World! To the screen {Prints “Hello World! To the screen} writeln(‘Hello World!’); END. Tell class I want comments as //Enter comments. Explain they will be important with more complicated code and within projects. Comments

12 Exercises Print your name to the screen.
Print your name to the screen in a border made of a character of your choice. Write a program to draw a rocket. Write a program to print your initials in large letters. * *** ***** ******* ** ** Give students time to complete these. Extension is on the next page.

13 Extension The following code has 3 integers (whole numbers) set up to be used in the program. Currently the program asks the user for a number and stores it in the variable Num1 Complete the program so the user must enter 2 numbers. Then have the sum of those two numbers printed to the console. Extension introduces variables. Although not taught they should be able to figure it out with the code given – can use internet if necessary,.


Download ppt "Computer Science and an introduction to Pascal"

Similar presentations


Ads by Google