Programming Constructs

Slides:



Advertisements
Similar presentations
Chapter 9 Introduction to Arrays
Advertisements

Chapter 4 Relational Databases Copyright © 2012 Pearson Education, Inc. publishing as Prentice Hall 4-1.
CSC 2720 Building Web Applications Database and SQL.
Brad Lloyd & Michelle Zukowski 1 Design and Implementation CIS 400 Final Project Dr. Bruce Maxim SQL.
Information systems and databases Database information systems Read the textbook: Chapter 2: Information systems and databases FOR MORE INFO...
Chapter 4 Relational Databases Copyright © 2012 Pearson Education 4-1.
CORE 2: Information systems and Databases STORAGE & RETRIEVAL 2 : SEARCHING, SELECTING & SORTING.
Introduction To Databases IDIA 618 Fall 2014 Bridget M. Blodgett.
Database System Concepts and Architecture Lecture # 3 22 June 2012 National University of Computer and Emerging Sciences.
Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizard’s Guide to PHP by David Lash.
Introduction to SQL Steve Perry
Chapter 9 Database Systems Introduction to CS 1 st Semester, 2014 Sanghyun Park.
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
Pavel Titenkov © SQL. Pavel Titenkov © Общий обзор англ. Structured Query Language — «язык структурированных запросов»англ. Это наиболее часто используемый.
Visual Programing SQL Overview Section 1.
SQL Jan 20,2014. DBMS Stores data as records, tables etc. Accepts data and stores that data for later use Uses query languages for searching, sorting,
Chapter 9 Introduction to Arrays Fundamentals of Java.
1 Section 10 - Embedded SQL u Many computer languages allow you to embed SQL statements within the code (e.g. COBOL, PowerBuilder, C++, PL/SQL, etc.) u.
1 Section 1 - Introduction to SQL u SQL is an abbreviation for Structured Query Language. u It is generally pronounced “Sequel” u SQL is a unified language.
Databases and Database User ch1 Define Database? A database is a collection of related data.1 By data, we mean known facts that can be recorded and that.
Databases and DBMSs Todd S. Bacastow January
Fundamentals of DBMS Notes-1.
CS4222 Principles of Database System
CIS 336 AID Your Dreams Our Mission/cis336aid.com
INLS 623– Database Systems II– File Structures, Indexing, and Hashing
Outline Types of Databases and Database Applications Basic Definitions
CHP - 9 File Structures.
Chapter 6 - Database Implementation and Use
Information Systems Today: Managing in the Digital World
Computer Programming BCT 1113
Microsoft Visual Basic 2005: Reloaded Second Edition
Chapter 9 Database Systems
Objectives Identify the built-in data types in C++
Appendix D: Network Model
Chapter 4 Relational Databases
Design and Implementation
Relational Algebra Chapter 4, Part A
CIS 336 str Competitive Success/snaptutorial.com
CIS 336 Competitive Success/snaptutorial.com
CIS 336 strCompetitive Success/tutorialrank.com
CIS 336 str Education for Service- -snaptutorial.com.
CIS 336 Education for Service-- snaptutorial.com.
CIS 336 STUDY Lessons in Excellence-- cis336study.com.
CIS 336 str Education for Service-- tutorialrank.com.
CIS 336 Teaching Effectively-- snaptutorial.com
CIS 336 str Teaching Effectively-- snaptutorial.com.
Databases and Information Management
Computer Programming.
DATABASE MANAGEMENT SYSTEM
SQL LANGUAGE and Relational Data Model TUTORIAL
Chapter 2 Database Environment Pearson Education © 2009.
Chapter 2 Database Environment.
Database Fundamentals
Database.
SQL OVERVIEW DEFINING A SCHEMA
Databases.
Data Model.
Normalization Normalization theory is based on the observation that relations with certain properties are more effective in inserting, updating and deleting.
Databases and Information Management
Programming We have seen various examples of programming languages
Design and Implementation
Accounting Information Systems 9th Edition
Chapter 8 Advanced SQL.
Database Management Systems
DATABASES WHAT IS A DATABASE?
Appendix D: Network Model
Data Structures & Algorithms
Chapter 2 Database Environment Pearson Education © 2009.
Chapter 2 Database Environment Pearson Education © 2009.
Presentation transcript:

