Introduction to Programming in Turing. Input, Output, and Variables

Similar documents
Introduction to TURING

Variables and Constants

BASIC ELEMENTS OF A COMPUTER PROGRAM

Math 6 Unit 2: Understanding Number Review Notes

PIETRO, GIORGIO & MAX ROUNDING ESTIMATING, FACTOR TREES & STANDARD FORM

C++ Programming: From Problem Analysis to Program Design, Third Edition

Accuplacer Arithmetic Study Guide

Python Programming Exercises 1

This tutorial will teach you about operators. Operators are symbols that are used to represent an actions used in programming.

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

CCBC Math 081 Order of Operations Section 1.7. Step 2: Exponents and Roots Simplify any numbers being raised to a power and any numbers under the

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

Repetition Structures

Condition-Controlled Loop. Condition-Controlled Loop. If Statement. Various Forms. Conditional-Controlled Loop. Loop Caution.

2.Simplification & Approximation

Programming with Python

The Very Basics of the R Interpreter

COSC 123 Computer Creativity. Introduction to Java. Dr. Ramon Lawrence University of British Columbia Okanagan

Graphics calculator instructions

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements

Student Success Center Arithmetic Study Guide for the ACCUPLACER (CPT)

CpSc 111 Lab 5 Conditional Statements, Loops, the Math Library, and Redirecting Input

Variables, expressions and statements

C How to Program, 6/e by Pearson Education, Inc. All Rights Reserved.

GRADE 7 MATH LEARNING GUIDE

Solving Equations with Inverse Operations

Java Programming Fundamentals - Day Instructor: Jason Yoon Website:

CpSc 1011 Lab 4 Formatting and Flow Control Windchill Temps

COMS 469: Interactive Media II

Expressions and Variables

4. Java Project Design, Input Methods

Fundamentals of Programming Session 4

The Absolute Value Symbol

Exponents. Reteach. Write each expression in exponential form (0.4)

Section A Arithmetic ( 5) Exercise A

CpSc 1111 Lab 4 Formatting and Flow Control

C introduction: part 1

Expressions and Casting. Data Manipulation. Simple Program 11/5/2013

CpSc 1111 Lab 4 Part a Flow Control, Branching, and Formatting

Fundamental of Programming (C)

Expressions and Casting

Odd-Numbered Answers to Exercise Set 1.1: Numbers

Algebraic Expressions & Models L1.2. Welcome Back! Get your stuff out and be ready to go when the bell rings!

Math Day 2 Programming: How to make computers do math for you

Python The way of a program. Srinidhi H Asst Professor Dept of CSE, MSRIT

CS 315 Software Design Homework 3 Preconditions, Postconditions, Invariants Due: Sept. 29, 11:30 PM

Variables and Literals

CSE 1001 Fundamentals of Software Development 1. Identifiers, Variables, and Data Types Dr. H. Crawford Fall 2018

TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA

CMPT 100 : INTRODUCTION TO

Integer Operations. Summer Packet 7 th into 8 th grade 1. Name = = = = = 6.

Unit E Step-by-Step: Programming with Python

Get to Know Your Calculator!

University of Technology. Laser & Optoelectronics Engineering Department. C++ Lab.

ENGINEERING 1020 Introduction to Computer Programming M A Y 2 6, R E Z A S H A H I D I

CpSc 1011 Lab 5 Conditional Statements, Loops, ASCII code, and Redirecting Input Characters and Hurricanes

Ex: If you use a program to record sales, you will want to remember data:

Programming for Engineers Introduction to C

ALGEBRA I Summer Packet

Summer Assignment Glossary

Math-2. Lesson 3-1. Equations of Lines

VBScript: Math Functions

7/8/10 KEY CONCEPTS. Problem COMP 10 EXPLORING COMPUTER SCIENCE. Algorithm. Lecture 2 Variables, Types, and Programs. Program PROBLEM SOLVING

Basic Math in Microsoft Excel

3 The Building Blocks: Data Types, Literals, and Variables

CS & IT Conversions. Magnitude 10,000 1,

A.4 Rationalizing the Denominator

Data Types & Variables

CS 115 Lecture 4. More Python; testing software. Neil Moore

WJEC MATHEMATICS INTERMEDIATE NUMBER STANDARD FORM

Professor: Sana Odeh Lecture 3 Python 3.1 Variables, Primitive Data Types & arithmetic operators

Mathematical Data Operators

Exercise: Inventing Language

Try typing the following in the Python shell and press return after each calculation. Write the answer the program displays next to the sums below.

Lecture 2: Variables and Operators. AITI Nigeria Summer 2012 University of Lagos.

COMP-202 Unit 2: Java Basics. CONTENTS: Using Expressions and Variables Types Strings Methods

Calculations with Sig Figs

Intermediate Algebra. Gregg Waterman Oregon Institute of Technology

GeoCode Language Reference Manual

Fundamentals of Programming CS-110. Lecture 2

VARIABLES. Aim Understanding how computer programs store values, and how they are accessed and used in computer programs.

