웹 프로그래밍 및 실습 (Web Programming & Practice) 기초 프로그래밍 최 미정 강원대학교 IT 대학 컴퓨터과학전공.

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

Air Force Institute of Technology Electrical and Computer Engineering
Computer Programming in C Chapter 년 가을학기 부산대학교 전자전기정보컴퓨터공학부.
Operators and Expressions Operators are symbols that produce a result based on some rules. Examples: +, -, =, > and
Pemrograman Dasar - Data Types1 OPERATOR. Pemrograman Dasar - Data Types2 Arithmetic operator  + - * /  / operator denotes integer division if both.
5/17/ Programming Constructs... There are several types of programming constructs in JAVA. - If-else construct or ternary operator - while - do-while.
PHP Intro/Overview Squirrel Book pages Server-side Scripting Everything you need to know in one slide 1.Web server (with PHP “plug-in”) gets a.
Java Syntax Primitive data types Operators Control statements.
COMP 14 Introduction to Programming Miguel A. Otaduy May 18, 2004.
COMP 110 Introduction to Programming Mr. Joshua Stough September 19, 2007.
12-2 Know how if and switch C statements control the sequence of execution of statements. Be able to use relational and logical operators in the conditional.
PHP Basics 1 ICS213, 1 / 2011 Dr. Seung Hwan Kang 1.
2015 년 봄학기 강원대학교 컴퓨터과학전공 문양세 이산수학 (Discrete Mathematics) 집합과 연산 (Sets and Operations)
COMPUTER SCIENCE, KOREA UNIVERSITY Chapter2 Lexical Elements, Operators,and the C System Rim, Hae-Chang Department of Computer Science and Engineering.
Python  By: Ben Blake, Andrew Dzambo, Paul Flanagan.
프로그래밍 기초와 실습 Chapter 7 Enumeration Types and typedef.
An Introduction to PHP The University of Tennessee at Chattanooga C. Daniel Chase “An introduction to basic PHP use with a focus on the power of dynamic.
NMED 3850 A Advanced Online Design January 26, 2010 V. Mahadevan.
Chap 3 – PHP Quick Start COMP RL Professor Mattos.
© 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5/e Starting Out with C++: Early Objects 5 th Edition Chapter 2 C++
Computer Programming in C Chapter 년 가을학기 부산대학교 전자전기정보컴퓨터공학부.
BIM313 – Advanced Programming Techniques Flow Control 1.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
S ystem P rogrammers' A ssociation for R esearching C omputer S ystems 3. Operators SPARCS JAVA Study.
CONTROL STRUCTURE The if, elseif, and else & switch Statements 1.
PHP Conditional Statements Conditional statements in PHP are used to perform different actions based on different conditions. Conditional Statements Very.
PHP 프로그래밍. Let ’ s start test
1 CS428 Web Engineering Lecture 20 Control Structures, Loops and Pointers File Uploading Function (PHP - III)
A First C Program /* Print a Message */ #include main() { printf("This is a test!\n"); } The program is compiled and run as cc pg32.c  a.out  This is.
S ystem P rogrammers' A ssociation for R esearching C omputer S ystems Visual Basic Study #2 April 06, 2004 Kim, Ki Young
PHP Teresa Worner. What is it? PHP: Hypertext Preprocessor server-side scripting language open source cross-platform compatible with almost all servers.php.php3.phtml.
PHP PHP: Hypertext Preprocesor Personal Home Page Tools.
Review the following: if-else One branch if Conditional operators Logical operators Switch statement Conditional expression operator Nested ifs if –else.
User-defined Functions CSED421: Database Systems Labs.
4.1 Object Operations operators Dot (. ) and new operate on objects The assignment operator ( = ) Arithmetic operators + - * / % Unary operators.
1 PHP Introduction Chapter 1. Syntax and language constructs.
Department of Electrical and Computer Engineering Introduction to C++: Primitive Data Types, Libraries and Operations By Hector M Lugo-Cordero August 27,
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
프로그래밍 기초와 실습 Chapter 6 The Fundamental Data Types.
C++ Basics. Compilation What does compilation do? g++ hello.cpp g++ -o hello.cpp hello.
ICT Introduction to Programming Chapter 4 – Control Structures I.
Review TEST 2 Chapters 4,5,7. QUESTION For which type of operands does the == operator always work correctly: (a) int, (b) double, or (c) String?
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
쉽게 풀어쓴 C언어 Express 제14장 포인터 활용 C Express.
OperatorstMyn1 Operators An operator is something that you feed with one or more values (or expressions, in programming jargon) which yields another value.
BOOLEAN OPERATIONS AND CONDITIONALS CHAPTER 20 1.
CSI 3125, Preliminaries, page 1 Control Statements.
Go by Example Closures ~ Errors , Sam Jo.
2: Basics Basics Programming C# © 2003 DevelopMentor, Inc. 12/1/2003.
PHP5 STUDY # SPARCS 구성모. 공부하기전에  Xming  Xlaunch  Windows 용 Xserver 프리웨어.
1 PHP Intro PHP Introduction After this lecture, you should be able to: Know the fundamental concepts of Web Scripting Languages in general, PHP in particular.
2012 년 봄학기 강원대학교 컴퓨터과학전공 문양세 이산수학 (Discrete Mathematics) 수학적 귀납법 (Mathematical Induction)
 2003 Prentice Hall, Inc. All rights reserved. 1 Basic C++ Programming.