Programming Constructs Andrew Csizmadia Monday 5th December 2016

Prerequisites for Learners For learners to be successful in using and engaging with programming theory, they will need to be: Familiar with fundamental programming constructs: selection, sequence and iteration Able to successfully read pseudocode Able to successfully write pseudocode Able to successfully debug pseudocode Able to use successfully use Computational Thinking concepts

arrays

Simple vs Structured Data Types Simple data type => data element contains a single value Structured data type => a data element contains a collection of data values x : 15 avg : 84.35 ch : ‘A’ scores : 85 79 92 57 68 80 name : ‘C’ ‘L’ ‘Y’ ‘D’ ‘E’

Big Idea - Array A variable can have a value that combines many values. You can: Extract one value Update part of the variable This idea is essential for representing complex data in programs: a song, an image a map

Big Idea - Arrays An array is a static data structure, Can: Cannot: i.e. its size is fixed Can: Select (i.e. index) one entry Update one entry Cannot: Add an extra entry to the start or end Insert/remove item from the middle

Arrays Arrays are Structured Static Data Types They have a means of accessing individual components using an index Values can be retrieved from and stored in the structure Structure given a single name Votes 12 34 23 43 21 35 22 Index 1 2 3 4 5 6 0 1 2 3 4 5 Individual elements accessed by index (integer Value) indicating relative position in collection

Arrays (1D) - Overview Structure - List Techniques - Create, Initialise, Search, Sort, Find Item, Reverse Implementation: Python (List) Application(s): Searching (Linear, Binary) Sorting (i.e. Quicksort)

Two-Dimensional (2D) Arrays Arrays may have multiple dimensions. Two-dimensional arrays can be visualized as tables with rows and columns. A two dimensional array is really an “array of arrays” where each element of a one-dimensional array contains another array.

Declaring a 2D Array Here is how you would declare a two-dimensional array chessboard with 8 rows and 8 columns: chessboard = table[8] [8] chessboard = table[8, 8] chessboard[8][8] chessboard[8, 8] 1 2 3 4 5 6 7 Rows 1 2 3 4 5 6 7 Columns

Which Way to label? Which way should be label/reference a two dimensional array? 1 2 3 4 5 6 7 7 6 5 4 3 2 1 Rows Rows OR 1 2 3 4 5 6 7 1 2 3 4 5 6 7 Columns Columns Which square is Chessboard [4, 4] is referring to?

Conceptualizing Two-D Arrays int [ ] [ ] table = new int [4][5]; The variable table references an array of four elements. Each of these elements in turn references an array of five integers … table is really an array of arrays.

Conceptualizing Two-D Arrays More specifically, table is an array of four memory locations and in each memory location of that array there is an array that has five memory locations. So table[0] refers to the first row of the 2D array and table[1] refers to the second row, table[2] refers to the third row and table[3] refers to the fourth row. Using the code table[2][3] allows us to work with the memory location in the third row and fourth column named row 2 column 3.

Conceptualizing Two-D Arrays A table of numbers, for instance, can be implemented as a two-dimensional array. The figure shows a two-dimensional array with four rows and five columns that contains some numbers.

Accessing an Element of a Two-D Array Suppose we name the array table; then to indicate an element in table, we specify its row and column position, remembering that index values start at 0: x = table[2][3]; // Set x to 23, the value in (row 2, column 3)

Arrays (2D) - Overview Structure - Table Techniques - Create, Initialise, Search, Sort, Find Item, Reverse Implementation: Python (List of lists) Application(s): Storing a table of data Image representation Game simulation Modelling relationships, networks and maps with graphs Building blocks for other data structures, i.e. trees

records

Records In computer science, a record : http://www.bbc.co.uk/education/guides/zfd2fg8/revision/5 In computer science, a record : contains a collection of data for each entity usually recorded as a row in a table

SQL (STRUCTURED Query Language)

SQL (Structured Query Language) SQL stands for Structured Query Language. It is the most commonly used relational database language today. SQL works with a variety of different fourth-generation (4GL) programming languages, such as Visual Basic, Python.

