cmpt 102 introduction to scientific computer programming
Post on 09-Mar-2016
60 Views
Preview:
DESCRIPTION
TRANSCRIPT
1 © Janice Regan, CMPT 102, Sept. 2006
CMPT 102Introduction to Scientific Computer Programming
Course Organization
© Janice Regan, CMPT 102, Sept. 2006 2
CMPT 102: Introduction to Scientific Computer Programming
Monday, Wednesday, Friday 9:30-10:20 Textbook:
C Program Design for EngineersAuthors: Jeri R. Hanly, Elliot B. Koffman
Additional References: Engineering Problem Solving with C, 3rd edition
Author: Delores M. Etter The C Programming Language
Authors: B. W. Kernighan, D. M. Ritchie
© Janice Regan, CMPT 102, Sept. 2006 3
Class web-site All the information discussed today and more
can always be found on the class web-site To find the class web site go to
http://www.cs.sfu.ca/CourseCentral Select Course Home pages Select the Homepage for CMPT 102
Course Central is also a useful link to abundant information useful to students taking a computing science course
© Janice Regan, CMPT 102, Sept. 2006 4
http://www.cs.sfu.ca/CourseCentral
© Janice Regan, CMPT 102, Sept. 2006 5
Course selection page
Click here to go
to CMPT102 website
© Janice Regan, CMPT 102, Sept. 2006 6
CMPT 102 Website
© Janice Regan, CMPT 102, Sept. 2006 7
My availability
© Janice Regan, CMPT 102, Sept. 2006 8
Exams Dates, Course Evaluation
© Janice Regan, CMPT 102, Sept. 2006 9
Exams and Evaluation
© Janice Regan, CMPT 102, Sept. 2006 10
Evaluation Assignments: 30% Weekly Quizzes: 15%
No quiz in week of midterm, week of Thanksgiving or week of Remembrance day
Lab Problems: 5% Practice Problems: no credit Midterm Examination: 15% Final Examination: 35%
© Janice Regan, CMPT 102, Sept. 2006 11
Assignments Four assignments
Each assignment worth 7.5% of your course grade
Assignments are to be completed individually Problems similar to the assignments will
appear on the midterm and the final. Help is available during weekly lab hours Complete solutions will be posted
© Janice Regan, CMPT 102, Sept. 2006 12
Lab Problems Four short lab problems Each lab problem is worth 1.25% of your final grade Practice Problems: no credit BUT valuable experience that will be useful when
completing lab problems and assignments
There are no Labs in the first week of classes (Sept. 5-8) Lab hours are not held on statutory holidays (Thanksgiving and Remembrance Day)
Weekly Quizzes: 15% One question on material covered in labs Monday-Tuesday of the same week Each quiz marked out of 17, worth 1.7% of the final grade All quiz results will be included in your final grade
Midterm: 15% Final: 35%
© Janice Regan, CMPT 102, Sept. 2006 13
Quizzes During each Wednesday’s lecture, you will be
asked to answer one question based on material covered in the lab exercises that week.
You will be asked to write a short concise paragraph of 10-15 sentences, explaining a concept or method, or a short piece of code.
You will be given 10-15 minutes to answer. Your answer will be graded out of 17 (each quiz is
worth 1.7% of your final grade)
© Janice Regan, CMPT 102, Sept. 2006 14
Midterm and Final One 50 minute in class midterm One 3 hour final examination 35% short answer problems 65% longer problems that utilize several
important concepts and require integration of those concepts.
A sample exam, including solutions, will be posted two weeks before the midterm and two weeks before the final exam
© Janice Regan, CMPT 102, Sept. 2006 15
Assignments, Labs, Solutions
© Janice Regan, CMPT 102, Sept. 2006 16
Important Dates
© Janice Regan, CMPT 102, Sept. 2006 17
Assignments At least two weeks before the due date the
assignment will be posted on the website Assignments must be completed individually Assignments will require you to combine and use
many concepts and tools you have learned Assignments will be much more demanding than lab
problems or practice problems Complete solutions to all assignments will be posted Information of proper preparation of assignments and
lab problems is available on the class website.
© Janice Regan, CMPT 102, Sept. 2006 18
Labs On or before Friday of each week problems will
be posted for the next week. These problems will be identified as Lab Problems: To be completed individually or in a
small group (up to four students) Submitted for grading
Practice Problems: A chance to use a new idea in a simple application, before you need to integrate multiple ideas into assignments. Collaboration is encouraged Not submitted for grading
Complete solutions to all problems will be posted
© Janice Regan, CMPT 102, Sept. 2006 19
Grading Information Assignments and Lab Problems should be:
submitted electronically using the submission server submitted in hard copy to the 102 drop box
Bonus points (10%) are available for submitting assignments more than 72 hours early
No late assignments or lab problems will be accepted
Unofficial grades will be available on GradeBook Login: your SFU computer ID, your student number
as password. Find link on Course Central
© Janice Regan, CMPT 102, Sept. 2006 20
Where to submit assignments: 1
© Janice Regan, CMPT 102, Sept. 2006 21
Where to submit assignments: 2
Submission drop boxes
© Janice Regan, CMPT 102, Sept. 2006 22
Required Readings, Notes
© Janice Regan, CMPT 102, Sept. 2006 23
Readings and Notes
© Janice Regan, CMPT 102, Sept. 2006 24
Academic Honesty
© Janice Regan, CMPT 102, Sept. 2006 25
Academic HonestyRead the
policy
© Janice Regan, CMPT 102, Sept. 2006 26
Getting Started If you have not already done so activate
your SFU computing account (CCN, Campus Computing Network account.) Use your own machine at home, or go to the
assignment lab (AQ 3145) Email regarding the class will be sent to your
Campus Account, so check it regularly Steps to activate your account …
© Janice Regan, CMPT 102, Sept. 2006 27
Activating your CCN account (1)
Select mySFU
© Janice Regan, CMPT 102, Sept. 2006 28
Activating your CCN Account (2)
Select Apply for ID, the follow the instructions. You will need your student ID and your TeleReg PIN
© Janice Regan, CMPT 102, Sept. 2006 29
Computing Science Instructional Labs (CSIL) The CSIL LINUX lab is available for your use at
all times beginning in the second week of classes. (ASB 9838)
At particular times the instructor and/or TA will be available in the lab to answer your questions. Instructor: Mon. 1:30-3:00 PM,
Tue: 9:00-10:30 AM TA: Tue: 10:00 – 10:30 AM . TBA
© Janice Regan, CMPT 102, Sept. 2006 30
Finding CSIL labs: 1
© Janice Regan, CMPT 102, Sept. 2006 31
Finding CSIL labs: 2
CSIL Labs
© Janice Regan, CMPT 102, Sept. 2006 32
Access to CSIL CSIL is protected by a security card
access system As a student in a computing science course
you are eligible to have a security access card for CSIL
If you are pre-registered your access card may be picked up from the card office at traffic and security (there is a $15 refundable deposit and a $3 processing fee)
© Janice Regan, CMPT 102, Sept. 2006 33
CSIL Rules Before you can use any of the computers in the
CSIL you must sign and return an ethics form. By signing the ethics form you indicate that you have
read and agree to abide by the SFU and CSIL regulations regarding use of computing resources and computer labs.
Links to these policies can be found on the class website or on Course Central
You can return your ethics forms during next class, or directly to the computing science main office.
© Janice Regan, CMPT 102, Sept. 2006 34
http://www.cs.sfu.ca/CourseCentral
Select to reach Policies
© Janice Regan, CMPT 102, Sept. 2006 35
CSIL page
IMPORTANTRead thePoliciesBefore Signing
Your Ethics form
© Janice Regan, CMPT 102, Sept. 2006 36
Getting Started in CSIL Before you try programming in CSIL read
the information provided for you Read the general information pages Browse the FAQs, Now you are ready to start
Your CSIL computer ID and password and the ID an password you use for your SFU email account.
© Janice Regan, CMPT 102, Sept. 2006 37
CSIL page
Read thegeneral
information
Browse The
FAQs
© Janice Regan, CMPT 102, Sept. 2006 38
Labs and using CSIL The computers in CSIL are available 24/7 At some times your instructor or TA will be
available to answer questions At some times OPEN LAB TA’s will be
available to answer questions. A list of TA’s presently in the lab will be
posted on the white board in CSIL.
© Janice Regan, CMPT 102, Sept. 2006 39
Optional Lab Hours Attendance at optional Lab hours is strongly
encouraged Lab Hours are held in the LINUX area of CSIL labs Lab Hours provide an opportunity to work with others
sharing knowledge and experience. Lab Hours give you an opportunity to ask the
instructor or TA one on one questions about problems and assignments.
Lab Hours help you learn the required concepts one by one and allow you to ask questions to assure you understand each one.
© Janice Regan, CMPT 102, Sept. 2006 40
Operating System In the CSIL labs you will be using
computers that run the LINUX operating system
In the first optional lab hours there will be tutorials on how to use the LINUX operating system (1 per hour)
The tutorial will also be posted so you can try it yourself at another time
© Janice Regan, CMPT 102, Sept. 2006 41
Reading Assignment Visit and read the information on the class
website Be sure you can find
Posted notes Reading assignments for each lecture Assignment due dates Instructions on using the CSIL labs Instructions on using your own computer for
assignments Have any questions ready for next lecture
42 © Janice Regan, CMPT 102, Sept. 2006
CMPT 102Introduction to Scientific Computer Programming
Chapter 1: Computer Components
© Janice Regan, CMPT 102, Sept. 2006 43
Hardware and Software A computer is a machine designed to perform
operations specified with a set of instructions called a program.
Hardware refers to the computer equipment. keyboard, mouse, terminal, hard disk, printer, CPA
Software refers to the programs that describe the steps we want the computer to perform.
© Janice Regan, CMPT 102, Sept. 2006 44
CPU
Computer Hardware CPU –
Central processing unit
ALU – Arithmetic and logic unit
ROM – Read only memory
RAM – Random access memory
InternalMemory
ExternalMemory
Input OutputProcessor
ALU
Cache/Memory
© Janice Regan, CMPT 102, Sept. 2006 45
Software: Operating System A system of computer programs that control the
interaction of the user and the computer hardware. Examples: Linux, Windows, QNX,…
Purposes of the operating system Controls communication between input and output
hardware and each process running in the computer. Directs and orders all operations of the computer Allocates and shares resources (memory,processor…) Controls access to resources and data (security) Provides a user interface (UI) and/or graphical user
interface (GUI) Stores and accesses data and applications
© Janice Regan, CMPT 102, Sept. 2006 46
Example: Command Line UI Windows Command Prompt
© Janice Regan, CMPT 102, Sept. 2006 47
Example: Graphical UI (GUI) Windows explorer
© Janice Regan, CMPT 102, Sept. 2006 48
Computer Software: Applications
Application Software (Software Tools) Word processors (Microsoft Word, WordPerfect, ...) Spreadsheet programs (Excel, Lotus1-2-3, ...) Computer games Communication software (email, chat, web
browser…) Telecommunication software (VOIP, …)
© Janice Regan, CMPT 102, Sept. 2006 49
Computer Software: Languages Some Computer Languages
Machine language (machine instruction set) assembly language high level languages
C, C++, Ada, Fortran, Basic, Java Do YOU know of any others? mathematical computation tools (MATLAB,
Mathematica, ...) Application software is written using computer
languages.
© Janice Regan, CMPT 102, Sept. 2006 50
Machine language Each type of processor (like Pentium 4, Athalon,
Z80, …) has its own instruction set Each instruction in an instruction set does a
single thing like access a piece of data, add two pieces of data, compare two pieces of data …
Each instruction is represented by a unique number This # may be different for different instruction sets, but no two instructions in the same instruction set will have the same #
© Janice Regan, CMPT 102, Sept. 2006 51
Machine Language programs In machine language a program is a list of
instructions Each instruction is represented by a number Inside the memory of the computer each
number is represented in binary (as a constant length string of 1’s and 0’s)
The long string of 0’s and 1’s is easy for the computer to understand and very difficult for a Human to read or write
© Janice Regan, CMPT 102, Sept. 2006 52
Assembler Assembler languages make it easier for
the programmer. Assembler is easier for humans to read/write The numbers that identify each of the
instructions in the instruction set are replaced with mnemonics like ADD, CMP, …
The code, written using these mnemonics is written into a text file.
© Janice Regan, CMPT 102, Sept. 2006 53
Assembler Programs The code for an Assembler program is written
into a text file. The computer read 1’s and 0’s not text How do we translate to machine readable form?
A computer program called a compiler is used to translate the text file (called a source file) containing the assembler code into machine readable code
The compiler writes a binary file containing the machine readable code (called an object file)
© Janice Regan, CMPT 102, Sept. 2006 54
Programs in High Level Languages Assembler is easier to read/write than machine
language. It is still very cumbersome High level languages are easier to write than
assembler The compiler is more complex, but that is a tool you
use, not one you write In this course we will learn the language C The rest of today's discussion is equally
applicable to C or to any other compiled language (C++, Fortran, …)
© Janice Regan, CMPT 102, Sept. 2006 55
Writing your program
Editor, Type inyour program
Source File
Text saved on hard disk
CompilerTranslate text into
Machine Readable code
© Janice Regan, CMPT 102, Sept. 2006 56
Source files Contains the text you type into a text editor The text is a program The program is a list of instructions written in a
special Human readable language (C) The program can be translated, from the Human
readable language (in source file) to a machine readable language (in object file), by a compiler
A compiler is a special piece of software used to translate from source files to object files
© Janice Regan, CMPT 102, Sept. 2006 57
Source files Source File:
Write using a text editor like Kate Do not write your code using a word
processor like Microsoft Word. A word processor will save in a special format.
The compiler reads only text, not special formats.
Beware: your text does not differentiate between a word processor and an editor
© Janice Regan, CMPT 102, Sept. 2006 58
Perfect Code? Finding Errors 1 It is highly unlikely than any of us will always
write perfect code that contains no errors How do we find errors? Are there different kinds of errors? Yes A computer program can contain syntax errors.
semantic errors, or logical errors When and how can we detect and correct
errors? Compile errors Link errors Run Time Errors
© Janice Regan, CMPT 102, Sept. 2006 59
Syntax Errors A computer program can contain syntax errors A computer language follows simple rules
how words and punctuation of different types may be combined.
In English syntax is similar to grammatical structure The compiler for a high level language can
detect errors that break those simple of syntax (syntax errors)
Syntax Errors are usually detected at compile time
© Janice Regan, CMPT 102, Sept. 2006 60
Semantic Errors A computer program can contain semantic
errors Semantics relates to the meaning of the words
in a sentence or a computer language command Just like a grammatically correct English
sentence can be nonsense, a syntactically correct high level computer language command can also contain semantic errors
Some semantic errors may be found by the compiler, some will be found when the program is linked, some may be found at run time
© Janice Regan, CMPT 102, Sept. 2006 61
Logical Errors When your program completes but gives
an unexpected answer it usually means there is a error in the logic in your solution of the problem
Logic errors can also cause a program to fail part way through execution
© Janice Regan, CMPT 102, Sept. 2006 62
Writing your programEditor, Type inyour programSource File
CompilerTranslation toMachine code
Syntax or Semantic Errors, Compiler Generates error Messages. To help us find and Correct errors in the
Source File
Object File
Binary, machine readable file
Syntactically Correct
code
Code with
syntax
Or semantic
errors
Editor, CorrectSyntax Errors
© Janice Regan, CMPT 102, Sept. 2006 63
Perfect Code? Finding Errors 2 If your code contains compile time errors is it
correct? NOT NECESSARILY How do we find the remaining errors? Use a tool that does more checks than the
compiler (splint). Move on to linking the code to libraries etc.
The linker resolves references, words in your program than are defined elsewhere
Errors occur when the definitions cannot be found Errors occur when the use of the word does not
correspond to the definition
© Janice Regan, CMPT 102, Sept. 2006 64
Linking your programEditor, Enter
program
Source File
(Text)
Compile
Find Syntax and
SemanticErrors
Object File
(binary)
CorrectErrors
LinkerResolves
References among
object files
Other Object FilesLibraries …
Executable File(load module)
(binary)
Semantic Errors Reported: Finds words with no defined meaning.
Code has linker errors
© Janice Regan, CMPT 102, Sept. 2006 65
Perfect Code? Finding Errors 3 If your code compiles and contains no
errors that can be found by the linker (or splint) is it correct? NOT NECESSARILY
How do we find the remaining logic and semantic errors?
When you run your executable program it may not complete (may or may not
generate error message) It may complete and give the wrong answer
© Janice Regan, CMPT 102, Sept. 2006 66
Loading/Running your programEditor, Enter
program
Source File
(Text)
Compile
Find Syntax and some
SemanticErrors
Object File
(binary)
CorrectErrors
LinkerResolves
References Other
Object FilesExecutable File
(binary)
Link Errors Reported:
LoaderCopies
ExecutableAnd Runs
Input data
output resultsCPU
© Janice Regan, CMPT 102, Sept. 2006 67
Summary:Executing a Computer Program
Compiler Converts a source file (containing your human
readable program in C) to and object file (computer readable binary file)
Linker Converts object program to executable program
Compile Link/load ExecuteC languageProgram inText file(source file)
MachinelanguageProgram In binary file(object file)
Program output
Input data
Otherobject files
© Janice Regan, CMPT 102, Sept. 2006 68
Summary: Types of Errors Syntax errors
Errors in syntax, how words are combined and used reported by the compiler or splint
Semantic errors Errors in the meaning of words,
Reported by the linker (linker errors) Reported by the compiler (compile time errors) Found at execution time (run-time errors)
Logic errors Errors causing the incorrect results, not reported Errors causing program failure (run-time errors)
top related