Computer Science 1 Get out your notebook

Slides:



Advertisements
Similar presentations
Introducing JavaScript
Advertisements

James Tam Getting Started With Pascal Programming How are computer programs created What is the basic structure of a Pascal Program Variables in Pascal.
James Tam Getting Started With Pascal Programming What is the basic structure of a Pascal Program Variables in Pascal Performing input and output with.
J. Michael Moore Input and Output (IO) CSCE 110 Drawn from James Tam's material.
Introduction to a Programming Environment
Input and Output (IO) CSCE 110 Drawn from James Tam's material.
CS161 Topic #21 CS161 Introduction to Computer Science Topic #2.
1 The CONST definition CONST Pi = , City = ‘New York’; Constant identifiers are used when you do not want the value of an identifier to change why.
INTRODUCTION TO ALGORITHMS PROGRAMMING. Objectives Give a definition of the term algorithm Describe the various parts of the pseudocode algorithm or algorithm.
Pascal Programming Strings, Arithmetic operators and output formatting National Certificate – Unit 4 Carl Smith.
Lecture 13 Midterm overview When you know a thing, to hold that you know it, and when you do not know a thing, to allow that you do not know it: this is.
Copyright 1999 by Larry Fuhrer. Pascal Programming Getting Started...
Chapter 2. C++ Program Structure C++ program is a collection of subprograms Subprograms in C++ are called FUNCTIONS Each function performs a specific.
INFORMATION TECHNOLOGY CSEC CXC 10/25/ PASCAL is a programming language named after the 17th century mathematician Blaise Pascal. Pascal provides.
Introduction to Pascal The Basics of Program writing.
Chapter 4: Subprograms Functions for Problem Solving Mr. Dave Clausen La Cañada High School.
Programming, an introduction to Pascal
Pascal Programming Today Chapter 11 1 Chapter 11.
So now we’re programming What do programs do? Manipulate (process) data Math Read files Write to files Create files.
1 More on Readln:numerical values Note: ENTER key counts sends a carriage return and a line feed to the computer definition: “white space”: space, tab,
Program Options: 10 Minutes online Write a program that will display your home address as it would on an envelope. –First Name Last Name –Address –City,
Computer Science 1 How do you store a bunch of similar stuff?
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
Input and Output Output Prompt: –A message displayed to the user indicating what they are to enter. Should be clear and exact on what you want. write:
Computer Science 1 9/10/2014 Review Dry Run Math in Pascal How do you start, when you don’t know where to start?
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 3: Input/Output Samples.
15.1 More About High-Level Programming Languages Syntax and Semantics Each programming language contains its own rules for both syntax and semantics. Syntax.
Bill Tucker Austin Community College COSC 1315
Chapter 2 – part b Brent M. Dingle Texas A&M University
Egyptian Language School Computer Department
Structured Programming
The CONST definition CONST Pi = , City = ‘New York’;
Chapter 2: Input, Processing, and Output
Understand how to break down a program into procedures
Objectives Identify the built-in data types in C++
Goals Understand how to create and compare Strings.
Chapter Topics 2.1 Designing a Program 2.2 Output, Input, and Variables 2.3 Variable Assignment and Calculations 2.4 Variable Declarations and Data Types.
Program Options: 10 Minutes online
Review Dry Run A Little More Math Fix it Online time
Computer Science and an introduction to Pascal
Review Finish program Graphics Programming
Structured Programming
Goals Understand how to create and compare Strings.
Variables in C Topics Naming Variables Declaring Variables
How do you store a bunch of similar stuff?
Computer Science II First With files.
Computer Science II First With files.
Review Dry Run Taking Names Online time Math is Good
Computer Science 1 Get out your notebook
Creating your first C program
Program Options: 10 Minutes online
Repeat Day2 Dry Run Second Repeat Program
How do you store a bunch of similar stuff?
Computer Science 1 Online time for Graphics Program Random review
How can you make a guessing game?
Computer Science Procedures Day 2.
Computer Science 1 For..do loop Dry Run Take notes on the For loop
Chapter 2: Input, Processing, and Output
How can you make a guessing game?
Computer Science
How do you store a bunch of similar stuff?
Variables in C Topics Naming Variables Declaring Variables
10/27/2016 Dry Run 2 Case Programs Fix it Second Case Program
Computer Science 1 Get out your notebook
Variables in C Topics Naming Variables Declaring Variables
Variables in C Topics Naming Variables Declaring Variables
Computer Science II First With files.
Variables in C Topics Naming Variables Declaring Variables
Getting Started With Coding
Presentation transcript:

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

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 .

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

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.

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

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

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.

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

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 http://us.penguingroup.com/static/packages/us/yreaders/madlibs/fun.html 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.