SQL is used for: Data Manipulation Data Definition Data Administration All are expressed as an SQL statement or command.

SQL SQL Requirements SQL Must be embedded in a programming language, or used with a 4GL like VB or Python SQL is a free form language so there is no limit to the number of words per line or fixed line break. Syntax statements, words or phrases are always in lower case; keywords are in uppercase. Not all versions are case sensitive!

SQL and Relational Database A Fully Relational Database Management System must: Represent all info in database as tables Keep logical representation of data independent from its physical storage characteristics Use one high-level language for structuring, querying, and changing info in the database Support the main relational operations Support alternate ways of looking at data in tables Provide a method for differentiating between unknown values and nulls (zero or blank) Support Mechanisms for integrity, authorization, transactions, and recovery

Design SQL represents all information in the form of tables Supports three relational operations: selection, projection, and join. These are for specifying exactly what data you want to display or use SQL is used for data manipulation, definition and administration .

Table Design Name Address Jane Doe 123 Main Street John Smith SQL Table Design Columns describe one characteristic of the entity Rows describe the Occurrence of an Entity Name Address Jane Doe 123 Main Street John Smith 456 Second Street Mary Poe 789 Third Ave

Data Retrieval (Queries) Queries search the database, fetch info, and display it. This is done using the keyword SELECT SELECT * FROM publishers pub_id pub_name address state 0736 New Age Books 1 1st Street MA 0987 Binnet & Hardley 2 2nd Street DC 1120 Algodata Infosys 3 3rd Street CA The * Operator asks for every column in the table.

Data Retrieval (Queries) Queries can be more specific with a few more lines SELECT * from publishers where state = ‘CA’ pub_id pub_name address state 0736 New Age Books 1 1st Street MA 0987 Binnet & Hardley 2 2nd Street DC 1120 Algodata Infosys 3 3rd Street CA Only publishers in CA are displayed

Data Input Putting data into a table is accomplished using the keyword INSERT Variable INSERT INTO publishers VALUES (‘0010’, ‘pragmatics’, ‘4 4th Ln’, ‘chicago’, ‘il’) Keyword pub_id pub_name address state 0736 New Age Books 1 1st Street MA 0987 Binnet & Hardley 2 2nd Street DC 1120 Algodata Infosys 3 3rd Street CA pub_id pub_name address state 0010 Pragmatics 4 4th Ln IL 0736 New Age Books 1 1st Street MA 0987 Binnet & Hardley 2 2nd Street DC 1120 Algodata Infosys 3 3rd Street CA Table is updated with new information

pub_id pub_name address state 0010 Pragmatics 4 4th Ln IL 0736 New Age Books 1 1st Street MA 0987 Binnet & Hardley 2 2nd Street DC 1120 Algodata Infosys 3 3rd Street CA Types of Tables There are two types of tables which make up a relational database in SQL User Tables: contain information that is the database management system System Tables: contain the database description, kept up to date by DBMS itself Relation Table Tuple Row Attribute Column

Using SQL SQL statements can be embedded into a program (cgi or perl script, Visual Basic, MS Access) OR SQL statements can be entered directly at the command prompt of the SQL software being used (such as mySQL) SQL Database

Using SQL CREATE DATABASE database_name USE database_name To begin, you must first CREATE a database using the following SQL statement: CREATE DATABASE database_name Depending on the version of SQL being used the following statement is needed to begin using the database: USE database_name

Using SQL To create a table in the current database, use the CREATE TABLE keyword CREATE TABLE authors (auth_id int(9) not null, auth_name char(40) not null) auth_id auth_name (9 digit int) (40 char string)

Using SQL To insert data in the current table, use the keyword INSERT INTO INSERT INTO authors values(‘000000001’, ‘John Smith’) Then issue the statement SELECT * FROM authors auth_id auth_name 000000001 John Smith

Using SQL auth_id auth_name auth_city auth_state 123456789 Jane Doe If you only want to display the author’s name and city from the following table: auth_id auth_name auth_city auth_state 123456789 Jane Doe Dearborn MI 000000001 John Smith Taylor SELECT auth_name, auth_city FROM publishers auth_name auth_city Jane Doe Dearborn John Smith Taylor

