12
1 CS 131 Wrap Up Fall 2008 What Good is Programming?

1 CS 131 Wrap Up Fall 2008 What Good is Programming?

Embed Size (px)

Citation preview

Page 1: 1 CS 131 Wrap Up Fall 2008 What Good is Programming?

1

CS 131 Wrap Up

Fall 2008

What Good is Programming?

Page 2: 1 CS 131 Wrap Up Fall 2008 What Good is Programming?

2

What have you learned?

Dataint

float

char

bool

string

array

struct

arrays of struct

Controlsequential

loop (for, while, while/do)

selection (if, switch)

Organizationfunctions

libraries

Is there anything you can't represent now? yes, more complicated information structures in CS 132

Are functions enough to organize a program? no, we need better ways to encapsulate related functionality

Page 3: 1 CS 131 Wrap Up Fall 2008 What Good is Programming?

3

Who Needs This?

Programming underlies most of what you do

In your worldStreams are fancier

input: mouse, touchpad, laser trigger, voice

output: webpage, pda display, cellphone

Information organization and its exploitation are less visible

do you ever ask how your cellphone knows who has called?

how can find a recipe for crab cakes on the web?

You function at a higher level

Photoshop commands versus processing an array

Google instead of a programming a search

But the underlying programming is what you have learned

Page 4: 1 CS 131 Wrap Up Fall 2008 What Good is Programming?

4

What else is Computer Science?

Database management

how can Amazon find all books by a given author?

how do they know what to suggest you buy?

Web programming

how does their website work so flawlessly?

Software engineering

how is a million line program developed?

Graphics

how can a program rotate an object in 3d?

how can Flash transform one object into another?

Computer engineering

who is building the next generation of computers and gadgets?

IT management

Wells should have wifi everywhere and the net always up, right?

Communications

Page 5: 1 CS 131 Wrap Up Fall 2008 What Good is Programming?

5

Where is Programming on the Web?

HTML for static web pages

JavaScript for client-side programmingthe sayings at the bottom of my page

Towers of Hanoi

PHP/ASP/Perl for server-side programminginterfaces to databases

interfaces to other web services such as credit card processing

Page 6: 1 CS 131 Wrap Up Fall 2008 What Good is Programming?

6

Client(you)

Server(aurora.wells.edu)

(2)

Client SW(IE/Netscape/

Firefox)

Server SW(Apache, IIS)

(1)

(3)

Steps: (1) Client sends an HTTP* request message (clicks on a link) (2) Server processes the request (3) Server sends response (an HTML page) (4) Client browser interprets it

* Hypertext Transfer Protocol, a format for Internet messages

Client/Server Communication (HTML)

Page 7: 1 CS 131 Wrap Up Fall 2008 What Good is Programming?

7

Example: HTML (a markup language to define how to format the content)

<html>

<head>

<title>Wells Open House</title>

</head>

<body>

<h1>Welcome to Wells</h1>

Things to do

<ol>

<li>Take a tour</li>

<li>Go to a class</li>

<li>Eat lunch</li>

</ol>

</body>

</html>

The page: welcome.htm

Page 8: 1 CS 131 Wrap Up Fall 2008 What Good is Programming?

8

)

(2)

Client(you)

Server(e.g. aurora)

Client SW (Netscape/IE/

Firefox)

(1)

(2)

Steps: (1) Client sends HTTP request message (2) Server sends page back to the client (3) Client executes JavaScript commands that are in the page

Client-Side Programming (JavaScript)

JavaScript interpreter

Server SW(IIS,

Apache)

(3)

Page 9: 1 CS 131 Wrap Up Fall 2008 What Good is Programming?

9

Example: JavaScript

<html>

<head> <title>Simple Alert</title>

</head>

<body>

Pick the right door and win a car:

<form>

<input type="button" value="Door 1"

onclick="alert('You got my goat')">

<input type="button" value="Door 2"

onclick="alert('You win a car')">

</form>

</body>

</html>

The page: door.htm

Other examples: checking form input, sudoku

Page 10: 1 CS 131 Wrap Up Fall 2008 What Good is Programming?

10

)

(2)

Client(you)

Server(e.g. my computer)

Client SW (Netscape/IE/

Firefox)

(1)

(3)

Steps: (1) Client sends HTTP request message (2) Server processes request message and executes any client-side programming (e.g. a database interaction) (3) Server sends page back to the client

Server-Side Programming (PHP)

CGI program

JavaScript interpreter CGI

Interface

Server SW(IIS,

Apache)

Page 11: 1 CS 131 Wrap Up Fall 2008 What Good is Programming?

11

Server-Side Programming

• Uses resources that are not on the client computer– a databaseof records

– software for processing them

• Languages commonly used: Perl, ASP, PHP

• Other applications– process an online order

– check the weather

– find driving directions to Wells

– manage your Facebook information

Page 12: 1 CS 131 Wrap Up Fall 2008 What Good is Programming?

12

<?php require_once('Connections/cn330.php');

mysql_select_db($database_cn330, $cn330);

$query_rsUsers = "SELECT * FROM tblUser";

$rsUsers = mysql_query($query_rsUsers, $cn330);

$row_rsUsers = mysql_fetch_assoc($rsUsers);

?>

<html><head><title>Write User Names</title></head><body>

<h2> Display All User Names</h2>

<br />

<?php

do {

echo $row_rsUsers['FullName'];

?>

<br />

<?php

} while ($row_rsUsers = mysql_fetch_assoc($rsUsers));

?>

</body></html> (view the code sent to the browser)

Example: PHP (WriteNames1.php)