Algebraically Speaking Chalkdust Algebra 1 Fall Semester

or 5.00 or 5.000, and so on You can expand the decimal places of a number that already has digits to the right of the decimal point.

rrr Cu 'Vt.-1 cal l-c.-<_ {CL/o,_

Working with Algebraic Expressions

Math 3 Coordinate Geometry Part 2 Graphing Solutions

DEPARTMENT OF MATHS, MJ COLLEGE

MATH REVIEW SUPPLEMENT. For The ARITHMETIC SECTION. of the. ACCUPLACER Entry Assessment

IT 1033: Fundamentals of Programming Data types & variables

Chapter 2. Designing a Program. Input, Processing, and Output Fall 2016, CSUS. Chapter 2.1

Programming Fundamentals and Python

Section 0.3 The Order of Operations

WHOLE NUMBER AND DECIMAL OPERATIONS

1 5 Integer Operations

Lab 1: Input, Processing, and Output This lab accompanies Chapter 2 of Starting Out with Programming Logic & Design.


Honors Computer Science C++ Mr. Clausen Program 3A, 3B, 3C

Solution Guide for Chapter 2

Numerical Analysis First Term Dr. Selcuk CANKURT

Transcription:

Introduction to Programming in Turing Input, Output, and Variables

The IPO Model The most basic model for a computer system is the Input-Processing-Output (IPO) Model. In order to interact with the computer as a programmer, we must develop simple examples of each of these stages, which we will then build upon to solve more and more sophisticated problems.

Output The most fundamental operation of a computer program is to communicate something useful to the end user. We accomplish this with the concept of Output. Output is implemented in many ways depending upon the programming language. For example: put, print, printf, puts

Using the put Command In the Turing programming language, output is accomplished using the put command. To start, we will consider outputting the most basic types of data strings (which are groups of characters), and integers (whole number values).

Output in Turing Whenever we refer to a string in Turing (and most other languages, and pseudocode), we need to put the characters in quotation marks: put Hello! put Hello world! For integers, no quotation marks are needed. Turing recognizes that they are numbers. put 35

Mathematical Operations To actually be making use of the computer's calculating ability, we need to use some mathematical operators. Operator Operation Code + Add A + B - Subtract A - B * Multiply A * B / Divide A / B ** Exponent A ** B

Math using Turing put 3 + 5 output is 8 put 4 11 output is -7 put 2 * 6 output is 12 put 7 / 2 output is 3.5 Remember that Order of Operations (BEDMAS) applies to what you are doing. You can use brackets to ensure calculations are done in the order you want.

3 4 2 5 11 6 2 3 (3 + 4) / (2 5) + (11 * 6) / (2**3)

Storage & Variables In order to interact with the outside world, programs have to accept Input. Before doing this, however, we need to discuss storage and variables. If the computer asks the user for their name, age, grade, address, or any other information, it should remember that information. We store information in memory, and the specific location in memory is called a variable (because its value varies).

Variables & Data Types When we declare a variable: 1. a space is reserved in memory for that data 2. a name is reserved to identify that data For now, we will consider only the three most basic types of data. When we declare variables, we also specify the data type. This is done to help the computer understand what we expect to use the variable for.

Data Types string a string value is a collection of characters, such as a name, address, or other combinations of letters and numbers int an integer value is a positive or negative whole number (..., -3, -2, -1, 0, 1, 2, 3, ) real a real number involves decimals, such as 0.5, 0.33, 10.7. You can also represent integers as reals, but try to avoid this (-3.0, 4.0)

Declaring Variables for: strings, integers, real numbers var firstname : string var age : int var bankbalance : real The keyword var is used to declare a variable. Then we give a meaningful name, and after the colon (:), identify the type of variable (string, int, real)

A Sample Program For input, use the get statement var firstname : string put Please enter your name get firstname put Hello put firstname

Improving the Interface Quite often, we want to combine our input and output on the same line. In Turing, use the two periods (..) at the end of the put line. var firstname : string put Please enter your name:.. get firstname put Hello.. put firstname

Exercises - setup You should have a folder for this unit: H:\00 ICS3M\02 Turing Basics\ Create a sub-folder called Exercises Save each exercise as you work through it, using consistent naming (exercise01a.t, exercise01b.t, etc...)

Exercises 1. Write a program that prompts the user for their name, age, and address, and then outputs this information using one or two nicely formatted sentences. (exercise01a.t) 2. Write a program that asks the user to input marks for 4 courses, and the displays the average mark. (exercise 01b.t) 3. Ask 5 simple math problems. After the user enters their answer, display the problem and the correct answer. The correct answer should be calculated by your program. (exercise01c.t)

Exercises... 4. Ask the user their name, age, and the current year. Greet the user and tell them the year they will be 25, 50, and 75. (exercise01d.t) 5. Have the user enter two integers between 1 and 9. Do the basic math operations using these numbers and display the answer (add, subtract, multiply, divide, exponent). (exercise 01e.t) 6. Using the available help guide for Turing, investigate how to do #2 with your answer rounded to one decimal place using put. (exercise 01f.t)