How to Program - Computer Science

advertisement
Introduction to Computer Science
CSCI 150 Section 002
Session 1
Dr. Richard J. Bonneau
IONA Technologies
Rich.Bonneau@iona.com
1/16/2003
CSCI 150 Introduction to Computer Science
Slide number: 1
Today’s Agenda
 Handouts
 Personal Introduction
 Course Mechanics and Policies
 Overview of course topics and tools
– Free Pascal - programming language environment
– CircuitMaker - digital design tool and simulator
– P88 - machine level simulator
 Tonight’s Lecture Topics
– Introductory Section
– Chapter 1 - An Introduction to Programming
» Write your first program!
 Summary
 Next Session Preview
1/16/2003
CSCI 150 Introduction to Computer Science
Slide number: 2
Course Handouts
 Survey Sheet –
– please hand in by the end of class
All the rest of handouts are also available on the Course Web Site:
http://mathcs.holycross.edu/~csci150
 Course Overview
 Class Schedule (Tentative!)
–
–
–
–
Dates of classes, lecture topics
Reading assignments from text
Homework assignments – when assigned and when due
Lab sessions
 Session Slides for Lecture #1
 Homework Assignment #1 - due next Thursday - more
on this later
1/16/2003
CSCI 150 Introduction to Computer Science
Slide number: 3
Personal Introduction
 Holy Cross Math Graduate in Math – years ago!
 Ph. D. in Math / Computer Science - from MIT
 Worked in Software & Systems Development at
Raytheon Company, Digital/Compaq Computer
Corporation and now IONA Technologies in
Waltham MA
 Taught CS courses at Holy Cross, Boston
University, Northeastern Univ., and St. Johns High
School in Shrewsbury as well as in industry
 Interested in all forms of software, especially
complex distributed software systems, computer
languages, object-oriented programming,
databases, computer applications of math
1/16/2003
CSCI 150 Introduction to Computer Science
Slide number: 4
Summary of Course Mechanics
 Meeting times
– lectures/labs Tu-Th 6:30 - 7:45,
– 3-4 scheduled labs
– flexible schedule due to business travel!
 Course Information including slides, assignments,
additional notes and resources, also will be on the web (sooner
or later) at
http://mathcs.holycross.edu/~csci150
 Course Policies
–
–
–
–
Course Text and associated resources
Reading assignments
Homework assignments
Quizzes, mid-term and final exams
 Office Hours
– Probably Tu Th 4:00 - 6:00 – but call ahead!
– Swords 339
1/16/2003
CSCI 150 Introduction to Computer Science
Slide number: 5
My Personal Teaching Style
 Powerpoint slides with whiteboard explanations where
necessary
– Slides may be available on the section web site before each class but
certainly after each class
 In-class and on-computer examples of real executing
programs and real circuits
 Most course materials will be available on the web
 I accept questions - any time - but may defer answer till
later!!
 Before/after class and office hours for more in-depth
questions and help
1/16/2003
CSCI 150 Introduction to Computer Science
Slide number: 6
Course Policies
 Reading assignments - keep up or else
you will get far behind - fast
 Most Textbook Exercises - you should be
able to do these - but they will NOT be
collected or graded
 Homework assignments
–
–
–
–
Programming exercises, graded, returned material, etc.
Some right from textbook exercises
Designs of circuits in second half of course
Web page construction near end of course
 Grading policies
– Final grade a function of
» Homework assignments - how many and how well
» Quiz scores
» Midterm exam
» Final exam
– Occasional opportunity for extra credit
1/16/2003
CSCI 150 Introduction to Computer Science
Slide number: 7
Summary of Course Goals
 Major Goal: Become exposed to Computer
Science from the user/programmer level all the
way down to the hardware designer/chip level!
 To understand how programs work
– enough to write simple ones on your own
 To understand how computers work
– enough to write better programs on your own
 To acquaint you with many areas of
computer science and how they might affect
you - no matter what you end up doing
1/16/2003
CSCI 150 Introduction to Computer Science
Slide number: 8
Non Goals of Course
 Web Surfing!!
 Using major software products such as:
–
–
–
–
Word Processors
Spreadsheets
Drawing programs
Games!
===========================
 We are here to learn Computer Science :
How to Program
and
How a Computer can
Execute Programs
1/16/2003
CSCI 150 Introduction to Computer Science
Software
Hardware
Slide number: 9
Major Tools for Course Work
 Part I - Programming
