CMPT 102 Introduction to Scientific Computer Programming Course

  • Slides: 68
Download presentation
CMPT 102 Introduction to Scientific Computer Programming Course Organization 12/22/2021 © Janice Regan, CMPT

CMPT 102 Introduction to Scientific Computer Programming Course Organization 12/22/2021 © Janice Regan, CMPT 102, Sept. 2006 0

CMPT 102: Introduction to Scientific Computer Programming ] Monday, Wednesday, Friday 9: 30 -10:

CMPT 102: Introduction to Scientific Computer Programming ] Monday, Wednesday, Friday 9: 30 -10: 20 ] Textbook: S C Program Design for Engineers Authors: Jeri R. Hanly, Elliot B. Koffman ] Additional References: S Engineering Problem Solving with C, 3 rd edition Author: Delores M. Etter S The C Programming Language Authors: B. W. Kernighan, D. M. Ritchie © Janice Regan, CMPT 102, Sept. 2006 1

Class web-site ] All the information discussed today and more can always be found

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/Course. Central S Select Course Home pages S 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 2

http: //www. cs. sfu. ca/Course. Central © Janice Regan, CMPT 102, Sept. 2006 3

http: //www. cs. sfu. ca/Course. Central © Janice Regan, CMPT 102, Sept. 2006 3

Course selection page Click here to go to CMPT 10 2 website © Janice

Course selection page Click here to go to CMPT 10 2 website © Janice Regan, CMPT 102, Sept. 2006 4

CMPT 102 Website © Janice Regan, CMPT 102, Sept. 2006 5

CMPT 102 Website © Janice Regan, CMPT 102, Sept. 2006 5

My availability © Janice Regan, CMPT 102, Sept. 2006 6

My availability © Janice Regan, CMPT 102, Sept. 2006 6

Exams Dates, Course Evaluation © Janice Regan, CMPT 102, Sept. 2006 7

Exams Dates, Course Evaluation © Janice Regan, CMPT 102, Sept. 2006 7

Exams and Evaluation © Janice Regan, CMPT 102, Sept. 2006 8

Exams and Evaluation © Janice Regan, CMPT 102, Sept. 2006 8

Evaluation ] Assignments: 30% ] Weekly Quizzes: 15% S No quiz in week of

Evaluation ] Assignments: 30% ] Weekly Quizzes: 15% S 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 9

Assignments ] Four assignments S Each assignment worth 7. 5% of your course grade

Assignments ] Four assignments S Each assignment worth 7. 5% of your course grade S Assignments are to be completed individually S Problems similar to the assignments will appear on the midterm and the final. S Help is available during weekly lab hours S Complete solutions will be posted © Janice Regan, CMPT 102, Sept. 2006 10

Lab Problems ] Four short lab problems ] Each lab problem is worth 1.

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 © Janice Regan, CMPT 102, Sept. 2006 11

Quizzes ] During each Wednesday’s lecture, you will be asked to answer one question

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 12

Midterm and Final One 50 minute in class midterm One 3 hour final examination

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 13

Assignments, Labs, Solutions © Janice Regan, CMPT 102, Sept. 2006 14

Assignments, Labs, Solutions © Janice Regan, CMPT 102, Sept. 2006 14

Important Dates © Janice Regan, CMPT 102, Sept. 2006 15

Important Dates © Janice Regan, CMPT 102, Sept. 2006 15

Assignments ] At least two weeks before the due date the assignment will be

Assignments ] At least two weeks before the due date the assignment will be posted on the website S Assignments must be completed individually S Assignments will require you to combine and use many concepts and tools you have learned S Assignments will be much more demanding than lab problems or practice problems S Complete solutions to all assignments will be posted S Information of proper preparation of assignments and lab problems is available on the class website. © Janice Regan, CMPT 102, Sept. 2006 16

Labs ] On or before Friday of each week problems will be posted for

Labs ] On or before Friday of each week problems will be posted for the next week. These problems will be identified as S Lab Problems: To be completed individually or in a small group (up to four students) l Submitted for grading S Practice Problems: A chance to use a new idea in a simple application, before you need to integrate multiple ideas into assignments. l l Collaboration is encouraged Not submitted for grading S Complete solutions to all problems will be posted © Janice Regan, CMPT 102, Sept. 2006 17

