COMP 202 – Introduction to Computing 1 COMP-202 Course Overview CONTENTS: Focus of the Course and Prerequisites Outline and Textbook Course Structure and Grading Scheme Computer Lab Info and Required Software Course Communication
CO
MP
202 – Introd
uction
to Com
pu
ting 1
COMP-202Course Overview
CONTENTS:Focus of the Course and PrerequisitesOutline and TextbookCourse Structure and Grading SchemeComputer Lab Info and Required SoftwareCourse Communication
CO
MP
202 – Introd
uction
to Com
pu
ting 1
COMP-202Intro to Computing I
(Section 2)
WELCOME!
CO
MP
202 – Introd
uction
to Com
pu
ting 1
My name is...
• Maja• Miss Frydrychowicz (fri-dri-ha-vitch)• Professor Frydrychowicz• Dr.Frydrychowicz• Miss/Ma'am/Sir/Professor
CO
MP
202 – Introd
uction
to Com
pu
ting 1
4COMP-202 - Course Details
Focus of the Course
• Introduction to computer programming– Basics of problem solving
– Essentials of program design and implementation
• Coursework will be done in a programming language called Java– Concepts taught in the course apply to other programming languages
as well
• Aimed at students with little or no background in programming and/or knowledge of computer science
CO
MP
202 – Introd
uction
to Com
pu
ting 1
Demo: A simple Java program...
CO
MP
202 – Introd
uction
to Com
pu
ting 1
6COMP-202 - Course Details
Do you know how to iterate over a 2D array? Can you write a
recursive program?• If you have no idea what the above questions are
about, GOOD, you're in the right course.
• If you suspect you might be overqualified for COMP-202, e-mail your section instructor (in this case, Maja).– We might invite you to write a test so that you can transfer
to a more advanced course.
CO
MP
202 – Introd
uction
to Com
pu
ting 1
7COMP-202 - Course Details
Prerequisites
• Prerequisite: A CEGEP-level math course or equivalent
• For those who graduated from high school outside Quebec and thus never attended CEGEP: any upper-level math course
• In any case, the ability to think logically and rigorously is more important than calculus, algebra or trigonometry
CO
MP
202 – Introd
uction
to Com
pu
ting 1
8COMP-202 - Course Details
Course Schedule
• Basics of programming– Variables, simple calculations, basic input and output
– Methods / functions / procedures
– Branching structures
– Loops
– Arrays, reference types
• Object-oriented programming– Using objects
– Defining your own classes of objects
– Exceptions, File I/O
– Recursion
– Maybe more...
CO
MP
202 – Introd
uction
to Com
pu
ting 1
9COMP-202 - Course Details
Course Communication
• Course home page:– http://www.cs.mcgill.ca/~cs202/2011-01/
• myCourses (WebCT Vista):– http://www.mcgill.ca/mycourses
CO
MP
202 – Introd
uction
to Com
pu
ting 1
10COMP-202 - Course Details
Course Structure
• Lectures (3 hours/week, compulsory)– Highlight key concepts; opportunity to practice and ask questions,
receive and give feedback, MAKE MISTAKES.
– Students are expected to complete readings (posted on course website) before class and actively participate in exercises.
– All material taught in lectures is examinable unless otherwise stated
CO
MP
202 – Introd
uction
to Com
pu
ting 1
11COMP-202 - Course Details
You Maja
CO
MP
202 – Introd
uction
to Com
pu
ting 1
12COMP-202 - Course Details
You Maja
Assignments!
CO
MP
202 – Introd
uction
to Com
pu
ting 1
13COMP-202 - Course Details
You Maja
Quiz!
CO
MP
202 – Introd
uction
to Com
pu
ting 1
14COMP-202 - Course Details
You Maja
Midterm!
CO
MP
202 – Introd
uction
to Com
pu
ting 1
15COMP-202 - Course Details
You Maja
Final Exam!
CO
MP
202 – Introd
uction
to Com
pu
ting 1
16COMP-202 - Course Details
Super Fun Activity: Interviews
• Walk around the room, talk to people (including Maja) and write down the name of:1. A person who has NEVER programmed before.
2. A person who is born outside of North or South America.
3. A person who is a 3rd-year undergraduate at McGill
4. A person who grew up in Montreal.
5. A person who is fluent in at least 3 (human) languages..
6. A person who has NEVER eaten poutine.
If you collect six different names that are not your own, you'll get some candy.
CO
MP
202 – Introd
uction
to Com
pu
ting 1
17COMP-202 - Course Details
Resources Outside of Class
• Tutorials (optional, but very useful)– Several sessions of each, offered at different times; go at most
convenient time for you
– Tutorials start Thursday! details to be announced on myCourses
– Most tutorials will take place in January to help you get started
• Office hours (2 instructors, 12-15 teaching assistants)– Approximately 25 office hours per week
– TA office hours start next week; details to be announced
CO
MP
202 – Introd
uction
to Com
pu
ting 1
18COMP-202 - Course Details
What to expect from teaching assistants?
Teaching assistants will:
• Provide you with constructive feedback about your assignments to help you improve your programming skills.
• Be well-prepared to help you understand course material and assignments during their office hours and on the myCourses discussion board.
• Grade each assignment before the next assignment is due.
• Will deliver well-organized tutorials that include interactive problem solving.
• Will arrive at their office hours and tutorials on time, or use the Google calendar and the discussion board on myCourses to announce any last-minute changes.
CO
MP
202 – Introd
uction
to Com
pu
ting 1
19COMP-202 - Course Details
Tutorials
• Purpose:– To reinforce material taught in lectures through examples and hands-
on exercises
– To enable you to familiarize yourself with software needed to complete coursework
• Led by a teaching assistant
• Take place in a computer lab
• Smaller groups, therefore more individualized attention
CO
MP
202 – Introd
uction
to Com
pu
ting 1
20COMP-202 - Course Details
Tutorial Topics
• Tutorial T1:– School of Comp Sci accounts, login / logout
– GNU/Linux desktop environment
– myCourses
– RText
– Writing, compiling, running a small Java program
• Tutorial T2: Variables, types, methods
• Tutorial T3: Conditionals and iterations, more methods.
• We'll add a few more advanced tutorials in later months as needed.
• Tutorials M and F: Preparation for the midterm and final examination, respectively
CO
MP
202 – Introd
uction
to Com
pu
ting 1
21COMP-202 - Course Details
Grading Scheme (1)
• 6 assignments: 28%– Each assignment is worth more than the previous
• Assignment 0: 2% (Released tomorrow, Due Wed Jan 12th !!!)
• Assignment 1: 4%
• Assignment 2: 4%
• Assignment 3: 4%
• Assignment 4: 6%
• Assignment 5: 8%
– All assignments count toward your final grade
– Best way to learn the material
– Each student has two “late days” to use during the semester
– MUST be done INDIVIDUALLY
CO
MP
202 – Introd
uction
to Com
pu
ting 1
22COMP-202 - Course Details
Grading Scheme (2)
• 1 in-class quiz: 4% (sometime between Feb 7 and 11)
• 1 midterm examination: 18% (March 3, Evening)– To be held outside lecture hours; written
– E-mail us if you have a conflict with another evening midterm!
• 1 final examination: 50%– Held during final exam session; written
CO
MP
202 – Introd
uction
to Com
pu
ting 1
23COMP-202 - Course Details
Plagiarism :(
CO
MP
202 – Introd
uction
to Com
pu
ting 1
24COMP-202 - Course Details
Recommended Textbook (free; available on course website)
• “How to Think Like a Computer Scientist”– Our lectures will not follow this textbook exactly, but you should
still read it.
– We particularly recommend the chapters about “debugging” your code. Really useful for your assignments.
CO
MP
202 – Introd
uction
to Com
pu
ting 1
25COMP-202 - Course Details
SOCS Computer Labs
• If you are officially registered in the course, you can create an account to use the computers on the 3rd floor of Trottier building
• Computer availability:– Computers in open areas: physically accessible 24 hours a day, 7 days
a week
– Computers in side rooms: physically accessible on weekdays 10:00 - 20:00, weekends 12:00 - 20:00
• Consultant on duty: weekdays 10:00 - 20:00, weekends 12:00 - 20:00
• Computers run GNU/Linux (Unix-like OS), not MS Windows– Unix seminars are offered by SOCS Systems staff
CO
MP
202 – Introd
uction
to Com
pu
ting 1
26COMP-202 - Course Details
Required Software
• You are encouraged to use your personal computer or laptop to complete course work
• Software used in this course– Required: Java Development Kit (JDK)
– Optional: RText, Eclipse (later in the course)
• See course outline for details on how to obtain the above software packages
• All programs you submit for assignments must compile and run using JDK 6 or later– JDK is backward compatible; programs that compile and run under
previous versions also compile and run under JDK 6
CO
MP
202 – Introd
uction
to Com
pu
ting 1
27COMP-202 - Course Details
Useful Tips
• Read everything carefully: slides, notes, textbooks, instructions, assignment specifications, documentation, announcements on myCourses, ...
• Do not wait until the last minute to do your assignments or submit them
• Do not fall behind; each new concept builds on previous ones
• Contact instructors / TAs if you have difficulties
• Do not expect to be given every single detail; you will have to look things up in the provided material and deduce some things on your own
• Experiment!
• Practice makes perfect!
CO
MP
202 – Introd
uction
to Com
pu
ting 1
28COMP-202 - Course Details
Anonymous Survey
• Answers the following questions1) Why did you register for this course?
2) What are the qualities of a good teacher?
3) Maja's always looking for new music: what song/band/artist would you recommend?
CO
MP
202 – Introd
uction
to Com
pu
ting 1
COMP-202 Introduction
CONTENTS:What Is Programming?How a Computer WorksProgramming Languages
CO
MP
202 – Introd
uction
to Com
pu
ting 1
Part 1: What Is Programming?
CO
MP
202 – Introd
uction
to Com
pu
ting 1
31COMP-202 - Introduction
Programming and Computers (1)
• In order to understand what programming is, we need to know what a computer is
• A computer is a machine that executes lists of instructions– We feed a list of instructions to the computer and the computer
executes them
– Takes “input”, produces “output”
• Programming a computer involves two things:– Designing lists of instructions that will make the computer solve
specific problems
– Having the computer execute the instructions
• The purpose is to have the computer solve the problem for you instead of you solving the problem by hand
CO
MP
202 – Introd
uction
to Com
pu
ting 1
32COMP-202 - Introduction
Cooking Scrambled Eggs (1)
• Input (things we need to follow the instructions):– Two eggs
– A tablespoon of oil
– A pan
– A stove
• Instructions:– Add oil to pan
– Heat pan on stove
– Crack eggs into pan
– Mix until light and flaky
• Output (things that result from following the instructions):– Scrambled eggs
CO
MP
202 – Introd
uction
to Com
pu
ting 1
33COMP-202 - Introduction
Counting Cards of a Given Suit (1)
• Input:– The deck
– The suit we are looking for
• Instructions:– Take a blank piece of paper
– As long as there are still cards in the deck that we have not looked at, do the following:
• If the current card is the card belongs to the suit, make a mark on the piece of paper
• Move on to the next card in the deck
– Number of cards that belong to the suit = number of marks on the piece of paper
CO
MP
202 – Introd
uction
to Com
pu
ting 1
34COMP-202 - Introduction
Counting Cards of a Given Suit (2)
• Output:– The number of cards in the deck that belong to the suit
CO
MP
202 – Introd
uction
to Com
pu
ting 1
35COMP-202 - Introduction
Ambiguous Instructions
• Suppose your cousin is not very creative and follows your instructions exactly– What happens if you forget to mention some details?
– What happens if you change the order of the instructions?
• For example, in the instructions for cooking scrambled eggs:– To what temperature should one "heat the pan on the stove"? Does it
matter? What will a person following the instructions do if it matters but it's not specified?
– What happens if one tries to "mix until light and flaky" before "cracking the eggs into the pan"?
CO
MP
202 – Introd
uction
to Com
pu
ting 1
36COMP-202 - Introduction
Exercise: parity of sheets in a stack of paper
• Your “computer” is a person who does not know how to multiply/divide/add/subtract and does not know what “odd” or “even” mean. The person is in an empty room and doesn't have access to any tools or devices.
• Individually, write down instructions for determining whether a stack of paper has an even or odd number of sheets.– What is the input and output?
CO
MP
202 – Introd
uction
to Com
pu
ting 1
37COMP-202 - Introduction
Instructions and Precision
• The instructions for finding a card in a deck or counting the number of cards of a given suit in a deck are very precise and unambiguous
• Your 6-year old cousin (or anyone else) will be able to follow them and arrive at the solution, even if– he / she has no creativity or imagination
– he / she has no ability to fill the gaps in your instructions (because you did not leave any gaps in your instructions)
– he / she does no understanding of the purpose of your instructions or what they are supposed to accomplish, and does not care
• Writing lists of instructions like these is the very essence of programming a computer
CO
MP
202 – Introd
uction
to Com
pu
ting 1
38COMP-202 - Introduction
Programs (1)
• Programs are essentially lists of instructions that tell a computer how to accomplish a task– Each instruction tells the computer to do something: an action, a
calculation, a comparison
• However, the computer does not understand the instructions or their purpose, it merely performs them without question
• Therefore, your instructions must be precise– The computer cannot fill the gaps if you forget to specify certain
things
– In those cases, it will either return the wrong result or choke
• Your instructions must also be ordered correctly– The computer will not be able to detect incorrectly ordered
instructions
CO
MP
202 – Introd
uction
to Com
pu
ting 1
39COMP-202 - Introduction
Programs (2)
– Again, in those cases, it will merely return the wrong result or choke
• Programs also have:– Input (things that they work on)
– Output (things that they produce)
• But programming a computer consists of more than just writing precise and unambiguous lists of instructions...
CO
MP
202 – Introd
uction
to Com
pu
ting 1
40COMP-202 - Introduction
Computer Languages
• The computer does not understand English or any other human language
• Therefore, not only must your lists of instructions be precise and unambiguous, they must be translated from human language to a language the computer understands
• Learning this language is similar to learning a foreign (human) language, but there are important differences
CO
MP
202 – Introd
uction
to Com
pu
ting 1
41COMP-202 - Introduction
Natural vs Formal Languages
• All languages that computers understand have a special structure which ensures that no valid statement expressible in these languages is ambiguous– Each statement has one possible meaning and only one possible
meaning
– Compare to the following English sentences:• "The lady hit the man with an umbrella"
• "Time flies like an arrow"
CO
MP
202 – Introd
uction
to Com
pu
ting 1
42COMP-202 - Introduction
Complex Tasks
• Sometimes, we want the computer to perform complex tasks
• Writing a detailed list of precise instructions for this complex task would be very difficult– There are just too many instructions for humans to manage
• Solution:– Break down the complex task into a series of simpler tasks; if the
simpler tasks are still too complex, break them down into even simpler tasks
– Write a list of instructions for each of the simpler tasks
– The list of instructions for each of the simpler tasks can be used as a single instruction in the list of instructions that performs the original task
CO
MP
202 – Introd
uction
to Com
pu
ting 1
43COMP-202 - Introduction
The Bank Machine
• A bank machine has a lot of functionality:– It checks whether you are who you say you are
– It gives you a choice of operations
– Each operation does something different
– It ensures that you satisfy the necessary conditions to perform the operation you have selected
• Let's try to break this complex task down
CO
MP
202 – Introd
uction
to Com
pu
ting 1
44COMP-202 - Introduction
The Bank Machine: Login
• Input– The customer's bank card
• Instructions:– Set the number of login attempts to 0
– As long as the number of login attempts is less than 3, do the following
• Read the PIN from the keyboard
• If the PIN matches the one associated with the bank card, then success, otherwise, add one to the number of login attempts
– Failure
• Output– Success if the login succeeds, failure otherwise
CO
MP
202 – Introd
uction
to Com
pu
ting 1
45COMP-202 - Introduction
The Bank Machine: Main Program
• Input:– The customer's bank card
• Instructions:– Perform Login subprogram
– If failure, keep the bank card and wait for next customer; otherwise• Ask user for operation
• As long as operation is not exit, perform subprogram associated with operation and ask user for another operation
• Return bank card and wait for next customer
• Output:– (Depends on the operations requested by user)
CO
MP
202 – Introd
uction
to Com
pu
ting 1
46COMP-202 - Introduction
Software
• Is a software package merely a program?
• Software typically consists of many subcomponents, modules, and subprograms
• Each subprogram solves a particular problem or performs a particular task
• Software also includes some information to be used and manipulated by the subprograms– For example, in a currency conversion program, it includes a table
with exchange rates
CO
MP
202 – Introd
uction
to Com
pu
ting 1
47COMP-202 - Introduction
Goals of This Course (1)
• To learn how to design and write precise, unambiguous, and detailed lists of instructions that can be used to solve a problem or perform a task– Requires imagination, rigor, and understanding of how we solve the
problem "by hand"
• To learn how to translate these instructions into a language the computer can understand– Requires remembering the "words" of this language, how they are
"spelled", what they mean, what the "grammar" and "punctuation" rules of this language are; similar to learning a foreign (human) language
• To learn how to deal with complex problems or tasks by:– Breaking them down into smaller subproblems or subtasks
CO
MP
202 – Introd
uction
to Com
pu
ting 1
48COMP-202 - Introduction
Goals of This Course (2)
– Writing subprograms which solve each subproblems or perform each subtask
– Connecting the subprograms that solve each subproblem or perform each subtask to form one program which solves the original complex problem or performs the original complex task
• In short, to learn how to develop software
• At the end of this course, you will be able to write a program that simulates a bank machine (and many other things)
CO
MP
202 – Introd
uction
to Com
pu
ting 1
Part 2: How a Computer Works
CO
MP
202 – Introd
uction
to Com
pu
ting 1
50COMP-202 - Introduction
Hardware and Software (1)
• A computer system consists of both hardware components and software
• Hardware consists of the physical, tangible parts of a computer– Cases, monitors, keyboard, mouse, chips
– Rule of thumb: If you can take it in your hands and it is part of a computer system, then it is hardware
– It is the hardware which executes the instructions
• Software: Programs and data that they use
• A computer requires both hardware and software– Software cannot run without hardware; instructions are useless unless
they are performed by someone / something
CO
MP
202 – Introd
uction
to Com
pu
ting 1
51COMP-202 - Introduction
Hardware and Software (2)
– Hardware will not do anything without software telling it what to do
– Therefore, each is essentially useless without the other
CO
MP
202 – Introd
uction
to Com
pu
ting 1
52COMP-202 - Introduction
A Personal Computer
Monitor /screen(output)
Speakers(output)
Keyboard (input)Mouse(input)
Case;contains:•CPU•Memory•Disk drives•...
CO
MP
202 – Introd
uction
to Com
pu
ting 1
53COMP-202 - Introduction
taking notes; packing a box
remembering what Maja said 2 minutesago
remembering your name
CO
MP
202 – Introd
uction
to Com
pu
ting 1
54COMP-202 - Introduction
Central Processing Unit (CPU)• The "operation/action" part of the
computer's brain– Basically controls the information / data in a
computer
• Perform instructions– Arithmetic operations
– Logic operations
– Decisions
• The instructions it understands are much simpler and fine-grained than those we have seen in previous examples
CO
MP
202 – Introd
uction
to Com
pu
ting 1
55COMP-202 - Introduction
Memory
• Memory holds the data– Think of a filing cabinet
• Main memory: Most of it is called RAM, which stands for Random-Access Memory– Data has to be in main memory so that the CPU can access it
– Volatile: its contents are lost when the program terminates or when the computer shuts down
• Secondary storage: Hard drive / CD / DVD / Blu-Ray disc / USB memory stick– Persistent: its contents will not be lost when the computer shuts down
– This is where you keep the data for long-term storage
– Secondary storage has much slower access times than main memory
CO
MP
202 – Introd
uction
to Com
pu
ting 1
56COMP-202 - Introduction
taking notes; packing a box(CPU)
remembering what Maja said 2 minutesago (RAM)
remembering your name (secondarystorage)
CO
MP
202 – Introd
uction
to Com
pu
ting 1
57COMP-202 - Introduction
Summary
• Computers are machines that execute programs.
• A program is a precise list of instructions that may take input and make produce output.
• Dividing programs into subprograms is really useful for writing large, complicated software.
• The CPU is the part of the computer that executes instructions from a program.
• Program execution relies on a combination of working memory (RAM) and long-term memory (e.g. a hard drive).