Session 2 Operators, Decisions and Loops. Objectives Operators Casting data Decision marking structures Loops break, continue, return.
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
Operators. Perl has MANY operators. –Covered in Chapter 3 of Camel –perldoc perlop Many operators have numeric and string version –remember Perl will.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 실 습실 습 4.
Unit – 3 Control structures. Condition Statements 1.If.…..else :- Has someone ever told you, "if you work hard, then you will succeed"? And what happens.
Introduction to PHP and MySQL (Creating Database-Driven Websites)
Hello world . Variables A variable consists of a name that you can choose, preceded by a dollar ($) sign. Some legal variables.
Shyam Gurram Graduate Assistant
Expressions and Control Flow in PHP
2.0 FUNDAMENTALS OF JAVA PROGRAMMING LANGUAGE
Expressions and Control Flow in JavaScript
PHP Intro/Overview Bird Book pages 1-11,
Recap Week 2 and 3.
Differences between Java and JavaScript
Presentation transcript:

웹 프로그래밍 및 실습 (Web Programming & Practice) 기초 프로그래밍 최 미정 강원대학교 IT 대학 컴퓨터과학전공

Web Programming Page 2 Source Code 모든 PHP 프로그램은 혹은 안에서 사용해야 함 모든 문장은 ; 으로 끝남 웹서버가 이고, 파일 이름이 print_test.php 라 하면, 를 호출 print 함수의 경우 () 를 생략하기도 함 Hello PHP 구성 (1/2) 기초 프로그래밍 <?PHP print (“Hello PHP”); print “Hello PHP”; ?>

Web Programming Page 3 수행 결과 (hello1.php) Hello PHP 구성 (2/2) 기초 프로그래밍

Web Programming Page 4 Source Code 두 번째 줄에 ; 표기가 빠져 있음 print 라는 함수가 prin 으로 잘못 코딩되어 있음  Parse error 발생 에러 발생 (1/2) 기초 프로그래밍 <?PHP prin “Hello PHP” ?>

Web Programming Page 5 수행 결과 (hello2.php, hello3.php) 에러 발생 (2/2) 기초 프로그래밍

Web Programming Page 6 프로그램에 대한 이해를 돕기 위한 글을 적음  comment1.php 프로그램 작성자, 프로그램 작성 의도, 프로그램 동작 형태 등을 적음 주석 (Comment) (1/2) 기초 프로그래밍 <?PHP print “Hello PHP”; // 이 문장은 Hello PHP 를 출력하는 문장입니다 /* 이 문장은 Hello PHP 를 출력하는 문장입니다. */ ?> C/C++ 와 매우 유사함 한 줄 Comment: // 혹은 # 를 사용 여러 줄 Comment: /* 표기와 */ 표기 사용 Comment 를 잘 활용하여 프로그램의 가치를 높일 수 있음

Web Programming Page 7 잘못된 Comment 의 예 (Nesting 이 허용되지 않는 경우 )  comment2.php 주석 (Comment) (2/2) 기초 프로그래밍 올바른 Comment 의 예 (Nesting 이 허용되는 경우 )  comment3.php <?PHP /* 처음 주석의 시작입니다. /* 두번째 주석의 시작입니다. 두번째 주석의 끝입니다. */ 처음 주석의 끝입니다. */ ?> <?PHP /* 처음 주석의 시작입니다. // 두번째 주석입니다. // 세번째 주석입니다. // 네번째 주석입니다. 처음 주석의 끝입니다. */ ?>