Grading Information ] Assignments and Lab Problems should be: S submitted electronically using the

Grading Information ] Assignments and Lab Problems should be: S submitted electronically using the submission server S 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 Grade. Book S Login: your SFU computer ID, your student number as password. Find link on Course Central © Janice Regan, CMPT 102, Sept. 2006 18

Where to submit assignments: 1 © Janice Regan, CMPT 102, Sept. 2006 19

Where to submit assignments: 1 © Janice Regan, CMPT 102, Sept. 2006 19

Where to submit assignments: 2 Submission drop boxes © Janice Regan, CMPT 102, Sept.

Where to submit assignments: 2 Submission drop boxes © Janice Regan, CMPT 102, Sept. 2006 20

Required Readings, Notes © Janice Regan, CMPT 102, Sept. 2006 21

Required Readings, Notes © Janice Regan, CMPT 102, Sept. 2006 21

Readings and Notes © Janice Regan, CMPT 102, Sept. 2006 22

Readings and Notes © Janice Regan, CMPT 102, Sept. 2006 22

Academic Honesty © Janice Regan, CMPT 102, Sept. 2006 23

Academic Honesty © Janice Regan, CMPT 102, Sept. 2006 23

Academic Honesty Read the policy © Janice Regan, CMPT 102, Sept. 2006 24

Academic Honesty Read the policy © Janice Regan, CMPT 102, Sept. 2006 24

Getting Started ] If you have not already done so activate your SFU computing

Getting Started ] If you have not already done so activate your SFU computing account (CCN, Campus Computing Network account. ) S Use your own machine at home, or go to the assignment lab (AQ 3145) S Email regarding the class will be sent to your Campus Account, so check it regularly S Steps to activate your account … © Janice Regan, CMPT 102, Sept. 2006 25

Activating your CCN account (1) Select my. SFU © Janice Regan, CMPT 102, Sept.

Activating your CCN account (1) Select my. SFU © Janice Regan, CMPT 102, Sept. 2006 26

Activating your CCN Account (2) Select Apply for ID, the follow the instructions. You

Activating your CCN Account (2) Select Apply for ID, the follow the instructions. You will need your student ID and your Tele. Reg PIN © Janice Regan, CMPT 102, Sept. 2006 27

Computing Science Instructional Labs (CSIL) ] The CSIL LINUX lab is available for your

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. S Instructor: S TA: S. Mon. 1: 30 -3: 00 PM, Tue: 9: 00 -10: 30 AM Tue: 10: 00 – 10: 30 AM TBA © Janice Regan, CMPT 102, Sept. 2006 28

Finding CSIL labs: 1 © Janice Regan, CMPT 102, Sept. 2006 29

Finding CSIL labs: 1 © Janice Regan, CMPT 102, Sept. 2006 29

Finding CSIL labs: 2 CSIL Labs © Janice Regan, CMPT 102, Sept. 2006 30

Finding CSIL labs: 2 CSIL Labs © Janice Regan, CMPT 102, Sept. 2006 30

Access to CSIL ] CSIL is protected by a security card access system S

Access to CSIL ] CSIL is protected by a security card access system S As a student in a computing science course you are eligible to have a security access card for CSIL S 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 31

CSIL Rules ] Before you can use any of the computers in the CSIL

CSIL Rules ] Before you can use any of the computers in the CSIL you must sign and return an ethics form. S 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. S Links to these policies can be found on the class website or on Course Central S You can return your ethics forms during next class, or directly to the computing science main office. © Janice Regan, CMPT 102, Sept. 2006 32

http: //www. cs. sfu. ca/Course. Central Select to reach Policies © Janice Regan, CMPT

http: //www. cs. sfu. ca/Course. Central Select to reach Policies © Janice Regan, CMPT 102, Sept. 2006 33

CSIL page IMPORTANT Read the Policies Before Signing Your Ethics form © Janice Regan,

CSIL page IMPORTANT Read the Policies Before Signing Your Ethics form © Janice Regan, CMPT 102, Sept. 2006 34

Getting Started in CSIL ] Before you try programming in CSIL read the information

Getting Started in CSIL ] Before you try programming in CSIL read the information provided for you S Read the general information pages S Browse the FAQs, S 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 35