– Free Pascal System
– Write, compile, execute and debug Pascal programs
 Part II - Computer design
Let’s see
these
programs
in action!!
– Circuit Maker (5.0) – A Digital Simulation System
– design simple digital electrical circuits
– test/simulate circuits
 Part III - Program Execution
– P88 program to show a real program as it executes
within the computer itself!
1/16/2003
CSCI 150 Introduction to Computer Science
Slide number: 10
Overview of the course – main topics
 Decision Trees
 Text Manipulation
and Algorithms
 Numerical
Computing and
Functions
 Top Down
Programming and
Database Methods
 Software
Engineering
1/16/2003
 Electric Circuits &
Computer
Architecture
 Language
Translation
 Virtual Environments
for Computing – AKA
Operating Systems
 Computer
Communications:
Networks and
Internet and the
Web and Browsers
CSCI 150 Introduction to Computer Science
Slide number: 11
Introductory Chapter
 Topic : Studying Computer Science
 Major Concepts/Terms Presented
– Computer science involves the study of “recipes” and ways of
carrying them out – both in hardware and software
– Fancy/technical word for Recipes = algorithms
– Writing the recipe/algorithm in a computer language (e.g. Pascal) so
that it can be executed - Code – used as both a noun and a verb
– Creating recipe and writing in a computer language = programming
– The resulting written recipe/algorithm is a program
1/16/2003
CSCI 150 Introduction to Computer Science
Slide number: 12
Chapter 1 Major Topics
 Good News
 Decision Trees
 Getting Started in Programming
 Reading and Storing Data
 Programming Decision Trees
 Arrow Notation and its Uses
1/16/2003
CSCI 150 Introduction to Computer Science
Tonight
Next sessions
Slide number: 13
Chapter 1 - Good News
 Computers can simplify doing some tasks
 ‘Work amplification’ = more work accomplished
with less effort
 Real world examples of things to program
through decision trees
1/16/2003
CSCI 150 Introduction to Computer Science
Slide number: 14
Chapter 1 – Coding Decision Trees
 Helps in translating making decisions into a
programming exercise
 Methodology:
– Draw boxes with questions in them
– Draw branches between boxes using arrows to represent
yes/no responses or other options
 See samples in book
–
–
–
–
–
–
book recommendation decision tree – next slide
medical advice decision tree – slide after
fortune telling decision tree
Seagull classification
Income tax helper
Nim - game playing - a little more complicated
 See Exercises in the text
– p. 10 - #1-3
1/16/2003
CSCI 150 Introduction to Computer Science
Slide number: 15
Book Recommendation Decision Tree
programming
I recommend “Oh
Pascal” by D. Cooper
Are you interested in
programming or
theoretical issues?
Yes
A fine overview is
given in the book
“Algorithmics” by D.
Harel
theory
Do you wish a
mathematical
approach?
No
programming
Would you prefer a
book that concentrates
on programming or do
you desire a general
overview of computer
science?
overview
From pages 2-3
in textbook
1/16/2003
CSCI 150 Introduction to Computer Science
A good place to start is
with “Karel the Robot”
by R. Pattis
You might enjoy “Great
Ideas in Computer
Science” by A.
Biermann
Slide number: 16
Medical Advice Decision Tree
Yes
I recommend trying
aspirin.
Are they mild and
infrequent?
Headaches
You should consult
your doctor.
No
What is your medical
problem?
Stomach aches
morning
Do they occur often?
When do these occur?
Coughing and
wheezing
Do you use alcoholic
beverages?
evening
After meals
From page 5
in textbook
1/16/2003
How long has this been
on?
CSCI going
150 Introduction
to Computer Science
Do you use alcoholic
beverages?
Slide number: 17
Why a “tree”?
 Normally a tree grows upward from the ground
 In our case, the tree starts with the starting of
root node on the far left and with branches
extending from left to right
 Each new question box or node is known as a
decision node
 When you get to the farthest node to the right,
you get to a final answer or leaf node
 This is one example of a computer “data
structure” used to represent complex
information or processing within a computer
system
1/16/2003
CSCI 150 Introduction to Computer Science
Slide number: 18
Chapter 1 –
Getting Started in Programming
 Computer program
 Program Structure
 Statements
 Program Execution
 Statement Meaning and Structure
 Exercises