Web Programming Page 8 변수 (Variables) (1/5) 기초 프로그래밍 변수 정보 ( 값 ) 를 저장 이름과 형식을 가지고 있음 (e.g., $age) PHP 에서 변수의 특성 변수는 ‘$’ 문자로 시작한다. 변수의 이름은 영문 대문자 (A-Z), 소문자 (a-z), 숫자 (0-9), ‘_’ 으로 이루어진다. ‘$’ 다음의 첫 문자로 숫자를 사용할 수 없다. PHP 에서는 변수 형을 선언 (declaration) 하지 않고 사용한다. PHP 변수의 예 $age $cyber21 $Student_Name $a_b_c $_NUMBER PHP 변수가 아닌 예 $21c cyber $Student-id

Web Programming Page 9 변수 (Variables) (2/5) 기초 프로그래밍 변수의 종류 불리언 (Boolean) 정수형 (integer) 실수형 (floating point numbers, real numbers) 문자열 (string) 배열 (array) 객체 (object) 변수형 강도 (strength) PHP 는 형 강도가 매우 약하며, 변수에 할당되는 값에 따라 형이 결정됨 예 :$totalamount = ; // integer type $totalamount = “hello”; // string type 변수형 변환 (casting) Casting operator 사용 : (int), (float), (double), (string), (array), (object) 예 :$totalqty = 0; $totalamount = (double)$totalqty;

Web Programming Page 10 변수 (Variables) (3/5) 기초 프로그래밍 변수형 검사 및 설정 gettype() 함수는 변수형을 스트링 (“integer”, “double”, …) 으로 반환함 settype() 함수는 변수의 형을 주어진 형으로 바꾸어 줌 예 : $a = 56;  var_type1.php print gettype($a); // integer settype($a, “double”); print gettype($a); // double 변수형 확인 함수 (true or false 를 리턴함 )  var_type2.php is_array() is_double(), is_float(), is_real() // 모두 같은 함수임 is_long(), is_int(), is_integer() // 모두 같은 함수임 is_string() is_object() string gettype(mixed var); bool settype(mixed var, string type);

Web Programming Page 11 변수 (Variables) (4/5) 기초 프로그래밍 변수에 값 대입 <?PHP $sum = ; // integer type print $sum; ?> <?PHP $sum = 12.3 – 42.72; // real(float) type) print $sum; ?>

Web Programming Page 12 변수 (Variables) (5/5) 기초 프로그래밍 정수형 변수의 표현 (int_rep.php) <?PHP $value = ; print $value. “ ”; $value = $value + 1; // $value = print $value. “ ”; $value = $value + 1; // $value = print $value. “ ”; $value = $value + 1; // $value = print $value. “ ”; $value = $value + 1; // $value = print $value. “ ”; $value = $value + 1; // $value = print $value. “ ”; ?>

Web Programming Page 13 연산자 및 수식 계산 (1/2) 기초 프로그래밍 연산자의 종류 및 의미 사용법의 미의 미 oprd1 + oprd2 orpd1 에 ordp2 를 더하기 oprd1 – orpd2 orpd1 에서 ordp2 를 빼기 oprd1 * orpd2 orpd1 에 ordp2 를 곱하기 orpd1 / orpd2 orpd1 에서 ordp2 를 나누기 orpd1 % orpd2 orpd1 에서 ordp2 를 나눈 나머지

Web Programming Page 14 연산자 및 수식 계산 (2/2) 기초 프로그래밍 사칙 연산자와 나머지 연산자의 사용 예  oprd.php <?PHP $result = 9 + 5; print “9 + 5 = $result ”; $result = 9 – 5; print “9 – 5 = $result ”; $result = 9 * 5; print “9 * 5 = $result ”; $result = 9 / 5; print “9 / 5 = $result ”; $result = 9 % 5; print “9 % 5 = $result ”; ?>

Web Programming Page 15 기타 연산자 (1/2) 기초 프로그래밍 증가 연산자, 감소 연산자 <?PHP $temp++;// $temp = $temp + 1; --$i;// $i = $i – 1; $k++;// $k = $k + 1; ?> +=-=*=/=%= (e.g., $temp += 3;  $temp = $temp + 3;) 대입 연산자