CSIL page Read the general information Browse The FAQs © Janice Regan, CMPT 102,

CSIL page Read the general information Browse The FAQs © Janice Regan, CMPT 102, Sept. 2006 36

Labs and using CSIL ] The computers in CSIL are available 24/7 ] At

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 37

Optional Lab Hours ] Attendance at optional Lab hours is strongly encouraged S Lab

Optional Lab Hours ] Attendance at optional Lab hours is strongly encouraged S Lab Hours are held in the LINUX area of CSIL labs S Lab Hours provide an opportunity to work with others sharing knowledge and experience. S Lab Hours give you an opportunity to ask the instructor or TA one on one questions about problems and assignments. S 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 38

Operating System ] In the CSIL labs you will be using computers that run

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 39

Reading Assignment ] Visit and read the information on the class website ] Be

Reading Assignment ] Visit and read the information on the class website ] Be sure you can find S Posted notes S Reading assignments for each lecture S Assignment due dates S Instructions on using the CSIL labs S Instructions on using your own computer for assignments ] Have any questions ready for next lecture © Janice Regan, CMPT 102, Sept. 2006 40

CMPT 102 Introduction to Scientific Computer Programming Chapter 1: Computer Components 12/22/2021 © Janice

CMPT 102 Introduction to Scientific Computer Programming Chapter 1: Computer Components 12/22/2021 © Janice Regan, CMPT 102, Sept. 2006 41

Hardware and Software ] A computer is a machine designed to perform operations specified

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. S 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 42

Computer Hardware ] CPU – S Central processing unit Internal Memory ] ALU –

Computer Hardware ] CPU – S Central processing unit Internal Memory ] ALU – External Memory S Arithmetic and logic unit ] ROM – S Read only memory ] RAM – S Random access memory © Janice Regan, CMPT 102, Sept. 2006 Input Processor Output ALU Cache/ Memory CPU 43

Software: Operating System ] A system of computer programs that control the interaction of

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 S Controls communication between input and output S S S 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 44

Example: Command Line UI ] Windows Command Prompt © Janice Regan, CMPT 102, Sept.

Example: Command Line UI ] Windows Command Prompt © Janice Regan, CMPT 102, Sept. 2006 45

Example: Graphical UI (GUI) ] Windows explorer © Janice Regan, CMPT 102, Sept. 2006

Example: Graphical UI (GUI) ] Windows explorer © Janice Regan, CMPT 102, Sept. 2006 46

Computer Software: Applications ] Application Software (Software Tools) S Word processors (Microsoft Word, Word.

Computer Software: Applications ] Application Software (Software Tools) S Word processors (Microsoft Word, Word. Perfect, . . . ) S Spreadsheet programs (Excel, Lotus 1 -2 -3, . . . ) S Computer games S Communication software (email, chat, web browser…) S Telecommunication software (VOIP, …) © Janice Regan, CMPT 102, Sept. 2006 47

Computer Software: Languages ] Some Computer Languages S Machine language (machine instruction set) S

Computer Software: Languages ] Some Computer Languages S Machine language (machine instruction set) S assembly language S high level languages l C, C++, Ada, Fortran, Basic, Java l Do YOU know of any others? l mathematical computation tools (MATLAB, Mathematica, . . . ) ] Application software is written using computer languages. © Janice Regan, CMPT 102, Sept. 2006 48

Machine language ] Each type of processor (like Pentium 4, Athalon, Z 80, …)

Machine language ] Each type of processor (like Pentium 4, Athalon, Z 80, …) 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 49

Machine Language programs ] In machine language a program is a list of instructions

Machine Language programs ] In machine language a program is a list of instructions S Each instruction is represented by a number S Inside the memory of the computer each number is represented in binary (as a constant length string of 1’s and 0’s) S The long string of 0’s and 1’s is easy for the computer to understand very difficult for a Human to read or write © Janice Regan, CMPT 102, Sept. 2006 50

Assembler ] Assembler languages make it easier for the programmer. S Assembler is easier

Assembler ] Assembler languages make it easier for the programmer. S Assembler is easier for humans to read/write S The numbers that identify each of the instructions in the instruction set are replaced with mnemonics like ADD, CMP, … S The code, written using these mnemonics is written into a text file. © Janice Regan, CMPT 102, Sept. 2006 51

