27 Pages

PHP

Course: COMP 519, Fall 2009
School: East Los Angeles College
Rating:
 
 
 
 
 

Word Count: 2898

Document Preview

Web COMP519: Programming Autumn 2008 PHP Basics: Introduction to PHP a PHP file, PHP workings, running PHP. Basic PHP syntax variables, operators, if...else...and switch, while, do while, and for. Some useful PHP functions How to work with HTML forms, cookies, files, time and date. How to create a basic checker for user-entered data Server-Side Dynamic Web Programming CGI is one of the most common...

Register Now

Unformatted Document Excerpt

Coursehero >> California >> East Los Angeles College >> COMP 519

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
Web COMP519: Programming Autumn 2008 PHP Basics: Introduction to PHP a PHP file, PHP workings, running PHP. Basic PHP syntax variables, operators, if...else...and switch, while, do while, and for. Some useful PHP functions How to work with HTML forms, cookies, files, time and date. How to create a basic checker for user-entered data Server-Side Dynamic Web Programming CGI is one of the most common approaches to server-side programming Universal support: (almost) Every server supports CGI programming. A great deal of ready-to-use CGI code. Most APIs (Application Programming Interfaces) also allow CGI programming. Choice of languages: CGI is extremely general, so that programs may be written in nearly any language. Perl is by far the most popular, with the result that many people think that CGI means Perl. But C, C++, Ruby or Python are also used for CGI programming. Drawbacks: A separate process is run every time the script is requested. A distinction is made between HTML pages and code. Other server-side alternatives try to avoid the drawbacks Server-Side Includes (SSI): Code is embedded in HTML pages, and evaluated on the server while the pages are being served. Add dynamically generated content to an existing HTML page, without having to serve the entire page via a CGI program. Active Server Pages (ASP, Microsoft) : The ASP engine is integrated into the web server so it does not require an additional process. It allows programmers to mix code within HTML pages instead of writing separate programs. (Drawback(?) Must be run on a server using Microsoft server software.) Java Servlets (Sun): As CGI scripts, they are code that creates documents. These must be compiled as classes which are dynamically loaded by the web server when they are run. Java Server Pages (JSP): Like ASP, another technology that allows developers to embed Java in web pages. PHP developed in 1995 by Rasmus Lerdorf (member of the Apache Group) originally designed as a tool for tracking visitors at Lerdorf's Web site within 2 years, widely used in conjunction with the Apache server developed into full-featured, scripting language for server-side programming free, open-source server plug-ins exist for various servers now fully integrated to work with mySQL databases PHP is similar to JavaScript, only its a server-side language PHP code is embedded in HTML using tags when a page request arrives, the server recognizes PHP content via the file extension (.php or .phtml) the server executes the PHP code, substitutes output into the HTML page the resulting page is then downloaded to the client user never sees the PHP code, only the output in the page The acronym PHP means (in a slightly recursive definition) PHP: Hypertext Preprocessor What do You Need? Our server supports PHP You don't need to do anything special! * You don't need to compile anything or install any extra tools! Create some .php files in your web directory - and the server will parse them for you. * Slightly different rules apply when dealing with an SQL database (as will be explained when we get to that point). Most servers support PHP Download PHP for free here: http://www.php.net/downloads.php Download MySQL for free here: http://www.mysql.com/downloads/index.html Download Apache for free here: http://httpd.apache.org/download.cgi (All of this is already present on the CS servers, so you need not do any installation yourself.) Basic PHP syntax A PHP scripting block always starts with <?php and ends with ?>. A PHP scripting block can be placed (almost) anywhere in an HTML document. <html> <!-- hello.php COMP519 --> <head><title>Hello World</title></head> <body> <p>This is going to be ignored by the PHP interpreter.</p> <?php echo <p>While this is going to be parsed.</p>; ?> <p>This will also be ignored by PHP.</p> <?php print(<p>Hello and welcome to <i>my</i> page!</p>'); ?> <?php //This is a comment /* This is a comment block */ ?> </body> </html> print and echo for output a semicolon (;) at the end of each statement // for a single-line comment /* and */ for a large comment block. view the output page The server executes the print and echo statements, substitutes output. Scalars All variables in PHP start with a $ sign symbol. A variable's type is determined by the context in which that variable is used (i.e. there is no strong-typing in PHP). <html><head></head> <!-- scalars.php COMP519 --> <body> <p> <?php $foo = true; if ($foo) echo "It is TRUE! <br /> \n"; $txt='1234'; echo "$txt <br /> \n"; $a = 1234; echo "$a <br /> \n"; $a = -123; echo "$a <br /> \n"; $a = 1.234; echo "$a <br /> \n"; $a = 1.2e3; echo "$a <br /> \n"; $a = 7E-10; echo "$a <br /> \n"; echo 'Arnold once said: "I\'ll be back"', "<br /> \n"; $beer = 'Heineken'; echo "$beer's taste is great <br /> \n"; $str = <<<EOD Example of string spanning multiple lines using heredoc syntax. EOD; echo $str; ?> </p> </body> </html> Four scalar types: boolean true or false integer, float, floating point numbers string single quoted double quoted view the output page Arrays An array in PHP is actually an ordered map. A map is a type that maps values to keys. <?php $arr = array("foo" => "bar", 12 => true); echo $arr["foo"]; // bar echo $arr[12]; // 1 ?> array() = creates arrays key = either an integer or a string. value = any PHP type. if no key, the maximum of the integer indices + 1. if an existing key, its value will be overwritten. can set values in an array unset() removes a key/value pair array_values() makes reindexing effect (indexing numerically) *Find more on arrays <?php array(5 => 43, 32, 56, "b" => 12); array(5 => 43, 6 => 32, 7 => 56, "b" => 12); ?> <?php $arr = array(5 => 1, 12 => 2); $arr[] = 56; // the same as $arr[13] = 56; $arr["x"] = 42; // adds a new element unset($arr[5]); // removes the element unset($arr); // deletes the whole array $a = array(1 => 'one', 2 => 'two', 3 => 'three'); unset($a[2]); $b = array_values($a); view the output page ?> Constants A constant is an identifier (name) for a simple value. A constant is case-sensitive by default. By convention, constant identifiers are always uppercase. <?php // Valid constant names define("FOO", "something"); define("FOO2", "something else"); define("FOO_BAR", "something more"); // Invalid constant names // with a number!) define("2FOO", (they shouldnt start "something"); You can access constants anywhere in your script without regard to scope. // This is valid, but should be avoided: // PHP may one day provide a magical constant // that will break your script define("__FOO__", "something"); ?> Operators Arithmetic Operators: +, -, *,/ , %, ++, - Assignment Operators: =, +=, -=, *=, /=, %= Example x+=y x-=y x*=y x/=y x%=y Is the same as x=x+y x=x-y x=x*y x=x/y x=x%y Comparison Operators: ==, !=, >, <, >=, <= Logical Operators: &&, ||, ! String Operators: . and .= (for string concatenation) $a = "Hello "; $b = $a . "World!"; // now $b contains "Hello World!" $a = "Hello "; $a .= "World!"; Conditionals: if else Can execute a set of code depending on a condition <html><head></head> <!-- if-cond.php COMP519 --> <body> <?php $d=date("D"); if ($d=="Fri") echo "Have a nice weekend! <br/>"; else echo "Have a nice day! <br/>"; $x=10; if ($x==10) { echo "Hello<br />"; echo "Good morning<br />"; } ?> </body> </html> if (condition) code to be executed if condition is true; else code to be executed if condition is false; date() is a built-in PHP function that can be called with many different parameters to return the date (and/or local time) in various formats In this case we get a three letter string for the day of the week. view the output page Conditionals: switch Can select one of many sets of lines to execute <html><head></head> <body> <!- switch-cond.php COMP519 --> <?php $x = rand(1,5); // random integer echo x = $x <br/><br/>; switch ($x) { case 1: echo "Number 1"; break; case 2: echo "Number 2"; break; case 3: echo "Number 3"; break; default: echo "No number between 1 and 3"; break; } ?> </body> </html> switch (expression) { case label1: code to be executed if expression = label1; break; case label2: code to be executed if expression = label2; break; default: code to be executed if expression is different from both label1 and label2; break; } view the output page Looping: while and do-while Can loop depending on a condition <html><head></head> <body> <?php $i=1; while($i <= 5) { echo "The number is $i <br />"; $i++; } ?> </body> </html> <html><head></head> <body> <?php $i=0; do { $i++; echo "The number is $i <br />"; } while($i <= 10); ?> </body> </html> view the output page view the output page loops through a block of code if, and as long as, a specified condition is true loops through a block of code once, and then repeats the loop as long as a special condition is true (so will always execute at least once) Looping: for and foreach Can loop depending on a "counter" <?php for ($i=1; $i<=5; $i++) { echo "Hello World!<br />"; } ?> <?php $a_array = array(1, 2, 3, 4); foreach ($a_array as $value) { $value = $value * 2; echo $value <br/> \n; } ?> <?php $a_array=array("a","b","c"); foreach ($a_array as $key => $value) { echo $key." = ".$value."\n"; } ?> loops through a block of code a specified number of times view the output page loops through a of block code for each element in an array User Defined Functions Can define a function using syntax such as the following: <?php function foo($arg_1, $arg_2, /* ..., */ $arg_n) { echo "Example function.\n"; return $retval; } ?> Can also define conditional functions, functions within functions, and recursive functions. Can return a value of any type <?php function square($num) { return $num * $num; } echo square(4); ?> <?php function small_numbers() { return array (0, 1, 2); } list ($zero, $one, $two) = small_numbers(); echo $zero, $one, $two; ?> <?php function takes_array($input) { echo "$input[0] + $input[1] = ", $input[0]+$input[1]; } takes_array(array(1,2)); ?> view the output page Variable Scope The scope of a variable is the context within which it is defined. <?php $a = 1; /* limited variable scope */ function Test() { echo $a; /* reference to local scope variable */ } Test(); ?> <?php $a = 1; $b = 2; function Sum() { global $a, $b; $b = $a + $b; } Sum(); echo $b; ?> The scope is local within functions, and hence the value of $a is undefined in the echo statement. global refers to its global version. <?php function Test() { static $a = 0; echo $a; $a++; } Test1(); Test1(); Test1(); ?> static does not lose its value. view the output page Including Files The include() statement includes and evaluates the specified file. vars.php <?php $color = 'green'; $fruit = 'apple'; ?> test.php <?php echo "A $color $fruit"; // A include 'vars.php'; echo "A $color $fruit"; // A green apple ?> ?> <?php function foo() { global $color; include ('vars.php); echo "A $color $fruit"; } /* * * * vars.php is in the scope of foo() so * $fruit is NOT available outside of this * scope. $color is because we declared it * as global. */ // A green apple // A green foo(); echo "A $color $fruit"; view the output page view the output page *The scope of variables in included files depends on where the include file is added! You can use the include_once, require, and require_once statements in similar ways. PHP Information The phpinfo() function is used to output PHP information about the version installed on the server, parameters selected when installed, etc. <html><head></head> <! info.php COMP519 <body> <?php // Show all PHP information phpinfo(); ?> <?php // Show only the general information phpinfo(INFO_GENERAL); ?> </body> </html> INFO_GENERAL The configuration line, php.ini location, build date, Web Server, System and more PHP 4 credits Local and master values for php directives Loaded modules Environment variable information All predefined variables from EGPCS PHP license information INFO_CREDITS INFO_CONFIGURATION INFO_MODULES INFO_ENVIRONMENT INFO_VARIABLES INFO_LICENSE INFO_ALL view the output page Shows all of the above (default) Server Variables The $_SERVER array variable is a reserved variable that contains all server information. <html><head></head> <body> <?php echo "Referer: " . $_SERVER["HTTP_REFERER"] . "<br />"; echo "Browser: " . $_SERVER["HTTP_USER_AGENT"] . "<br />"; echo "User's IP address: " . $_SERVER["REMOTE_ADDR"]; ?> </body> </html> view the output page The $_SERVER is a super global variable, i.e. it's available in all scopes of a PHP script. File Open The fopen("file_name","mode") function is used to open files in PHP. r w a x Read only. r+ Write only. w+ Append. a+ Create and open for write only. x+ Read/Write. Read/Write. Read/Append. Create and open for read/write. <?php $fh=fopen("welcome.txt","r"); ?> For w, and a, if no file exists, it tries to create it (use with caution, i.e. check that this is the case, otherwise youll overwrite an existing file). For x if a file exists, it returns an error. <?php if ( !($fh=fopen("welcome.txt","r")) ) exit("Unable to open file!"); ?> If the fopen() function is unable to open the specified file, it returns 0 (false). File Workings fclose() closes a file. fgetc() reads a single character fwrite(), fputs () writes a string with and without \n <?php $myFile = "welcome.txt"; if (!($fh=fopen($myFile,'r'))) exit("Unable to open file."); while (!feof($fh)) { $x=fgetc($fh); echo $x; } fclose($fh); view the output page ?> <?php $lines = file('welcome.txt'); foreach ($lines as $l_num => $line) { echo "Line #{$l_num}: .$line.<br/>; view the output page } ?> feof() determines if the end is true. fgets() reads a line of data file() reads entire file into an array <?php $myFile = "welcome.txt"; $fh = fopen($myFile, 'r'); $theData = fgets($fh); fclose($fh); echo $theData; view the output page ?> <?php $myFile = "testFile.txt"; $fh = fopen($myFile, 'a') or die("can't open file"); $stringData = "New Stuff 1\n"; fwrite($fh, $stringData); $stringData = "New Stuff 2\n"; fwrite($fh, $stringData); fclose($fh); view the output page ?> Form Handling Any form element is automatically available via one of the built-in PHP variables (provided the element has a name defined with it). <html> <-- form.html COMP519 --> <body> <form action="welcome.php" method="POST"> Enter your name: <input type="text" name="name" /> <br/> Enter your age: <input type="text" name="age" /> <br/> <input type="submit" /> <input type="reset" /> </form> </body> </html> <html> <!- welcome.php COMP 519 --> <body> Welcome <?php echo $_POST["name"]..; ?><br /> You are <?php echo $_POST["age"]; ?> years old! </body> </html> $_POST contains all POST data. $_GET contains all GET data. view the output page Cookie Workings setcookie(name,value,expire,path,domain) creates cookies. <?php setcookie("uname", $_POST["name&qu...

Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more. Course Hero has millions of course specific materials providing students with the best way to expand their education.

