computer science 1620 syllabus, introduction. instructors lectures robert benkoczi office d520...
Post on 19-Dec-2015
229 views
TRANSCRIPT
Computer Science 1620
Syllabus, Introduction
Instructors
LecturesRobert Benkoczi Office D520 403-329-2298 [email protected]
Labs, tutorialsArie Bomhof Office C510 403-329-5171 [email protected]
Textbook
C++ ProgrammingProgram Design Including Data Structures
4th Edition (this is a picture of 3rd ed)
By: D.S. Malik
Copies have been ordered for the bookstore.
Not the first time this book has been used (so used copies may be out there).
Topics
Topics: (approximate listing and order, scheduling depends on time constraints)
1. Introduction to Programming
2. C++ Basics data types expressions variables basic input/output
3. Control Structures selection, iteration
4. Functions parameter passing, return values, prototyping, reference parameters
5. Arrays & Strings
6. Structures & Classes
Grading Scheme
Programming Assignments (8) 32% Midterm exam 20% Final Exam 40% 1 lab quiz 3% 2 class quizzes 5% CodeLab homework (bonus) 8%
Conversion to Letter Grades (may be revised):
95% or higher A+ 70% or higher C+
90% or higher A 66% or higher C
86% or higher A- 62% or higher C-
82% or higher B+ 58% or higher D+
78% or higher B 50% or higher D
74% or higher B- Lower than 50% F
Assignments
Assignments 8 assignments, due Wednesdays 23:59 4% each handed in electronically Not easy! Do not attempt to finish in 1 afternoon
Academic Honesty you are encouraged to work together to solve
problems however, you may not copy the work of another
student. TA-s will look for similar code. copying is a very serious offence … please refrain.
Codelab
Optional, but excellent learning tool for beginners. Will prepare you for assignments, midterm, and exam.
Example:
URLs:www.tcgo1.comwww.tcgo2.com
Exams
Midterm Wed. Oct. 28 (usual lecture time and location) closed book 20% of your grade
Final closed book 40% of your grade cumulative (covers everything from beginning)
no electronics allowed at exams (mp3, cell phones, etc) picture ID (preferably a student card) required to write
Quizzes: short (10-15 min), in class, announced 1 week ahead of time.
Labs
Labs hands-on experience with class concepts opportunity to work on assignments with assistance Linux/gcc concepts (not covered in class)
Tutorials: supplement class material interactive (Q & A) session)
Class web page:www.cs.uleth.ca/~a.bomhof/cs1620A
Comments No late assignments (except for medical reasons)
Plagiarism, copying, and misrepresentation are a serious offence, and can lead to severe penalties – refer to the course calendar for details. If in doubt about what constitutes cheating, please consult your instructor.
Students with special classroom or exam requirements should consult the calendar (Part 17, 12) for procedures on how to make such requests.
Comments Please be respectful of your fellow students.
try to arrive at the lecture on time please limit your discussion to class discussion during the
lecture please remember to turn off the sound on any electronic device
(laptop, cell phone, etc).
I will not answer questions about course material via e-mail. You are welcome to see me if you need help.
…. Let’s get started
Computers Man’s greatest invention? Productivity
Computers perform many tasks faster and more efficiently than humans
Communication We communicate with others all over the world quickly
Information Terabytes of information are available at our fingertips
The progress of computers1946 2007
The ENIAC• $500,000• 30 tonnes• 5000 ops/second
Laptop PC• $750• 4 lbs• billons of ops/second
Desktop computersProductivity software
Word processorsSpreadsheets
Information InternetElectronic resources (encyclopedias)
Gamesetc
How is all ofthis accomplished?
Computer Program A sequence of instructions designed to perform a
specific task, or collection of tasks Eg. Microsoft Word
Monitors keyboard input, displays it on the screen Formats input for more readable presentation Spellchecks your work Prints your work Saves your work ….
Computer ProgrammingThe science (art) of constructing a program
to achieve a specific goalThat is, for every program you have on your
desktop PC, a programmer (team of programmers) had to create that program
ProgramStep-by-step instructions to achieve the
desired task(s)Each instruction is executed by the processor
Hardware
Dr. John Von Neumann – Princeton University, Dr. John Von Neumann – Princeton University, 1946, proposed the concept of a 1946, proposed the concept of a stored stored program computerprogram computer – a computer whose – a computer whose program is stored in computer memory.program is stored in computer memory.
This architecture is still the basis for today's This architecture is still the basis for today's digital computer.digital computer.
Prior to this, the computer called the E.N.I.A.C Prior to this, the computer called the E.N.I.A.C (1946) could only be programmed by (1946) could only be programmed by connecting wires and setting switches.connecting wires and setting switches.
Von Neumann architecture
VN model: every computer is organized into four main VN model: every computer is organized into four main partsparts
CPUCPU - central processing unit - central processing unit brains of the computer.brains of the computer. eg. Pentium 4, AMD Athloneg. Pentium 4, AMD Athlon
Main MemoryMain Memory stores information being processed by the CPUstores information being processed by the CPU eg. 1 GByteeg. 1 GByte
Secondary StorageSecondary Storage stores data and programsstores data and programs eg. 200GByte Hard driveeg. 200GByte Hard drive
Input/Output devicesInput/Output devices allows people to supply information to and from allows people to supply information to and from
computerscomputers eg. printers, scanners, speakers, monitors, etc.eg. printers, scanners, speakers, monitors, etc.
ExampleSuppose we wish to perform the following
calculation:
how do we program our computer to make this calculation?
(17 + 29) x 56
Machine Code the language of your processor
each line represents an instruction to be executed (this “code” is stored in the memory; CPU executes the instruction pointed by the Program Counter; after execution, the PC points to the next instruction, etc)
00001001000100010000101000011101000100110010100000001100001110000010010101110000
place value "17" in memory location 1
place value "29" in memory location 2add values in loc. 1 and 2, place in loc. 3
place value "56" in memory location 4
multiply values in loc. 3 and 4, place in loc. 5 the solution to the problem is in memory location 5
Machine Code – Problems 1) Difficult to read and write
the numeric version of each instruction must be remembered each number must be translated to binary
00001001000100010000101000011101000100110010100000001100001110000010010101110000
place value "17" in memory location 1
place value "29" in memory location 2
add values in loc. 1 and 2, place in loc. 3
place value "56" in memory location 4
multiply values in loc. 3 and 4, place in loc. 5
Machine Code – Problems 2) Prone to error
mistaking a 1 for a 0 (or vice versa) can cause program failure difficult to diagnose
00001001000100010000101000011101000100110010100000001100001110000010010101110000
place value "17" in memory location 1
place value "29" in memory location 2
add values in loc. 1 and 2, place in loc. 3
place value "56" in memory location 4
multiply values in loc. 3 and 4, place in loc. 5
if these two bits are switched, addition will occur instead of multiplication
Machine Code – Problems 3) Time Consuming
simple formula required 5 instructions suppose you had a really complex task?
000010010001000100001010000111010001001100101000000011000011100000100101011100000000100100010001000010100001110100010011001010000000110000111000001001010111000000001001000100010000101000011101000100110010100000001100001110000010010101110000000010010001000100001010000111010001001100101000000011000011100000100101011100000000100100010001000010100001110100010011001010000000110000111000001001010111000000001001000100010000101000011101000100110010100000001100001110000010010101110000000010010001000100001010000111010001001100101000000011000011100000100101011100000000100100010001000010100001110100010011001010000000110000111000
000010010001000100001010000111010001001100101000000011000011100000100101011100000000100100010001000010100001110100010011001010000000110000111000001001010111000000001001000100010000101000011101000100110010100000001100001110000010010101110000000010010001000100001010000111010001001100101000000011000011100000100101011100000000100100010001000010100001110100010011001010000000110000111000001001010111000000001001000100010000101000011101000100110010100000001100001110000010010101110000000010010001000100001010000111010001001100101000000011000011100000100101011100000000100100010001000010100001110100010011001010000000110000111000
000010010001000100001010000111010001001100101000000011000011100000100101011100000000100100010001000010100001110100010011001010000000110000111000001001010111000000001001000100010000101000011101000100110010100000001100001110000010010101110000000010010001000100001010000111010001001100101000000011000011100000100101011100000000100100010001000010100001110100010011001010000000110000111000001001010111000000001001000100010000101000011101000100110010100000001100001110000010010101110000000010010001000100001010000111010001001100101000000011000011100000100101011100000000100100010001000010100001110100010011001010000000110000111000
000010010001000100001010000111010001001100101000000011000011100000100101011100000000100100010001000010100001110100010011001010000000110000111000001001010111000000001001000100010000101000011101000100110010100000001100001110000010010101110000000010010001000100001010000111010001001100101000000011000011100000100101011100000000100100010001000010100001110100010011001010000000110000111000001001010111000000001001000100010000101000011101000100110010100000001100001110000010010101110000000010010001000100001010000111010001001100101000000011000011100000100101011100000000100100010001000010100001110100010011001010000000110000111000
000010010001000100001010000111010001001100101000000011000011100000100101011100000000100100010001000010100001110100010011001010000000110000111000001001010111000000001001000100010000101000011101000100110010100000001100001110000010010101110000000010010001000100001010000111010001001100101000000011000011100000100101011100000000100100010001000010100001110100010011001010000000110000111000001001010111000000001001000100010000101000011101000100110010100000001100001110000010010101110000000010010001000100001010000111010001001100101000000011000011100000100101011100000000100100010001000010100001110100010011001010000000110000111000
000010010001000100001010000111010001001100101000000011000011100000100101011100000000100100010001000010100001110100010011001010000000110000111000001001010111000000001001000100010000101000011101000100110010100000001100001110000010010101110000000010010001000100001010000111010001001100101000000011000011100000100101011100000000100100010001000010100001110100010011001010000000110000111000001001010111000000001001000100010000101000011101000100110010100000001100001110000010010101110000000010010001000100001010000111010001001100101000000011000011100000100101011100000000100100010001000010100001110100010011001010000000110000111000
000010010001000100001010000111010001001100101000000011000011100000100101011100000000100100010001000010100001110100010011001010000000110000111000001001010111000000001001000100010000101000011101000100110010100000001100001110000010010101110000000010010001000100001010000111010001001100101000000011000011100000100101011100000000100100010001000010100001110100010011001010000000110000111000001001010111000000001001000100010000101000011101000100110010100000001100001110000010010101110000000010010001000100001010000111010001001100101000000011000011100000100101011100000000100100010001000010100001110100010011001010000000110000111000
000010010001000100001010000111010001001100101000000011000011100000100101011100000000100100010001000010100001110100010011001010000000110000111000001001010111000000001001000100010000101000011101000100110010100000001100001110000010010101110000000010010001000100001010000111010001001100101000000011000011100000100101011100000000100100010001000010100001110100010011001010000000110000111000001001010111000000001001000100010000101000011101000100110010100000001100001110000010010101110000000010010001000100001010000111010001001100101000000011000011100000100101011100000000100100010001000010100001110100010011001010000000110000111000
Machine Code – Problems 4) Unnatural
machine instructions are quite far from natural language not entirely intuitive what is being done
•place value "17" in memory location 1
•place value "29" in memory location 2
•add values in loc. 1 and 2, place in loc. 3
•place value "56" in memory location 4
•multiply values in loc. 3 and 4, place in loc. 5
means (17 + 29) x 56
Machine-Specificonly processors implementing that specific
instruction set can interpret the code
00001001000100010000101000011101000100110010100000001100001110000010010101110000
This may not correspond to a load commandon other processors.
Assembly Codeclose to machine codedifferences
numbers can be written in a different base (decimal)
instruction type given readable name instruction is separated visibly into components
Assembly Code
00001001000100010000101000011101000100110010100000001100001110000010010101110000
Machine Code
load t1 17load t2 29add t3 t1 t2load t4 56mult t5 t3 t4
Assembly Code
Note: A 1 to 1 instruction correspondence with machine code
Assembly Code to Machine Codeprocessor does not interpret assembly codea separate program called an assembler
translates the assembly code to machine code
00001001000100010000101000011101000100110010100000001100001110000010010101110000
load t1 17load t2 29add t3 t1 t2load t4 56mult t5 t3 t4
Assembler
Assembly Code vs. Machine Code
• Difficult to read and write
• Error Prone
• Time Consuming
• Unnatural
• Machine Specific
Machine Code
• Symbolic representations of instructions and numbers easier to read
• Symbolic representations of instructions and numbers reduce error
• Time Consuming
• Unnatural
• Machine Specific
Assembly Code
High-Level Programming Languagee.g. C++, Java, Pascal offers a more natural language for
programmingcommands are less coupled to the
instructions of the processor
High-Level Programming Language (C++)
00001001000100010000101000011101000100110010100000001100001110000010010101110000
load t1 17load t2 29add t3 t1 t2load t4 56mult t5 t3 t4
Machine Code Assembly Code
(17 + 29) * 56;
C++ Code
HL Code to Machine Codeprocessor definitely does not interpret high-
level codea separate program called a compiler
translates the code to machine code
00001001000100010000101000011101000100110010100000001100001110000010010101110000
(17+29) * 56;
Compiler
High-Level Code vs. Machine Code
• Difficult to read and write
• Error prone
Machine Code
• Most of the instructions in C++ are English words (if, else, while, for, do)
• numbers can be written in base 10, or 16, or 8, etc.
• words and numbers easier to interpret
• compiler flags all syntax errors for the programmer
High Level Code
High-Level Code vs. Machine Code
• Time Consuming
• Unnatural
Machine Code
• One C++ instruction often translates to many machine instructions
• Existing C++ libraries are available for use and cut programming time dramatically
• instructions are often English words
• mathematical formulae can be written in familiar notation
High Level Code
High-Level Code vs. Machine Code
• Machine-specific
Machine Code
• C++ is universal
• Only the compiler is machine-specific
High Level Code
C++a "high-level language"developed by Stroustrup
extended the "C" languagea very popular programming
languageefficient – yet powerful