Computer Science 1620 Syllabus, Introduction Instructors Lectures Robert Benkoczi Office D520 403-329-2298 robert.benkoczi@uleth.ca Labs, tutorials Arie Bomhof Office C510 403-329-5171 a.bomhof@uleth.ca Textbook C++ Programming Program 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. 2. Introduction to Programming C++ Basics 3. Control Structures 4. 6. selection, iteration Functions 5. data types expressions variables basic input/output parameter passing, return values, prototyping, reference parameters Arrays & Strings Structures & Classes Grading Scheme Programming Assignments (8) Midterm exam Final Exam 1 lab quiz 2 class quizzes CodeLab homework (bonus) Conversion to Letter Grades (may be revised): 32% 20% 40% 3% 5% 8% 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.com www.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 Communication Computers perform many tasks faster and more efficiently than humans We communicate with others all over the world quickly Information Terabytes of information are available at our fingertips The progress of computers 1946 The ENIAC • $500,000 • 30 tonnes • 5000 ops/second 2007 Laptop PC • $750 • 4 lbs • billons of ops/second Desktop computers Productivity software Word processors Spreadsheets Information How is all of this accomplished? Internet Electronic resources (encyclopedias) Games etc 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 Programming The science (art) of constructing a program to achieve a specific goal That is, for every program you have on your desktop PC, a programmer (team of programmers) had to create that program Program Step-by-step instructions to achieve the desired task(s) Each instruction is executed by the processor Hardware Dr. John Von Neumann – Princeton University, 1946, proposed the concept of a stored program computer – a computer whose program is stored in computer memory. This architecture is still the basis for today's digital computer. Prior to this, the computer called the E.N.I.A.C (1946) could only be programmed by connecting wires and setting switches. Von Neumann architecture VN model: every computer is organized into four main parts CPU - central processing unit brains of the computer. eg. Pentium 4, AMD Athlon Main Memory stores information being processed by the CPU eg. 1 GByte Secondary Storage stores data and programs eg. 200GByte Hard drive Input/Output devices allows people to supply information to and from computers eg. printers, scanners, speakers, monitors, etc. Example Suppose we wish to perform the following calculation: (17 + 29) x 56 how do we program our computer to make this calculation? 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) 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 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 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 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 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 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 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? 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 0000100100010001 0000101000011101 0001001100101000 0000110000111000 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-Specific only processors implementing that specific instruction set can interpret the code This may not correspond to a load command on other processors. 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 Assembly Code close to machine code differences numbers can be written in a different base (decimal) instruction type given readable name instruction is separated visibly into components Assembly Code Machine Code 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 Assembly Code load load add load mult t1 t2 t3 t4 t5 Note: A 1 to 1 instruction correspondence with machine code 17 29 t1 t2 56 t3 t4 Assembly Code to Machine Code processor does not interpret assembly code a separate program called an assembler translates the assembly code to machine code load load add load mult t1 t2 t3 t4 t5 17 29 t1 t2 56 t3 t4 Assembler 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 Assembly Code vs. Machine Code Machine Code Assembly Code • Difficult to read and write • Symbolic representations of instructions and numbers easier to read • Error Prone • Symbolic representations of instructions and numbers reduce error • Time Consuming • Time Consuming • Unnatural • Unnatural • Machine Specific • Machine Specific High-Level Programming Language e.g. C++, Java, Pascal offers a more natural language for programming commands are less coupled to the instructions of the processor High-Level Programming Language (C++) Machine Code Assembly Code C++ Code 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 load load add load mult (17 + 29) * 56; t1 t2 t3 t4 t5 17 29 t1 t2 56 t3 t4 HL Code to Machine Code processor definitely does not interpret highlevel code a separate program called a compiler translates the code to machine code Compiler (17+29) * 56; 0000100100010001 0000101000011101 0001001100101000 0000110000111000 0010010101110000 High-Level Code vs. Machine Code Machine Code • Difficult to read and write High Level 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. • Error prone • words and numbers easier to interpret • compiler flags all syntax errors for the programmer High-Level Code vs. Machine Code Machine Code • Time Consuming High Level Code • One C++ instruction often translates to many machine instructions • Existing C++ libraries are available for use and cut programming time dramatically • Unnatural • instructions are often English words • mathematical formulae can be written in familiar notation High-Level Code vs. Machine Code Machine Code • Machine-specific High Level Code • C++ is universal • Only the compiler is machinespecific C++ a "high-level language" developed by Stroustrup extended the "C" language a very popular programming language efficient – yet powerful