Coding Concepts (Data- Types)

Slides:



Advertisements
Similar presentations
Week 2: Primitive Data Types 1.  Programming in Java  Everything goes inside a class  The main() method is the starting point for executing instructions.
Advertisements

CIS 234: Using Data in Java Thanks to Dr. Ralph D. Westfall.
Introduction to Computers and Programming Lecture 7:
Chapter 3 Data Representation.
Chapter 3 Data Representation. Chapter goals Describe numbering systems and their use in data representation Compare and contrast various data representation.
Working with the data type: char  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to Computers and Programming.
Storing data Getting data out Data types Ruby as a foundation Program Variables Click icon to hear comments (the download may take a minute)
IT253: Computer Organization
Copyright © 2002 W. A. Tucker1 Chapter 7 Lecture Notes Bill Tucker Austin Community College COSC 1315.
Mastering Char to ASCII AND DOING MORE RELATED STRING MANIPULATION Why VB.Net ?  The Language resembles Pseudocode - good for teaching and learning fundamentals.
CS190/295 Programming in Python for Life Sciences: Lecture 3 Instructor: Xiaohui Xie University of California, Irvine.
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
Chapter 2: Using Data.
5 BASIC CONCEPTS OF ANY PROGRAMMING LANGUAGE Let’s get started …
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
Lab 4 - Variables. Information Hiding General Principle: – Restrict the access to variables and methods as much as possible Can label instance variables.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
CSI 3125, Preliminaries, page 1 Data Type, Variables.
Road map char data type Reading –Liang 5: Chapter 2: 2.7.4; 2.9; –Liang 6: Chapter 2: 2.7.4; 2.9 –Liang 7: Chapter 2: 2.7.4; 2.9.
Announcements Assignment 2 Out Today Quiz today - so I need to shut up at 4:25 1.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Input, Output and Variables GCSE Computer Science – Python.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Week 2 - Wednesday CS 121.
Topics Designing a Program Input, Processing, and Output
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
IGCSE 4 Cambridge Data types and arrays Computer Science Section 2
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.
Recap Add these numbers together in binary
Introduction to Python
CMSC201 Computer Science I for Majors Lecture 22 – Binary (and More)
Standard Data Encoding
Containers and Lists CIS 40 – Introduction to Programming in Python
Object Oriented Programming
Other Kinds of Arrays Chapter 11
Introduction to C++ October 2, 2017.
University of Gujrat Department of Computer Science
Thinking about programming
Chapter 2.
Topic 3: Data Binary Arithmetic.
Data Representation Data Types Complements Fixed Point Representation
Variables ICS2O.
Coding Concepts (Sub- Programs)
Coding Concepts (Data Structures)
Topic 1: Problem Solving
Introduction to Primitive Data types
C++ Data Types Data Type
We’re moving on to more recap from other programming languages
Coding Concepts (Basics)
Variables Title slide variables.
Topic 1: Problem Solving
Binary Numbers.
CS190/295 Programming in Python for Life Sciences: Lecture 3
Fundamentals of Functional Programming
Language Constructs Construct means to build or put together. Language constructs refers to those parts which make up a high level programming language.
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Thinking about programming
String Processing 1 MIS 3406 Department of MIS Fox School of Business
Primitive Types and Expressions
Unit 3: Variables in Java
Java: Variables, Input and Arrays
Data Types Every variable has a given data type. The most common data types are: String - Text made up of numbers, letters and characters. Integer - Whole.
Data Types and Maths Programming Guides.
ASCII LP1.
Variables and Constants
Introduction to Primitive Data types
Section 6 Primitive Data Types
Presentation transcript:

Coding Concepts (Data- Types) Topic 2: Programming Coding Concepts (Data- Types)

Programming: Coding Concepts (Data-Types) This presentation is all about data The different forms we can see in a program The different structures we can use to store it In every programming language, data comes in different types Although data is just binary, these types help the interpreter/compiler understand what the data is used for Is it text? Then we can concatenate it Is it numerical? Then we can add/subtract/multiply/divide it Programming: Coding Concepts (Data-Types)

Numerical Logical Text Data Types Programming languages usually have their own way of saying whether something is a number or text Some languages don’t care Before looking at specific languages, let’s cover the main data-types we can come across They’re split into three categories Numerical Logical Text Programming: Coding Concepts (Data-Types)

Programming: Coding Concepts (Data-Types) Data Types: Numerical Numerical types are split into two sub-types Whole Numbers (Integer) Decimal Numbers (Real) Integers are positive or negative numbers that do not have a fractional part to them Reals are positive or negative numbers that can have a fractional part Though they don’t need one Programming: Coding Concepts (Data-Types)

Programming: Coding Concepts (Data-Types) Data Types: Numerical Integers are typically represented using the int keyword int meaning Integer In technical terms, an int is any whole number that fits within 32 bits Most significant bit used for sign (think Two’s Complement) Imagine converting a denary number to a binary one If it fits within these digits, then there’s no problem If the number is too large, we’ll get an overflow The number will go back to a really small one Programming: Coding Concepts (Data-Types)