Web Programming Page 16 기타 연산자 (2/2) 기초 프로그래밍 증가 연산자의 사용 예 (inc_dec.php) <?PHP $temp = 1; if($temp++ == 1) print "temp in the 1st if() is 1"; else print "temp in the 1st if() is 2"; $temp = 1; if(++$temp == 1) print ", and temp in 2nd if() is 1."; else print ", and temp in the 2nd if() is 2."; ?>

Web Programming Page 17 스트링 연산자 기초 프로그래밍 Concatenation 을 수행하는 “.” 연산자 사용 두 문자열을 연결하는 연산자임 (concat.php) <? $city = “in Chunchon”; $name1 = “Kangwon ”; $name2 = “National University “; print $name1.$name2.$city; ?>

Web Programming Page 18 수학적 함수 (1/2) 기초 프로그래밍 삼각함수 (sin, cos, …) 는 기본적으로 Radian 사용 (2  = 360  ) 로그함수 log() 는 기본적으로 자연 로그 ( 밑이 e) 이며, 대수 로그 ( 밑이 10) 는 log10() 을 사용한다. 삼각함수의 사용 예 (sin_cos1.php) <?PHP $result = sin(M_PI / 6); print “sin(30) = $result ”; $result = cos(M_PI / 6); print “cos(30) = $result ”; $result = tan(M_PI / 6); print “tan(30) = $result ”; $result = asin(0.5); print “asin(0.5) = $result ”; $result = acos( ); print “acos( ) = $result ”; $result = atan( ); print “atan ( ) = $result ”; ?>

Web Programming Page 19 수학적 함수 (2/2) 기초 프로그래밍 Degree 값 (360 도 기준 값 ) 사용  deg2rad() 함수 활용  sin_cos2.php log(), log10(), sqrt() 사용 예  sin_cos2.php <?PHP $degree = 30; $radian = deg2rad($degree); $result = sin($radian); print “sin(30) = $result”; ?> <?PHP $result = log (10); print “log(10) = $result ”; $result = log10 (10); print “log10(10) = $result ”; $result = sqrt (49); print “sqrt(49) = $result”; ?>

Web Programming Page 20 Bitwise 연산자 기초 프로그래밍 사용법이 름이 름의 미의 미 orpd1 & orpd2 AND orpd1 과 orpd2 의 비트 모두 1 이면 연산의 결과는 1 이다. orpd1 | orpd2 OR orpd1 또는 orpd2 의 비트가 1 이면 연산의 결과는 1 이다. orpd1 ^ orpd2 XOR 한 Operand 의 비트는 1 이고 나머지 Operand 의 비 트가 0 이면 연산의 결과는 1 이다. ~orpd1 NOT orpd1 의 비트가 0 이면 연산의 결과는 1 이고, oprd1 의 비트가 1 이면 연산의 결과는 0 이다. orpd1 << orpd2 Shift Left orpd1 을 왼쪽으로 orpd2 번 Shift 한다. orpd1 >> orpd2 Shift Right orpd1 을 오른쪽으로 orpd2 번 Shift 한다. 사용 예  bitwise.php