Assembler Programs ] The code for an Assembler program is written into a text

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? S 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 S The compiler writes a binary file containing the machine readable code (called an object file) © Janice Regan, CMPT 102, Sept. 2006 52

Programs in High Level Languages ] Assembler is easier to read/write than machine language.

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 S 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 53

Writing your program Editor, Type in your program Source File Text saved on hard

Writing your program Editor, Type in your program Source File Text saved on hard disk Compiler Translate text into Machine Readable code © Janice Regan, CMPT 102, Sept. 2006 54

Source files ] Contains the text you type into a text editor ] The

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 55

Source files ] Source File: S Write using a text editor like Kate S

Source files ] Source File: S Write using a text editor like Kate S Do not write your code using a word processor like Microsoft Word. A word processor will save in a special format. S 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 56

Perfect Code? Finding Errors 1 ] It is highly unlikely than any of us

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? S Compile errors S Link errors S Run Time Errors © Janice Regan, CMPT 102, Sept. 2006 57

Syntax Errors ] A computer program can contain syntax errors ] A computer language

Syntax Errors ] A computer program can contain syntax errors ] A computer language follows simple rules S how words and punctuation of different types may be combined. S 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 58

Semantic Errors ] A computer program can contain semantic errors ] Semantics relates to

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 59

Logical Errors ] When your program completes but gives an unexpected answer it usually

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 60

Writing your program Editor, Correct Syntax Errors Source File Editor, Type in your program

Writing your program Editor, Correct Syntax Errors Source File Editor, Type in your program Code Syntax or Semantic Errors, with Syntactically Object File Compiler Generates error syntax Correct Compiler Messages. To help us find Translation to Binary, Or code and Correct errors in the Machine code machine readable file semantic Source File errors © Janice Regan, CMPT 102, Sept. 2006 61

Perfect Code? Finding Errors 2 ] If your code contains compile time errors is

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. S The linker resolves references, words in your program than are defined elsewhere S Errors occur when the definitions cannot be found S Errors occur when the use of the word does not correspond to the definition © Janice Regan, CMPT 102, Sept. 2006 62

Linking your program Correct Errors Find Syntax and Semantic. Errors Source File (Text) Editor,

Linking your program Correct Errors Find Syntax and Semantic. Errors Source File (Text) Editor, Enter program Compile Object File (binary) Code has linker errors Semantic Errors Reported: Finds words with no defined meaning. © Janice Regan, CMPT 102, Sept. 2006 Other Object Files Libraries … Linker Resolves References among object files Executable File (load module) (binary) 63

Perfect Code? Finding Errors 3 ] If your code compiles and contains no errors

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 S it may not complete (may or may not generate error message) S It may complete and give the wrong answer © Janice Regan, CMPT 102, Sept. 2006 64

Loading/Running your program Editor, Enter program Source File (Text) Correct Errors Find Syntax and

Loading/Running your program Editor, Enter program Source File (Text) Correct Errors Find Syntax and some Semantic. Errors Object File (binary) Compile Input data CPU output results Link Errors Reported: Other Object Files Linker Resolves References Executable File (binary) © Janice Regan, CMPT 102, Sept. 2006 Loader Copies Executable And Runs 65

Summary: Executing a Computer Program Input data C language Program in Text file (source

Summary: Executing a Computer Program Input data C language Program in Text file (source file) Compile ] Compiler Machine language Program In binary file (object file) Link/load Execute Program output Other object files S Converts a source file (containing your human readable program in C) to and object file (computer readable binary file) ] Linker S Converts object program to executable program © Janice Regan, CMPT 102, Sept. 2006 66

Summary: Types of Errors ] Syntax errors S Errors in syntax, how words are

Summary: Types of Errors ] Syntax errors S Errors in syntax, how words are combined and used l reported by the compiler or splint ] Semantic errors S Errors in the meaning of words, l Reported by the linker (linker errors) l Reported by the compiler (compile time errors) l Found at execution time (run-time errors) ] Logic errors l l Errors causing the incorrect results, not reported Errors causing program failure (run-time errors) © Janice Regan, CMPT 102, Sept. 2006 67