User Input Keyboard input.

Slides:



Advertisements
Similar presentations
Character Arrays (Single-Dimensional Arrays) A char data type is needed to hold a single character. To store a string we have to use a single-dimensional.
Advertisements

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.
1 10/25/06CS150 Introduction to Computer Science 1 Reading from and Writing to Files.
Basic Input/Output and Variables Ethan Cerami New York
C - Input & Output When we are saying Input that means to feed some data into program. This can be given in the form of file or from command line. C programming.
Input/Output  Input/Output operations are performed using input/output functions  Common input/output functions are provided as part of C’s standard.
Introduction to Python
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #002 (January 17, 2015)
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
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.
COMPUTER PARTS AND COMPONENTS INPUT DEVICES
Manipulating Text In today’s lesson we will look at: why we might want to pick out parts of text strings some BASIC functions that can be used to chop.
Programming Fundamentals. Today’s Lecture Why do we need Object Oriented Language C++ and C Basics of a typical C++ Environment Basic Program Construction.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Session 1 Simple Python Programs Using Print, Variables, Input.
In and Out are opposites. This is something to keep in mind when considering Input and Output. INPUT OUTPUT Ask: Does this device send information in?
1 Program Input Software Design Chapter 4. 2 You Will Want to Know... Prompting for and reading values into a program. Accessing data from a file. What.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
Data Types and Conversions, Input from the Keyboard CS303E: Elements of Computers and Programming.
Python Lesson 1 1. Starter Create the following Excel spreadsheet and complete the calculations using formulae: 2 Add A1 and B1 A2 minus B2 A3 times B3.
1 Input (Read) Statement. Variable Declaration (Definition) Initialization Assignment Displaying variables: using cout statement Reading variables from.
Part 1 Learning Objectives To understand that variables are a temporary named location to store data and that programmers work with different data types.
Chapter 4 Strings and Screen I/O. Objectives Define strings and literals. Explain classes and objects. Use the string class to store strings. Perform.
DATA Unit 2 Topic 2. Different Types of Data ASCII code: ASCII - The American Standard Code for Information Interchange is a standard seven-bit code that.
INPUT AND OUTPUT DEVICES. INPUT ALL THE ELEMENTS THAT HELP TO PUT INFORMATION INSIDE THE COMPUTER.
Output THE BASICS. What is Output? Output is the information that comes FROM a computer OUT to a user Sometimes this information is feedback to an action.
User Input ICS2O.
Chapter 1.2 Introduction to C++ Programming
Chp 4: Input and Output Devices
Chapter 1.2 Introduction to C++ Programming
Topics Designing a Program Input, Processing, and Output
User-Written Functions
Input/Output.
Chapter 1.2 Introduction to C++ Programming
Using the Console.
Chapter 2 More on Math More on Input
Chapter 1.2 Introduction to C++ Programming
Data Types Variables are used in programs to store items of data e.g a name, a high score, an exam mark. The data stored in a variable is entered from.
INC 161 , CPE 100 Computer Programming
Chapter 2 - Introduction to C Programming
Programming Fundamental
Variables, Expressions, and IO
Getting Started with C.
Introduction to C++ October 2, 2017.
Chapter 2 - Introduction to C Programming
Keyboard Input and Screen Display ––––––––––– Interactive Programming
Input/Output Input/Output operations are performed using input/output functions Common input/output functions are provided as part of C’s standard input/output.
IPC144 Introduction to Programming Using C Week 2 – Lesson 1
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Introduction to TouchDevelop
Number and String Operations
Chapter 2 - Introduction to C Programming
Topics Introduction Hardware and Software How Computers Store Data
File I/O in C Lecture 7 Narrator: Lecture 7: File I/O in C.
Chapter 2 - Introduction to C Programming
Data Groupings: File File: a group of related records
Variables In today’s lesson we will look at: what a variable is
Using screens and adding two numbers - addda.cbl
Topics Designing a Program Input, Processing, and Output
Understand the interaction between computer hardware and software
Topics Designing a Program Input, Processing, and Output
Chapter 2 - Introduction to C Programming
Reading from and Writing to Files
Developing a Program.
Introduction to C Programming
ASCII LP1.
Reading from and Writing to Files
Getting Started With Coding
Presentation transcript:

User Input Keyboard input

What is Input? Data sent into the computer for processing, storage and output Many possible formats Sound (microphone) Graphical (image from a camera) Text (from the keyboard) Positional (from a mouse) Many sources Internet, keyboard, mouse, music file, picture file...

Keyboard Input User types in something on the keyboard The program uses that input to perform some computations (also called processing or calculations) The processed data is eventually output to the screen

Does keyboard input have to be characters? It can be... But each character can represent something else Example: Where have you seen this? w – forward s – back a – left d - right

How Does Turing Do Keyboard Input Turing can do keyboard input many ways For now we will look at one method Keyboard (Today) Mouse

Input Whenever we want information from the user, that information is called input Before we can expect the user to enter information we must ask them for it, we call this “prompting” the user. This may come in the form of a put command or some type of indicating screen image, like an arrow

Input To use the information we need to store the information we receive from the user, we do this by putting it in a variable Now it’s simply a matter of telling Turing to wait for input from the user and store it in the variable. We have two commands to do this get and getch

get The get command when executed simply waits on that line of code until the user enters data and presses the Enter key. It will then store that data into an indicated variable Syntax: get <identifier> E.g. var userName : string get userName

Teacher-Led Example: Write a user-friendly program that reads in the User’s first name User’s last name User’s age User’s Xbox Gamer Score Output the username as their (first name + their last) name (e.g. Bob Joe will produce BobJoe) Output their rating as the Gamer Score divided by their age (age 24, Gamer Score 10389 will produce 432.875)

Input BE CAREFUL WHEN WORKING WITH USER INPUT: What if the program asks for an age and the user enters “Boomerang” But the variable for age is an int, not a string...what happens? ERROR Ensure the data entered by a user is the data type you expect to work with. Right now all we can do is trust them. Soon we will learn how to force them to enter proper data.

Dealing with Spaces Sometimes we may ask the user for more than single word input. E.g. We may ask them to enter their full name The problem is that the get command will only read up until it sees the first space E.g. If the user types in Bart Simpson, the only thing read in is Bart We an get around this by simply adding a bit of extra code to the end of our get statement informing Turing to read in everything until the end of the line That extra “bit” is simply : * E.g var fullName : string put “Please enter your full name” get fullName : *

getch( ) getch( ) is short for get character. The difference between getch( ) and get is that getch will only retrieve one character at a time and you do not have to hit the Enter key after. Where would this be useful? Games (w,a,s,d)...you do not have to hit Enter

getch ( ) There is one catch to using a getch( ) command: The variable used to store the input MUST be a string that can be no longer than 1 character We can specify how long a string can be when we declare it E.g. var key : string (1)

getch ( ) Special Note: When typing data for a get command the text you type shows on the screen, this is called echo. However when using a getch( ), there is no echo

getch( ) Syntax: var <identifier> : string (1) getch(identifier) E.g. var key : string (1) getch(key) We will have more detailed practice on this soon