Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Science 1 Get out your notebook

Similar presentations


Presentation on theme: "Computer Science 1 Get out your notebook"— Presentation transcript:

1 Computer Science 1 Get out your notebook. 9-8-2016
Break down a program Generic Program outline First Dry Run Write a Program from Scratch

2 Breaking down the program.
Math := ‘Is assigned the value of…’ * / + - () Sqr() for squaring Sqrt() Can’t use ^ Order of operations {Mr. Smith} {Sample Tax Program} {2/1/08} Program first; Uses crt; Const TAX=0.05; Var price, totalCost:real; numberOfItems:integer; Begin clrscr; writeln(‘Please enter the price of the item’); readln(price); writeln(‘How many would you like to buy?’); readln(numberOfItems); totalCost:= numberOfItems*price*(1+TAX); writeln(‘Price = ‘, price:10:2); writeln(‘Number of items =‘, numberOfItems); writeln(‘The total cost = ‘, totalCost:10:2); End. Breaking down the program. Begin Every begin has an end. Indent between the begin and end. Eventually programs will have several begins and ends. {} Comments // Single Line Comments On each program include: Your Name, Short Description of your program, and the date More on writeln You can show several values, Strings, variables, or expressions (it will show the answer) but you need to put a , between them. Strings: put inside ‘’ Variables/Expressions, no ‘’ Formatting :10 uses 10 spaces for strings, characters, integers Formatting:10:2 For reals, sets 10 spaces t be used, 2 of them are for values to the right of the decimal point. Writeln Write Line Shows information on the screen and goes down to the next line. ‘Shows every character in ‘’’ To show and ‘, you enter ‘’ (Two apostrophes) Identifier Names: Start with a character. Then can have characters and/or numbers No spaces, punctuation or reserved words. Also, for this version of Pascal. It can’t match the saved name of the program Var section used to declare variables. Real: Have decimals Integer: No decimals Char: single characters String: A bunch of characters. (Names words, sentences up to 256 characters) Uses: Ties to libraries of commands. Const: Used to declare constants. Translate to Pascal Ans = (1/2)bh Ans =πr2 Ans = 3a + 4b Ans = 1/r1 + 1/r2 Ans = 4/3 πr3 Clrscr Clearscreen. Must have the uses crt in order to use the clrscr command. Readln; Used for getting information from the user. It stops the program from running and waits for the enter key to be hit. If you enter a value before hitting enter, it places that value in the variable. Type mismatch? End. The end of the program. Note this line ends with a .

3 Getting Names Program sample2; var begin end. name:string;
writeln(‘Please enter your name.’); readln(name); writeln(‘Hello ‘, name,’ welcome back!’); readln; end.

4 Computer Science 1 Learning
Review Be able to ‘Dry Run’ a program. Be able to fix a poorly written program. Given a problem, be able to write a program to solve the problem. Get out your notebooks.

5 Review Describe the following Reserved word Writeln Readln Begin Var
Const uses Const Type {} // End Program :10:2 Compile

6 Put the following in order as they would appear in a program.
Var Type Program Begin Uses End const Program Uses Const Type Var Begin end

7 General Outline of a Program
{Header information Name Description Date} Program name; uses const type Procedures/functions var begin //main body end. Leave these sections off, if you are not using them.

8 Dry run 1 (What do you think the following program does?)
{Mr. Smith's Sample Program} {Dry Run #1} {9/7/12} program DryRunTest; uses crt; var a,b,c:integer; begin clrscr; a:= 8; b:= 6; c:= a+b; writeln(a, b, c); b:= b + 2*a; a:= a + 7; end. Dry run 1 (What do you think the following program does?) a b c Screen

9 Your next program Write a program that will display your home address as it would on an envelope. Push: Let the user enter some or all of the information, and have your program format it. Write a mad-lib program Have the user enter at least 4 pieces of information. Noun, Adverb (honestly), Adjective (messy), Verb, Geographical location, … The computer will generate the mad-lib Here is a sample website Write a program that shows a poem or song. Can be an original work. Include space as appropriate. Push: Look up for..do, or repeat..until to have your program repeat the song several times. Push: Use the Pascal tutorial to add color etc.


Download ppt "Computer Science 1 Get out your notebook"

Similar presentations


Ads by Google