Web Programming Page 21 연산자 우선순위 기초 프로그래밍 결합성연산자 left, or leftxor leftand left= += -= *= /=.= %= != ~= >= left?: left|| left&& left| ^ & non-associative== != non-associative >= left > left+ -. left* / % right! ~ (int) (double) (string) (array) right[ non-associativenew

Web Programming Page 22 if-else 구문 (1/2) 기초 프로그래밍 주어진 조건에 따라서 서로 다른 문장을 수행 문법 if(condition) statement; if(condition) { statement1; statement2; } if(condition) statement; else statement; if(condition1) statement; elseif(condition2) statement; elseif(condition3) statement; elseif(condition4) statement; else statement;

Web Programming Page 23 if-else 구문 (2/2) 기초 프로그래밍 if-else 구문의 예 (ifelse.php) <?PHP $temp1 = 1; $temp2 = 2; if($temp1 == 1 && $temp2 == 1) print "condition of if() is true."; elseif($temp1 == 1 && $temp2 == 2) { print "condition of elseif() is true. "; print "temp 1 is 1 and temp2 is 2."; } else print "condition of else is true."; ?>

Web Programming Page 24 비교 연산자 (1/2) 기초 프로그래밍 연산자의 미의 미 == 같다 (equal). != 같지 않다 (not equal). < 작다 (less than). > 크다 (greater than). <= 작거나 같다 (less than or equal to). >= 크거나 같다 (greater than or equal to). === 동일하다 (identical). 두 Operand 가 서로 같고 형식 (type) 이 같다.

Web Programming Page 25 비교 연산자 (2/2) 기초 프로그래밍 <?PHP $a = 123; $b = 456; if ($a == $b) print “ 두 값이 같습니다. ”; if ($a != $b) print “ 두 값이 같지 않습니다. ”; if ($a < $b) print “$a 값이 $b 값보다 작습니다. ”; if ($a > $b) print “$a 값이 $b 값보다 큽니다. ”; if ($a <= $b) print “$a 값이 $b 값보다 작거나 같습니다. ”; if ($a >= $b) print “$a 값이 $b 값보다 크거나 같습니다. ”; if ($a === $b) print “$a 값이 $b 값과 동일합니다. ”; ?> 비교 연산자 사용 예 (comp_op.php)

Web Programming Page 26 삼항 연산자 (? :) 기초 프로그래밍 (condition) ? statement_true : statement_false; (cond_st.php) <?PHP $num = 5; (($num % 2) == 1) ? print “ 홀수 ” : print “ 짝수 ”; print “ ”; $num = 8; (($num % 2) == 1) ? print “ 홀수 ” : print “ 짝수 ”; ?>

Web Programming Page 27 논리 연산자 기초 프로그래밍 사용법이름의 미의 미 !orpd not Operand 의 값이 FALSE 이면 연산 결과가 TRUE, Operand 의 값이 TRUE 이면 연산 결과가 FALSE orpd1 && orpd2 and 두 Operand 의 값이 모두 TRUE 일 때만 연산 결 과가 TRUE, 그 외에는 연산 결과가 FALSE orpd1 || orpd2 or 두 Operand 의 값이 모두 FALSE 일 때만 연산 결 과가 FALSE, 그 외에는 연산 결과가 TRUE orpd1 xor orpd2 xor 하나의 Operand 는 TRUE 나머지 Operand 는 FALSE 일 때 연산 결과가 TRUE, 그 외에는 연산 결과가 FALSE 사용 예  logicop.php

Web Programming Page 28 while 구문 (1/2) 기초 프로그래밍 문법 while 구문의 사용 예 (while.php) while (expression) statement <?PHP $i = 1; $sum = 0; while ($i < 101) { $sum = $sum + $i; $i = $i + 1; } print “The sum from 1 to 100 is $sum”; ?>

Web Programming Page 29 while 구문 (2/2) 기초 프로그래밍 무한 루프의 예 <?PHP $i = 0; $value = 1; while (TRUE) { $value = $value * 3; $i = $i + 1; if ($value > 10000) break; } print $i; ?>

Web Programming Page 30 do-while 구문 기초 프로그래밍 문법 do-while 구문의 사용 예 (do-while.php) do statement while (expression); <?PHP $i = 1; do { $j = $i * 5; $i = $i + 1; print $j. “ ”; } while ($j < 100); ?>

Web Programming Page 31 함수 정의 (1/3) 기초 프로그래밍 문법 add() 함수의 정의  func_add.php function func_name($var1, $var2,...) { statements; } <?PHP function add($x, $y) { $sum = $x + $y; return $sum; } $result = add (3, 5); print $result; ?>

Web Programming Page 32 함수 정의 (2/3) 기초 프로그래밍 Default Values (func_def.php) <?PHP function my_log ($arg, $base = 2) { $result = log ($arg) / log ($base); return $result; } print “log2(10) = ”. my_log(10, 2). “ ”; print “log10(100) = ”. my_log(100, 10). “ ”; print “log2(8) = ”. my_log(8, 2). “ ”; print “ ”; print “log2(8) = ”. my_log(8). “ ”; ?>

Web Programming Page 33 <?PHP function my_print () { $args = func_get_args (); foreach ($args as $arg) print “ 파라미터 : $arg ”; } my_print (“Apple”, “Orange”, “Pear”, “Banana”, “Cherry”); ?> 함수 정의 (3/3) 기초 프로그래밍 func_get_args() 함수 활용 (func_arg.php)