Below is a small sample set of documents:

East Los Angeles College - COMP - 519
DatamodelsXML: eXtensible Markup LanguageSlides are based on slides from Database System Concepts Silberschatz, Korth and Sudarshan See www.db-book.com for conditions on re-use Many examples are from www.w3schools.comRDBMS: atomic elements store
East Los Angeles College - COMP - 519
Comp 519: Web Programming Autumn 2008Advanced SQL and PHP Advanced queries Querying more than one table Searching tables to find information Aliasing tables PHP functions for using query resultsUsing several tables mySQL (like any other database
Sveriges lantbruksuniversitet - GEOG - 420
2/20/2009GEOG 420 Lecture 5 feminismsOutline feminist cultural geographiesFeminist cultural geographiesfeminismsSex: biologically male or female Gender: social rendering (e.g. inscription, identification, and enactment) of male and fema
Sveriges lantbruksuniversitet - GEOG - 420
1/16/2009GEOG 420 Lecture 1Outline Environmental determinism Carl Sauer &amp; landscapeOld Cultural Geography The superorganic Important to understand how culture has been used and why it has been used in certain ways History of geography i
Sveriges lantbruksuniversitet - GEOG - 420
1/23/2009GEOG 420 Lecture 2Outline 20th C. human geographies cultural studiesnew cultural geography new cultural geographyspace Late 19th C. and early 20th C. geography explored, identified, described, mapped, classified (Sauer, Hartsho
Sveriges lantbruksuniversitet - GEOG - 420
2/6/2009GEOG 420 Lecture 4 social theoryOutline globalization of capitalism Don Mitchells critiqueMarxist critiquessocial theoryUKCommittee on SOCIAL THEORY The University of Kentucky's Committee on Social Theory was formed in 1989 to
Sveriges lantbruksuniversitet - GEOG - 102
Lect. 4 GEOG 102 Sep. 26, `07 Hertzman1) Comments on Ronald Wright's conclusions 2) Urban heat islands-myths and facts 3) Cities of the Less Developed World &amp; Related Issues1a) Comments on Ronald Wright's conclusionsa) pp. 128-29 RUNAWAY TRAIN i
East Los Angeles College - COMP - 103
CPU Registers in PentiumComputer Systems Lecture 9CPU status flags EFLAG: The Flag register holds the CPU status flags The status flags are separate bits in EFLAG where information on important arising conditions such as overflow, or carry bits
East Los Angeles College - COMP - 205
COMP205 IMPERATIVE LANGUAGES 4. MORE ON BASIC DATA TYPES1) Pointers 2) Type declarations 3) Access/reference values 4) Type renaming/aliasing 5) Subtypes 6) Macro substitutionPOINTERS Pointer variables have as their value an address, i.e. a refer
East Los Angeles College - COMP - 317
Exponentialsc := 1 ; while b &gt; 0 c := 1 ; while b &gt; 0 while (b a := b := b := b c := c * { c=mn }The Goal{ a=m b=n b 0 }while (b div 2) * 2 = b a := a * a ; b := b div 2 b := b 1 ; c := c * adiv 2) * 2 = b a * a ; b div 2 1 ; aThe Invar
East Los Angeles College - COMP - 205
COMP205 Comparative Programming LanguagesPart 1: Introduction to programming languagesLecture 3: Managing and reducing complexity, program processingMANAGING AND REDUCING COMPLEXITY, AND PROGRAM PROCESSING1. Managing and reducing complexity
East Los Angeles College - COMP - 205
COMP205 IMPERATIVE LANGUAGES INTRODUCTION1) Definition2) Note on structured and modular programming, and information hiding 3) Example imperative languages 4) Features of imperative languages(Q) WHAT IS AN IMPERATIVE LANGUAGE? We can define such
East Los Angeles College - COMP - 213
COMP213 Example Exam: Model Solution 1. (a) import java.util.Vector; /* * Trees with integer internal labels and lists of subtrees. * * The {@link TreeNode list of subtrees} is implemented as a linked list. * * @author &lt;a href=&quot;mailto:grant@liverpool
East Los Angeles College - COMP - 213
COMP213DEPARTMENT : Computer ScienceSEPTEMBER 2005 EXAMINATIONSBachelor of Arts : Year 2 Bachelor of Arts : Year 3 Bachelor of Engineering : Year 2 Bachelor of Science : Year 1 Bachelor of Science : Year 2Advanced Object-Oriented Programming
East Los Angeles College - COMP - 205
COMP205 IMPERATIVE LANGUAGES 5. COMPOUND (HIGHER LEVEL) DATA TYPES I - ARRAYS1) Introduction to higher level types 2) Arrays and their declaration 3) Assigning values to array elements 4) Operations on arrays 5) Ada array attributesINTRODUCTION TO
East Los Angeles College - COMP - 205
Comp 205:Comparative Programming LanguagesDeclarative Programming Languages Logic Programming Horn-Clause Logic PrologLecture notes, exercises, etc., can be found at: www.csc.liv.ac. uk/~grant/Teaching/COMP205/Declarative vs ImperativeDecla
Sveriges lantbruksuniversitet - PHYS - 101
CHAPTER 3: Kinematics in Two or Three Dimensions; Vectors46. Choose the origin to be at ground level, under the place where the projectile is launched, and upwards to be the positive y direction. For the projectile, v0 = 65.0 m s , 0 = 35.0, a y =
Sveriges lantbruksuniversitet - PHYS - 1010901
CHAPTER 3: Kinematics in Two or Three Dimensions; Vectors46. Choose the origin to be at ground level, under the place where the projectile is launched, and upwards to be the positive y direction. For the projectile, v0 = 65.0 m s , 0 = 35.0, a y =
East Los Angeles College - COMP - 205
COMP205 IMPERATIVE LANGUAGES 12a. ERROR HANDLING1) Causes of errors 2) Classification of errors 3) Signals and exceptionsCAUSES OF ERRORS1) Domain/data errors: an operation is called with data that cannot be handled by that operation, e.g. divide
Sveriges lantbruksuniversitet - COGS - 300
Some material relevant to the Syllogism.First, we should get straight on the four &quot;categorical forms&quot; of statements. They are: A: E: I: O: All X are Y No X are Y Some X are Y Some X are not YThe A, E, I, O are the standard names for the type of st
East Los Angeles College - COMP - 205
COMP205 IMPERATIVE LANGUAGES 11. PROGRAM CONSTRUCTS 2 (REPETITION)REPETITION Two main forms of repetition: 1) Fixed Count Loops: Repetition over a finite set (for loops). 2) Variable Count Loops: Repetition as long as a given condition holds (whil
East Los Angeles College - COMP - 205
Comp 205:Comparative Programming LanguagesFunctional Programming Languages:T A R L e i s c t u c r s o m i v e p d r e e h f i n e n i t i o s i o n n s s M h e t y p e o f l i s t s i sRecursion r e c u r s i v e l y d e f i n e d :More
East Los Angeles College - COMP - 205
Comp 205:Comparative Programming LanguagesE eErrorsr r o v a l ur s aa t er e s areported w h x n i l l e g a l ee pn r e st h se i o nH :askel li nt er pr et erLazy Evaluation E E I n vr r o a
East Los Angeles College - COMP - 213
COMP 213Advanced Object-oriented ProgrammingLecture 13Propositional Logic(Mondrian )TaskDevelop a program that: allows a user to enter a string representing a term in propositional logic; prints out the term with minimal and maximal bracke
East Los Angeles College - COMP - 205
k y {w } z xwv C #8} w8 D8~&amp;d {| w y D% B 9jSP WQ P FP QuCDPdg 9PfgYpP Q j%5 DeuC 6I#DED5B @85641 Q A BC S A A 9 F B C A97 3 k 94%IDB t 9 P9 BY6m Clengths = map (length) incAll = map (plus 1) where plus m n = m + n # kH l 44 Q %4%3 D4Pd Tr D 9 D
East Los Angeles College - COMP - 213
COMP213DEPARTMENT : Computer ScienceSEPTEMBER 2004 EXAMINATIONSBachelor of Arts : Year 2 Bachelor of Arts : Year 3 Bachelor of Engineering : Year 2 Bachelor of Science : Year 1 Bachelor of Science : Year 2Advanced Object-Oriented Programming
East Los Angeles College - COMP - 213
COMP 213Advanced Object-oriented ProgrammingLecture 5ScopeClassesA class contains declarations of members. Members can be: fields (including constants) methods classes Each of these has a name, as do classes themselves. Every name has a scop
East Los Angeles College - COMP - 205
COMP205 Comparative Programming LanguagesGrant Malcolm (grant@csc.liv.ac.uk) Introduction to programming languages The imperative paradigm The functional paradigm Other paradigms and concluding remarksBOOKS1. Tucker, A. and Noonan, R. Program
East Los Angeles College - COMP - 205
COMP205 IMPERATIVE LANGUAGES 9. EXPRESSIONS AND STATEMENTS1. Unions 2.Expressions. 3.Operators. 4.Type equivalence. 5.Coercion, casting and conversion.UNIONS It is sometimes desirable to define a variable which can be of two or more different typ
East Los Angeles College - COMP - 205
COMP205 IMPERATIVE LANGUAGES 6. COMPOUND (HIGHER LEVEL) DATA TYPES II - MORE ON ARRAYS1) Constrained (static) and unconstrained (dynamic) arrays. 2) Flexible arrays 3) Multi-dimensional arrays 4) Arrays of arrays 5) Lists, sets, bags,Etc. 6) Strings
East Los Angeles College - COMP - 205
COMP205 IMPERATIVE LANGUAGES 14. PROGRAM COMPOSITION II1) More on parameter passing: a) Parameter association b) Default parameters c) Procedures as parameters 2) Modules: Ada packages, C modules, C header files 3) Programs 4) Generics and Abstract
East Los Angeles College - COMP - 205
COMP205 IMPERATIVE LANGUAGES 2. DATA1) Data Attributes2) Declarations, Assignment and Instantiation 3) Global and Local Data 4) Variables 5) Constants 6) Example programsDATA - &quot;that which is given&quot;A data item has a number of attributes: 1) An A
Cal Poly - MEC - 6304
PERFORMANCE 23 18SWASHPLATESERIES PUMP ANGLETHESE CURVES DO NOT TAKE LOSSES DUE TO THE, CHARGEINTO PUMPACCOUNT
East Los Angeles College - COMP - 205
COMP205 IMPERATIVE LANGUAGES 3. DATA AND DATA TYPES1) Data Review 2) Anonymous Data Items 3) Renaming 4) Overloading 5) Introduction to Data Types 6) Basic types 7) Range and precision 8) Ada/Pascal &quot;attributes&quot;ANONYMOUS DATA ITEMS Often we use d
East Los Angeles College - COMP - 205
COMP205 IMPERATIVE LANGUAGES 5. COMPOUND (HIGHER LEVEL) DATA TYPES I - ARRAYS1) Introduction to higher level types 2) Arrays and their declaration 3) Assigning values to array elements 4) Operations on arrays 5) Ada array attributesINTRODUCTION TO
East Los Angeles College - COMP - 205
COMP205 IMPERATIVE LANGUAGES 6. COMPOUND (HIGHER LEVEL) DATA TYPES II - MORE ON ARRAYS1) Constrained (static) and unconstrained (dynamic) arrays. 2) Flexible arrays 3) Multi-dimensional arrays 4) Arrays of arrays 5) Lists, sets, bags,Etc. 6) Strings
East Los Angeles College - COMP - 205
COMP205 Comparative Programming LanguagesGrant Malcolm (grant@csc.liv.ac.uk) Introduction to programming languages The imperative paradigm The functional paradigm Other paradigms and concluding remarksBOOKS1. Tucker, A. and Noonan, R. Program
East Los Angeles College - COMP - 205
COMP205 IMPERATIVE LANGUAGES 11. PROGRAM CONSTRUCTS 2 (REPETITION)1) Fixed count loops 2) Variable count loops 3) Post-test Loops 4) Terminating a loopREPETITION Two main forms of repetition: 1) Fixed Count Loops: Repetition over a finite set (fo
Sveriges lantbruksuniversitet - M - 251
Homework #1 MATH 251 Coordinates in Three Dimensions a) Describe the geometry of the set of points whose coordinates (x, y, z) satisfy the equation: x2 + y 2 + z 2 + 4x + 2y 6z 22 = 0 . b) Show that the intersection of the object in part a) with
East Los Angeles College - COMP - 205
COMP205 IMPERATIVE LANGUAGES 7. COMPOUND (HIGHER LEVEL) DATA TYPES III1) Enumerated types 2) 3) 4) 5) 6) Records and structures Accessing fields in records/structures Operations on records/structures Variant records Dynamic and static arrays of reco
East Los Angeles College - COMP - 205
COMP205 IMPERATIVE LANGUAGES 9. EXPRESSIONS AND STATEMENTS1. Unions 2.Expressions. 3.Operators. 4.Type equivalence. 5.Coercion, casting and conversion.UNIONS It is sometimes desirable to define a variable which can be of two or more different typ
East Los Angeles College - COMP - 205
COMP205 IMPERATIVE LANGUAGES 12a. ERROR HANDLING1) Causes of errors 2) Classification of errors 3) Signals and exceptions12b. PROGRAM COMPOSITION I1) Program hierarchy 2) Blocks 3) Routines 4) Procedures and functionsCAUSES OF ERRORS1) Domain/
Sveriges lantbruksuniversitet - MATH - 443
MATH 443 Assignment #7Below are short answers (hints) to assigned questions.19A(i) There are 6 = 15 points in the incidence structure. Consider two 2 distinct edges of K6 . If they have a common endpoint, they belong to a unique triangle, and to
East Los Angeles College - COMP - 205
COMP205 IMPERATIVE LANGUAGES INTRODUCTION1) Definition2) Note on structured and modular programming, and information hiding 3) Example imperative languages 4) Features of imperative languages(Q) WHAT IS AN IMPERATIVE LANGUAGE? We can define such
East Los Angeles College - COMP - 205
COMP205 Comparative Programming LanguagesPart 1: Introduction to programming languagesLecture 3: Managing and reducing complexity, program processingMANAGING AND REDUCING COMPLEXITY, AND PROGRAM PROCESSING1. Managing and reducing complexity
East Los Angeles College - COMP - 205
TYPE EQUIVALENCE1) Coercion 2) Casting 3) ConversionCOERCION Operators require their operands to be of a certain type (similarly expressions require their arguments to be of the same type). In some cases it may be appropriate, when a compiler fi
Sveriges lantbruksuniversitet - MATH - 202
MACM 202 Assignment 3, Spring 2004Luis Goddyn and Michael MonaganThis assignment is worth 10% of your grade. It is due Friday February 18th at beginning of class. A late penalty of 20% will apply for each day late. Do question: Either 1 or 2 , eith
East Los Angeles College - COMP - 205
COMP205 IMPERATIVE LANGUAGES 4. MORE ON BASIC DATA TYPES1) Pointers 2) Type declarations 3) Access/reference values 4) Type renaming/aliasing 5) Subtypes 6) Macro substitutionPOINTERS Pointer variables have as their value an address, i.e. a refer
East Los Angeles College - COMP - 205
COMP205 IMPERATIVE LANGUAGES 13. PROGRAM COMPOSITION II1) Scope a] Ada scope rules b] C scope rules 2) Parameter passing a] Ada parameter modes b) Parameter passing mechanismsSCOPE RULES Scope rules govern the visibility and life time of data ite
Sveriges lantbruksuniversitet - MATH - 443
MATH 443 - Assignment #3Below are short answers (hints) to assigned questions.14EFix one edge, say e, of the convex (n + 1)-gon. For any particular dissection into quadrilaterals consider the quadrilateral &quot;supported&quot; by edge e. The remaining thr
East Los Angeles College - COMP - 205
Comp 205:Comparative Programming Languages FunctionalProgrammingLanguages:MoreLists Recursivedefinitions Listcomprehensions Lecturenotes,exercises,etc.,canbefoundat: www.csc.liv.ac.uk/~grant/Teaching/COMP205/RecursionThetypeoflistsisrecursive
Sveriges lantbruksuniversitet - MATH - 820
TSP Lower BoundsLuis Goddyn, Math 408 We give here two techniques for obtaining lower bounds on TSP instances. That is, for a given instance (V, d), we would like to find the largest possible number t such that (T ) t for every TSP tour T . We firs
Sveriges lantbruksuniversitet - MATH - 445
A SAMPLE MATH DOCUMENTJOHN DOE, MATH 445, FALL 2006This is a sample input le. Comparing it with the output it generates can show you how to produce a simple document of your own. 1. Ordinary Text The ends of words and sentences are marked by space
Sveriges lantbruksuniversitet - MATH - 820
TSP HeuristicsLuis Goddyn, Math 408 There are two types of heuristic methods for finding optimal TSP tours. Scratch methods produce an initial tour which is hopefully fairly close (say 10%) from being optimal. Improvement methods (sometimes called p
Sveriges lantbruksuniversitet - MATH - 445
Homework 7 SolutionsOuterplanar A graph G is outerplanar if it can be drawn in the plane so that all vertices lie on the infinite face. 1. Show that G is outerplanar if and only if G has no K2,3 or K4 minor. Solution: Let G+ be the graph obtained fr
Sveriges lantbruksuniversitet - MATH - 820
Exercises for Math 820 Luis Goddyn 1. Let w : V {0, 1, 2, . . .} be a weighting of the vertices of an undirected graph G = (V, E). Describe an algorithm which either nds an orientation of G for which each vertex v has out-degree exactly + (v) = w(v
Sveriges lantbruksuniversitet - MATH - 443
MATH 443 - Assignment #5Below are short answers (hints) to assigned questions.37ALet C denote the group of rotations of the cube. Following the description of elements of C in Appendix 1 we find that the cycle index of the action of C on the six
Sveriges lantbruksuniversitet - MATH - 445
Higher Surfaces I: embeddings and the torusIn this section, graphs are permitted to have loops and parallel edges. Surface: A surface is a topological space which appears locally like the plane. More precisely, for every point x in the surface, ther
Sveriges lantbruksuniversitet - MATH - 445
Extremal Graph Theory II: more Ramsey TheoryIn this section, graphs are assumed to have no loops or parallel edges. Hypergraph: A hypergraph H consists of a set of vertices, denoted V (H), a set of edges (sometimes called hyperedges), denoted E(H),
Sveriges lantbruksuniversitet - MATH - 445
Homework 5 Solutions1. If G is a 2-connected simple plane graph with minimum degree 3, does it follow that the dual graph G is simple? Give a proof or a counterexample. Solution: The following graph is a counterexample:2. Prove that contracting an
East Los Angeles College - COMP - 213
Time allowed: TWO Hours Answer four questions. If you answer more than four questions, your answer with the lowest mark will be ignored. 1. A Rose Tree is a tree with an integer internal label and a List of subtrees, each of which is a Rose Tree. We