1/16/2003
CSCI 150 Introduction to Computer Science
Slide number: 19
Computer program
 Program: A list of commands or statements that
can be carried out by a computer
 The written program or part of it = code
 Sample program FirstCode - See Next Slide
 What is needed to run/execute a program??
–
–
–
–
computer
software to process/parse/understand the pascal program
manual to run the computer
knowledgeable friend or professor
 Software to process the programs - commonly
called a compiler
 Instructions on how to run computer/compiler from labs and Q & A and samples in class
1/16/2003
CSCI 150 Introduction to Computer Science
Slide number: 20
First Pascal Program
program FirstCode;
begin
writeln(‘
Great Ideas
writeln(‘
in
writeln(‘ Computer Science
readln;
end.
1/16/2003
CSCI 150 Introduction to Computer Science
’);
’);
’);
Slide number: 21
Program Structure
All Pascal programs
look like this!!!
Primary components of a program
Header with keyword
program ...
1) keyword
2) series of
begin
statements
... ;
each followed by a
semicolon
3) keyword with
period at end
1/16/2003
header
}
body
end.
CSCI 150 Introduction to Computer Science
Slide number: 22
Statements
 An individual command to the computer
 Like a sentence in English, except ends with
“;” not a period “.”
 In FirstCode example – there are 4 statements
– three are writeln (short for ‘write line’) - a command
to write some information to the computer screen
– last is readln (short for ‘read line’) - a command to
read input into the program from the user
1/16/2003
CSCI 150 Introduction to Computer Science
Slide number: 23
Program Execution
 The computer is responsible for executing in
sequence the commands or statements in the
program
 Usually sequentially, unless something stops it
from doing that
 In our simple cases, simply in a sequential
fashion (we will see more variations later!)
1/16/2003
CSCI 150 Introduction to Computer Science
Slide number: 24
Statement Meaning and Structure
writeln(‘ Great Ideas ’);
 Two major parts:
– command syntax writeln(
);
– program data
‘
Great Ideas’
» Writeln statements can have different program data supplied
 Compiler detects syntax errors
– misspelled keyword
– bad format of program and its statements
– E.g. missing semicolons
 Execution of program detects data or logic errors
 Spacing allowed (and ignored) in most cases - to make it
more readable - also blank lines are OK
 No spacing allowed within a keyword, e.g. begin or end or
Program
 Second sample program: SecondCode
1/16/2003
CSCI 150 Introduction to Computer Science
Slide number: 25
Second Sample Program
program SecondCode;
begin
writeln(‘*******************’);
writeln(‘*
*’);
writeln(‘* Decision Tress *’);
writeln(‘*
*’);
writeln(‘*******************’);
readln;
end.
1/16/2003
CSCI 150 Introduction to Computer Science
Slide number: 26
First homework assignment
 See handout and/or class Web Pages for first
assignment - due next Thursday
 Mixture of handwritten (typed?) responses, programs
on diskette and printed output!
 Read the assignment carefully and follow it precisely
 Feel free to ask questions about assignment and/or any
of the lecture notes – at the end of class, or via email, or
at office hours
1/16/2003
CSCI 150 Introduction to Computer Science
Slide number: 27
Summary of Session
 Key concepts:
– algorithm, code, program, programming, compiler
– Pascal program form - header, keywords, statements, syntax
 What is coming up next class
– Lecture - declaring and using variables in Pascal
– Lab - using Free Pascal to write, run programs
 Reading assignment
– For this session (you’re already behind!!)
» Introduction in book
» Chapter 1 - pp. 1 - 15
– For next session
» Chapter 1 - pp. 16 - 22 - Storing/retrieving data
1/16/2003
CSCI 150 Introduction to Computer Science
Slide number: 28
Next Session - First Lab Session
Tuesday – Jan. 21 – 6:30 – 7:45 PM
1st Computer Lecture/Lab Session – Haberlin 408 – across the courtyard from the classroom
 Learn about
– Lecture: How to start declaring and using variables in your
programs
– Free Pascal development environment
 Goals:
– Write and execute your first Pascal program(s)!!
– Learn about how to edit, save, print programs
– Gain knowledge useful to complete your first homework
assignment
1/16/2003
CSCI 150 Introduction to Computer Science
Slide number: 29
End of Session 1
Thanks for listening
Feel free to ask questions
about the course after
class
Have a good weekend !!
1/16/2003
CSCI 150 Introduction to Computer Science
Slide number: 30
Download