Welcome to CS 100
Download
Report
Transcript Welcome to CS 100
Welcome to CS 100
Goal: Learn to write intelligible, correct
computer programs
Language: Java (but the language
should not be the primary focus)
Software: CodeWarrior
Plan: Compressed, intense version of a
full-semester course. Be sure to keep
up!
CS 100
Lecture 1
1
Course Staff
Instructor: Lynette Millett, millett@cs
TAs:
– Wei Tsang Ooi, [email protected]
– Alan Renaud, [email protected]
– David Welte, [email protected]
Consultants:
– Rocky Chen, [email protected], Young Ho
Cho, [email protected], Amanda Waack,
[email protected]
CS 100
Lecture 1
2
Logistics
Lectures every day (Mon-Fri)
Roughly two assignments per week
– NO LATE ASSIGNMENTS ACCEPTED
0 or more short quizzes per week
Partners: 1 partner allowed where
specified
Highest level of academic integrity
expected
CS 100
Lecture 1
3
Logistics continued
Office hours: as noted on web
One prelim: Monday, July 19, 1999
Final Grades:
– 50% assignments
– 25% prelim
– 25% final
First Assignment due this THURSDAY
CS 100
Lecture 1
4
When Turning in Assignments:
No late assignments accepted
Your name and Cornell ID# should be on
frontpage (in comments, if a program)
For programming assignments turn in
printout of source code, sample output and
disk
For written assignments: please type. TAs
reserve right not to grade illegible
homework.
CS 100
Lecture 1
5
Main Concepts Today
What is an algorithm?
Method and method call
Reading this week: Chapter 1 (skim),
Chapters 2 and 3
Handouts
CS 100
Lecture 1
6
Algorithm
A set of instructions for performing
some task that is:
– precise
– unambiguous
– effective
– abstract
In other words: well-specified
CS 100
Lecture 1
7
Examples of Algorithms
A recipe for chocolate mousse
Given this list of integers, tell me which
ones are even
Play a game of tic-tac-toe in a way that
you never lose
Find your Star Wars name
CS 100
Lecture 1
8
Star Wars example:
First SW name: Write
first 3 letters of your
last name then
attach first 2 letters
of your first name
Last SW name: Write
first 2 letters of
mother’s maiden
name and attact first
3 letters of
hometown
CS 100
Lynette Millett born in
Norway, ME to I.
(Rogers) Millett
becomes:
Mil+Ly = Milly
Ro+Nor = Ronor
Lecture 1
9
Ambiguous Algorithm
Take two pieces of bread
Put peanut butter on one side of one
piece
Put jelly on one side of the other piece
Put the pieces together
Output of this algorithm is. . . .
CS 100
Lecture 1
10
A Messy Sandwich
Why?
The algorithm did not specify that the
pieces of bread should be put together
so that the peanut butter and jelly are
on the inside
Computers do exactly what they’re
told or, worse, something undefined
Precision is important
Any other ambiguities in that example?
CS 100
Lecture 1
11
Programs
A program is an algorithm written in some
language: English, C++, Java, . .
“Computer program” is a program in a
computer language such as Java
Abstraction vs. Representation
– Algorithm -- Program
– Number -- Numeral
– Object having “threeness” -- 3, III, three, |||
CS 100
Lecture 1
12
How does it work?
Algorithm given as sequence of
instructions to execute in order
In Java, each instruction is called a
statement
Common statement in Java is a method
call or method invocation
But, what’s a method?
“Method”, “procedure”, “function” often
used interchangeably
CS 100
Lecture 1
13
Sample Method Heading
// Draw a line from point (x1, y1) to point
//(x2, y2)
public void drawLine
(int x1, int y1, int x2, int y2)
– Comment: explains the method precisely in
English. Always begin with “//”
– Prefix modifiers public, void (will explain later)
– Method name: drawLine
– Parameters: x1, y1, x2, y2, and their types: int
CS 100
Lecture 1
14
Method Call
// Draw a line from point (x1, y1) to point
//(x2, y2)
public void drawLine
(int x1, int y1, int x2, int y2)
Call: drawLine(3, 5, 1, 1);
Command to be executed: Draw a line
from point (3,5) to point (1,1)
CS 100
Lecture 1
15
Another Example
// Print the largest of x, y and z
public void printMax
(int x, int y, int z)
Call: printMax(7, 83, 20*5-52);
Command to be executed: print the
largest of 7, 83 and 20*5-52
Note: the method name “printMax” has
no meaning to Java. It is just a string of
characters. We could have called it aaa,
pm, mymethod, etc. . .
CS 100
Lecture 1
16
Yet Another Example
// In the output window, skip a line and print
// “Hello!”
public void printHello()
Call: printHello();
Command to be executed: In the
output window, skip a line and print
“Hello!”
CS 100
Lecture 1
17
Points to Remember
A method can have zero parameters
Syntax of a method call is:
name
(
list of 0 or more arguments separated
by commas
)
;
CS 100
Lecture 1
18
What does the Method do?
To find out what a method does:
– Make a copy of the specification (the
comment in the heading)
– replace all parameters by the appropriate
arguments in the call
This assumes the programmer wrote
good comments
CS 100
Lecture 1
19
Understanding Methods
The way we have understood these
methods relies on comments that are
– precise
– understandable
– correct
Your programs will be judged partially
on how well your documentation is
CS 100
Lecture 1
20
Reading
From now on, consult syllabus and/or
webpage. We will try to point out
appropriate readings from the text, but
you should use the text as a reference
when solving homework problems.
URL:
http://www.cs.cornell.edu/cs100-su99
CS 100
Lecture 1
21
Assignment W1
Series of questions requiring written
answers
Should be fairly straightforward if
you’ve done the reading
Due Thursday July 1 at the beginning of
class
CS 100
Lecture 1
22
Registration Form
Please fill out and turn in before you
leave class today.
CS 100
Lecture 1
23