COMP 4—Power Tools for the Mind1 PowerTools What’s in the Box? Turing 1: An Introduction to Programming You will learn elementary computer programming.

Slides:



Advertisements
Similar presentations
CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
Advertisements

Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Lecture 2 Introduction to C Programming
Introduction to C Programming
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
Introduction to C Programming
COSC 120 Computer Programming
Computer Science 1620 Variables and Memory. Review Examples: write a program that calculates and displays the average of the numbers 45, 69, and 106.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
1 Key Concepts:  Data types in C.  What is a variable?  Variable Declaration  Variable Initialization  Printf()  Scanf()  Working with numbers in.
CS 1400 Chapter 1 Introduction and Background
Introduction to a Programming Environment
Programming Logic and Design, Introductory, Fourth Edition1 Understanding Computer Components and Operations (continued) A program must be free of syntax.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
Introduction to C Programming
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 1 Introduction.
1 The First Step Learning objectives write Java programs that display text on the screen. distinguish between the eight built-in scalar types of Java;
Copyright 2003 Scott/Jones Publishing Brief Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
Chapter 2 Software Tools and Assembly Language Syntax.
Computer Science 101 Introduction to Programming.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 1 Introduction to Computers and Programming.
Chapter Introduction to Computers and Programming 1.
Visual Basic Fundamental Concepts. Integrated Development Enviroment Generates startup form for new project on which to place controls. Features toolbox.
CSC 125 Introduction to C++ Programming Chapter 1 Introduction to Computers and Programming.
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming 1.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Chapter 1: Introduction to Computers and Programming.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
Copyright © 2008 Pearson Prentice Hall. All rights reserved. 1 Microsoft Office Excel Copyright © 2008 Pearson Prentice Hall. All rights reserved
PYTHON. Python is a high-level, interpreted, interactive and object- oriented scripting language. Python was designed to be highly readable which uses.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Computer Science 101 Introduction to Programming.
C++ Basics Structure of a Program. C++ Source Code Plain text file Typical file extension .CPP Must compile the C++ source code without errors before.
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
5 BASIC CONCEPTS OF ANY PROGRAMMING LANGUAGE Let’s get started …
1 C++ Programming Basics Chapter 2 Lecture CSIS 10A.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
Chapter 2. C++ Program Structure C++ program is a collection of subprograms Subprograms in C++ are called FUNCTIONS Each function performs a specific.
1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Session 1 Simple Python Programs Using Print, Variables, Input.
Programming, an introduction to Pascal
1 A Balanced Introduction to Computer Science David Reed, Creighton University ©2005 Pearson Prentice Hall ISBN X Chapter 4 JavaScript and.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
1 Printing in Python Every program needs to do some output This is usually to the screen (shell window) Later we’ll see graphics windows and external files.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
1. COMPUTERS AND PROGRAMS Rocky K. C. Chang September 6, 2015 (Adapted from John Zelle’s slides)
1 1 Chapter 2 Elementary Programming. 2 2 Motivations In the preceding chapter, you learned how to create, compile, and run a Java program. Starting from.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
Chapter 1: Introduction to Computers and Programming.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
Introducing Python 3 Introduction to Python. Introduction to Python L1 Introducing Python 3 Learning Objectives Know what Python is and some of the applications.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
Chapter 2 - Introduction to C Programming
Variables, Expressions, and IO
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
T. Jumana Abu Shmais – AOU - Riyadh
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
12th Computer Science – Unit 5
Introduction to C Programming
Getting Started With Coding
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

COMP 4—Power Tools for the Mind1 PowerTools What’s in the Box? Turing 1: An Introduction to Programming You will learn elementary computer programming in a high-level language called Turing. (Turing 4.0.2) You’ve already met most of the important ideas: –How a processor works; how memory works –What machine language instructions look like –Spreadsheet formulas and functions Now we meet the ideas put together in a single programming language. Digression: Why learn Programming? Why Turing ?

COMP 4—Power Tools for the Mind2 PowerTools What’s in the Box? Ideas from Machine Language Statements are executed one after the other. Control can branch to a different statement. Statements can be repeated over and over again. It should be able to read input, transform or process it, and write output. INPUT (Keyboard) OUTPUT (Monitor) Store ( RAM ) PROCESSING (CPU)

COMP 4—Power Tools for the Mind3 PowerTools What’s in the Box? In Excel: part to right of = expression. Spreadsheet expressions can be made up of –constants “fired” –cell names (variables) $B$7 $D$5 $C$12 –mathematical operators: + – * / ^ –relational operators: = = –Boolean operators: AND OR NOT –special symbols (known w/in context):, : ( ) –functions (verbs/commands): SUM AVERAGE IF Ideas from Spreadsheet Formulas