Programming: Coding Concepts (Data-Types) Data Types: Numerical Reals can be represented in two ways 32-bit floating-point numbers: float 64-bit floating-point numbers: double The double is the most commonly seen, and what we’ll use (if the programming language needs it) These numbers can have a decimal point with digits after it Programming: Coding Concepts (Data-Types)

Data-Types: Numerical Python doesn’t care about data-types when we program in it It is referred to as a loosely-typed language The data-type of a variable doesn’t really matter As long as our program makes sense C# and Java, however, need to know what data- types to use They are strictly-typed Programming: Coding Concepts (Data-Types)

Data-Types: Numerical Here’s how we can use these types in the different programming languages Including conversion Python Java C# Programming: Coding Concepts (Data-Types)

Programming: Coding Concepts (Data-Types) Data-Types: Logical The Logical type is represented in one way Using a Boolean Booleans refer to any value that is true or false Or 1/0 As before, Python doesn’t care However, C# uses bool and Java uses Boolean They both have the values as true and false Python, however, has the values as True and False Those capitals are important! Programming: Coding Concepts (Data-Types)

Programming: Coding Concepts (Data-Types) Data-Types: Logical Here’s how we can use the Boolean type in each of the languages Including conversion Note that we don’t convert directly to a Boolean We take the text input And compare it against another result This gives us the Boolean value Java C# Python Programming: Coding Concepts (Data-Types)

Programming: Coding Concepts (Data-Types) Data Types: Text This final type has two sub-types as well Individual characters (Character) A series of characters in a row (String) These are represented using two keywords (in C# and Java) Characters use char Strings use string (in C#) and String (in Java) Python, as usual, doesn’t really care Programming: Coding Concepts (Data-Types)

Programming: Coding Concepts (Data-Types) Data Types: Text There are also two different ways of representing values of these sub-types String values often use speech marks (“”) Character values often use quotation marks (‘’) Python doesn’t care what you use, and actually doesn’t differentiate between strings and characters This does matter for C# and Java, as it thinks of characters as numbers As they come from the ASCII table Programming: Coding Concepts (Data-Types)

Programming: Coding Concepts (Data-Types) Data-Types: Text Here’s how we can use these text types in different programming languages C# Java Python Programming: Coding Concepts (Data-Types)

Programming: Coding Concepts (Data-Types) Manipulating Text The number and logical data-types have their own operators Numerical Operators: + - * / % Logical Operators: ||/or &&/and Relational Operators: > < == >= <= Equality Operators: == !/not Text also has its own features Not really operators per se But functions which that text value can use Programming: Coding Concepts (Data-Types)

Manipulating Text: Cases First up is the ability to take any text value and make it all upper-case or lower-case Running this function typically returns a new text value That is the upper/lower case version We would need to store this in a variable This is a useful thing to do, especially with user input Programming: Coding Concepts (Data-Types)

Manipulating Text: Cases For example, we want to compare a user-input value against a choice A simple one is yes/no, or y/n The characters Y and y are actually different Because they have different ASCII values We should accept both Y and y from the user if they enter it in Since, from the user’s standpoint, they are the same letter Programming: Coding Concepts (Data-Types)

Manipulating Text: Cases Here’s how we can handle input without introducing a case bug C# Java Python Java has to compare Strings using equals() (because it is an object). Java also has equalsIgnoreCase() for Strings, which removes the need for changing the case. Programming: Coding Concepts (Data-Types)

Programming: Coding Concepts (Data-Types) Create the following program: Generate a random number (between 0 and 1000) Ask the user if they would like to see another number Give the option of y/n If they do, then generate another random number If they do not, then end the program Programming: Coding Concepts (Data-Types)

Manipulating Text: Substring Strings are technically strings of characters Which means there is more than one character value If we have ‘more than one’ of a value in a single variable, well that’s an array We can treat string values as arrays Which means getting individual characters (as we saw before) Or getting substrings (groups of characters in the string) Programming: Coding Concepts (Data-Types)

Manipulating Text: Substring Let’s say we’re creating a registration system that needs user information It creates a username for a user based off A unique identifier at the beginning Their first-name’s initial 4 letters from their surname If their surname has more than 4 letters, then we only want to get the first 4 For example, for Jane Doeson, their username could be: 0192JDOES Programming: Coding Concepts (Data-Types)

Manipulating Text: Substring If we’re making this program, then we would Generate a number for the beginning of the username (could be randomly) Ask for the user’s first name Ask for the user’s surname From this we would need to create the username That means Getting the first letter of the first name Getting the first 4 letters of the surname (or the whole surname if less than, or equal to, 4 letters) Concatenating this all together and making it upper case Programming: Coding Concepts (Data-Types)

Manipulating Text: Substring Here is how we can do this in the different languages C# Python Java Python stores Strings in arrays, meaning we can use array slicing. That’s the [0:4] bit. We’re getting all the values from index 0 to index 4 (exclusive). Programming: Coding Concepts (Data-Types)

Programming: Coding Concepts (Data-Types) Create the following program Get a word from the user Add a hyphen to the end of the word: - Take the first letter of the word and move it to the end Add “ay” to the end of the word Output the word Programming: Coding Concepts (Data-Types)