introduction to programming

Post on 26-Feb-2016

19 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

Introduction to Programming. Doman’s Lecture CSCI101 . What is programming?. - PowerPoint PPT Presentation

TRANSCRIPT

Introduction to Programming

Doman’s LectureCSCI101

Method or interface to do this:PROGRAMMING LANGUAGESExample: Java:

Public class helloWorld {Public static void main ( ) {system.out.println(“Hello World”) }}

Instruct a computer

Example: C++ #include<iostream>using namespace std;

int main(){cout << “Hello World” << endl;}

Instruct a computer

Example: html

<html><body><p> Hello World </p></body></html>

Instruct a computer

Example Python

print “Hello World!”

Instruct a computer

Programming is a creative process done by programmers to instruct a computer on how to do a task. (http://cplus.about.com)

What is programming?

Puzzles

Problem solving

What is programming?

Your car has blue smoke coming from the tailpipe, is idling roughly and has lost fuel efficiency.

How do you solve it?

Problem Solving

Unbreakable rules about problems or the way in which problems must be solved.

Car problem constraints: Cost of repair How long before you need it fixed No new tools be purchases

Constraints

Programming language Platform Performance Memory footprint

User/customer specific constraints Design constraints.

Common Programming Constraints

Figure out the steps to take to solve the problem

Be able to list the steps Be able to repeat the steps

You can NOT change the rules (constraints) to get something solved!

Problem solving

PROBLEM: HOW TO CROSS THE RIVER?

A farmer with a fox, a goose and a sack of corn needs to cross a river. The farmer has a rowboat, but there is only room for the farmer and one of his three items. Unfortunately, both the fox and the goose are hungry. The fox cannot be left alone with the goose; the goose cannot be left alone with the grain. How does the farmer get everything across the river?

Puzzle: Fox, goose, grain

Constraints Only one item at a time in the boat Can’t leave fox with goose Can’t leave goose with grain

Operations Carry the fox to the far side of the river Carry the goose to the far side of the river Carry the grain to the far side of the river

Puzzle: Fox, goose, grain

An association between a value and a symbolic name

Sentence = “Hello World!” Print Sentence

Variables

Like a recipe or a blueprint

A repeatable set of instructions that tell the computer to do something to reach a goal.

Algorithm

Abstract the problem Be more general in describing the way we

will solve the problem

Concept: VariableVariable is the item that can goes into the boat: fox, goose or grainLet item vary between fox, goose or grain

Rephrase the problem

Puzzle: Fox, goose, grain

Constraints Only one item at a time in the boat Can’t leave item(fox) with item(goose) Can’t leave item(goose) with item(grain)

Operations Row the boat from one shore to the other If the boat is empty, load an item on the boat If the boat is full, take the item off the boat

Puzzle: Fox, goose, grain

Puzzle: Fox, goose, grain

Puzzle: Sudoku

3 4 78 16 2 5

5 8

4 7

1 97 3

3 4 78 9 16 2 5

Constraints

Techniques Start with the easiest Try something…… be prepared to change if it doesn’t work. Try something else

Puzzle: Soduko

Problem Solving Have a plan Generalize the problem

Restate the problem Start with what you know Divide the problem Look for analogies or patterns Experiment!!!

THINK like a programmer!

top related