COMP 4—Power Tools for the Mind4 PowerTools What’s in the Box? Turing has same basic ideas in its expressions, called program statements. –A program is made up of these statements. Constants: “fired” variable names: FirstName Age Grade assignment operator: := mathematical operators: + – * / ^ relational operators: = = Boolean operators: & | not special symbols (within context):, : ( ) verbs/commands called keywords: put get Ideas from Spreadsheet Formulas

COMP 4—Power Tools for the Mind5 PowerTools What’s in the Box? Turing: interactive language: –During run time, it can stop to ask user for data. Hmmm….. Another example of that behavior in a service that you use/interact with quite often? –Then Resumes execution. –Plenty of other ways to get input; we won’t cover. Storing INPUT Turing needs a place to store, keep track, and use input data values: where? RAM ! Two keywords will be required for this: – var – get

COMP 4—Power Tools for the Mind6 PowerTools What’s in the Box? Variables Much like SS cells: cell reference stays same, but contents can change, thereby destroying what was stored there before. Variable name identifies a chunk of RAM. Much like what in memory? Much like what in a SS? varname Note: my shortcut for variable name: varname Address Cell reference –Similar to SS cell name... we refer to varname but are interested in what’s stored there. Varname: acts much like absolute cell reference –General languages: the programmer creates mnemonic varnames—that helps his/her associate their meaning.

COMP 4—Power Tools for the Mind7 PowerTools What’s in the Box? Turing’s syntax for varnames: –begin with alphabetic character –only letters, digits, and _ (no spaces!) –not longer than 50 characters –not a reserved word (see handout) Valid varnames: empName Age hours M16 Amt Not valid: 3D emp name var true Declaring variables –With freedom to choose name comes obligation to tell the translator a unique name and a data type before you can use it. –3 data types: int, real, string (define)

COMP 4—Power Tools for the Mind8 PowerTools What’s in the Box? Examples: var firstName : string var age : int var payRate : real Quotable... Syntax for declaration statement: var [yourVarname] : [type] var and the different types are reserved keywords –var is also a command The colon is part of the lexicon and means something (semantics) to the translator within this context. Syntax dictates the ordering of the statement parts, and dictates what varnames are legal.

COMP 4—Power Tools for the Mind9 PowerTools What’s in the Box? How do you store input data in a SS cell? Program: stores data in a variable a few ways: (1) ask user to type it at run time : Programmer writes get, followed by varname. var firstName : string why do we need this? get firstName –Syntax for get statement: get [varname] What get command does at run time: 1. Turing pauses, waits for user to type in data [Enter] 2.Grabs keyed data and stores it in RAM chunk that was pre-assigned that varname More about Input

Step through each statement, just like the computer does: (we’ll run program at computer later) var firstName : string get firstName RAM Editor Window Turing Environment var firstName : string get firstName RUN OOT Run Window firstName Mary <ENTER> Mary 2

COMP 4—Power Tools for the Mind11 PowerTools What’s in the Box? Excel: there is visual representation of the values of all cells (-> all variables) on the screen at all times. Output Turing: screen output needs an explicit put operations followed by the values you want displayed on screen: variables (input data, or result of formula); constants; or some combination –Values will appear in the Run window at run time. –Observe these statements: put “Your total pay will be” put totPay –At run time, the run window will display: Your total pay will be 650 This is certainly not a complete program! What’s missing? or whatever is stored in totPay at run time.

COMP 4—Power Tools for the Mind12 PowerTools What’s in the Box? Output –String (constant) values are placed inside quotes. Where have you seen this behavior before in a SS? Why do you suppose you need to do this? What about varnames? Put inside quotes? Why? –Observe these statements: put “Your total pay will be” put “totPay” –At run time, that run window will display: Your total pay will be totPay

COMP 4—Power Tools for the Mind13 PowerTools What’s in the Box? Can put out more than 1 item* on a display line: – list each item in one program statement, AND separate each entire item* with a comma: put “Your total pay will be ”, totPay -- I included a space before the final quote; WHY? --What if I put the comma inside the final quote? *Items: var’s, constants (number or string), & results of formulas. Evaluate these separate program statements individually: put “Hello, World!” Hello, World! put “You are ”, yourAge, “ yrs old” put YourName put “Your Name” You are 22 yrs old Margaret Your Name put 8+8 put “8+8= ”, = 16 Output?

–Launch Turing program… provides programming environment and the Turing translator program (a compiler ), all in one. –Program entry & editing: Editor window. File/new for another window. Simple editing tools. Press Enter only after each complete statement! –Click Run to make it start: 1st: Program is translated into machine code –Error Viewer Window displays syntax errors. –Fix them; Run (translate) again ; –More errors? Fix, Run again…. Called: Run & Debug How things work

–CLEAN compilation? Machine language instructions are executed, one after the other (that’s when the machine cycles begin….) Run window will pop up if program includes put and/or get –for data entry (user) –for screen prompts, any input data you want echoed back to user, and desired program output. –TEST the output! How? Why? Then fix program as needed, run again….test… How things work, continued