Using SQL auth_id auth_name auth_city auth_state 123456789 Jane Doe To delete data from a table, use the DELETE statement: DELETE from authors WHERE auth_name=‘John Smith’ auth_id auth_name auth_city auth_state 123456789 Jane Doe Dearborn MI 000000001 John Smith Taylor

Using SQL auth_id auth_name auth_city auth_state 123456789 Jane Doe To Update information in a database use the UPDATE keyword UPDATE authors SET auth_name=‘hello’ auth_id auth_name auth_city auth_state 123456789 Jane Doe Dearborn MI 000000001 John Smith Taylor Hello Hello Sets all auth_name fields to hello

Using SQL auth_id auth_name auth_city auth_state 123456789 Jane Doe To change a table in a database use ALTER TABLE. ADD adds a characteristic. ALTER TABLE authors ADD birth_date datetime null Type Initializer auth_id auth_name auth_city auth_state 123456789 Jane Doe Dearborn MI 000000001 John Smith Taylor birth_date . ADD puts a new column in the table called birth_date

Using SQL auth_id auth_name auth_city auth_state 123456789 Jane Doe To delete a column or row, use the keyword DROP ALTER TABLE authors DROP birth_date auth_id auth_name auth_city auth_state 123456789 Jane Doe Dearborn MI 000000001 John Smith Taylor auth_state . DROP removed the birth_date characteristic from the table

Using SQL auth_id auth_name auth_city auth_state 123456789 Jane Doe The DROP statement is also used to delete an entire database. DROP DATABASE authors auth_id auth_name auth_city auth_state 123456789 Jane Doe Dearborn MI 000000001 John Smith Taylor DROP removed the database and returned the memory to system

Activity: w3Schools’ SQL Tutorial Work through w3Schools’ SQL tutorial Challenge SQL Learning Mat https://www.khanacademy.org/computing/hour-of-code/hour-of-sql/v/welcome-to-sql SQL Workbook SC : Creating and Manipulating SQL Databases

Activity: SQL with Khan Academy Work through Creating SQL databases with Khan Academy Challenge SQL Learning Mat https://www.khanacademy.org/computing/hour-of-code/hour-of-sql/v/welcome-to-sql SQL Workbook SC : Creating and Manipulating SQL Databases

Activity: SQL with Access Explore using SQL with Northwest Trader Challenge SQL Learning Mat https://www.khanacademy.org/computing/hour-of-code/hour-of-sql/v/welcome-to-sql SQL Workbook SC : Using SQL with Access

SQL Summary SQL is a versatile language that can integrate with numerous 4GL languages and applications SQL simplifies data manipulation by reducing the amount of code required. More reliable than creating a database using files with linked-list implementation Determine the best close for your audience and your presentation. Close with a summary; offer options; recommend a strategy; suggest a plan; set a goal. Keep your focus throughout your presentation, and you will more likely achieve your purpose.

Design - Subroutines Subroutines are used to allows us to breakdown (decompose) a complex task into a set of solvable tasks in order to produce a solution to the original task. Subroutine may be : a function which returns value(s) a procedure which does not return a value

Design - Subroutines Using subroutines allows the designer or programmer to focus on one task as a time. Advantages Modular approach Efficient – only need to replace subroutine if change is required.

Subroutines and Parameters move (playerToPlay) ------------------------------------ Value(s) can be passed to a subroutine via parameter(s) to be used in that subroutine Aim – create a generalised subroutine, which perform the same task using different values. (Efficient design, Elegant design). currentPlayer = playerOne move(currentPlayer) currentPlayer = playerTwo ① ② ③ ④

Task : Tic-Tac-Toe Design Identify the subroutines that would be used to design a program to play tic-tac-toe (O-X-O) Challenge(s) Identify the subroutines which will need parameter(s) passed to them Identify the subroutines (functions) which will return parameter(s) https://users.soe.ucsc.edu/~sbrandt/111/code/DESIGN SC : Identify the subroutines requited to play Tic-Tac-Toc (O-X-O)

Any questions? Refreshments in diner 4pm