gülşen demiröz fall 2011 cs 201 introduction to computing

38
Gülşen Demiröz Fall 2011 CS 201 Introduction to Computing

Upload: marilynn-fitzgerald

Post on 01-Jan-2016

237 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Gülşen Demiröz Fall 2011 CS 201 Introduction to Computing

Gülşen Demiröz

Fall 2011

CS 201 Introduction to Computing

Page 2: Gülşen Demiröz Fall 2011 CS 201 Introduction to Computing

This course will give youBasic computer science notionsMostly C++ programming concepts

with emphasis on computational problemsObject Oriented Programming language

At the end of this course, you will be able todevelop algorithms write programs using C++but not-so-big-applications

Page 3: Gülşen Demiröz Fall 2011 CS 201 Introduction to Computing

Course Information CS201 – Introduction to Computing

Websitehttp://myweb.sabanciuniv.edu/gulsend/su_current_courses/cs-201-spring-2008/

also follow SUCourse an e-mail list will be set up for announcements

so you are responsible to check your e-mails (sabanciuniv account) Instructor: Gülşen Demiröz, FENS L015, [email protected] Schedule

Lectures: Monday 13:40 - 15:30 in FENS G077, Tuesday 10:40 - 11:30, FASS G062

Recitations will start first week See schedule for date, time and location Recitations will also be used as labs, so please take your laptops to

recitations Recitations B2, B3, B4, C4 and D3 will be closed. During add-drop period they

should change their section to the available one at the same time. Attend all. It is to your benefit. Recitation Attendance: %7 of your grade.

Random attendance at the lectures will be also added to this. Weekly or Biweekly Homework Assignments Textbook: A Computer Science Tapestry, by Astrachan

http://www.cs.duke.edu/csed/tapestry/

Page 4: Gülşen Demiröz Fall 2011 CS 201 Introduction to Computing

Course PolicyTwo Midterm Exams + Final Exam

Midterm 1: November 19 Saturday, 13:00 – 15:00 Midterm 2: December 17 Saturday, 10:00 - 12:00Final exam is scheduled by the registrar

No late homework without penaltyOne late day is allowed at cost of 10% of full grade

Plagiarism is not toleratedHomeworks are to be done personallyCooperation is not an excuse

If you do not know how to cooperate, don’t do itwe use software tools to detect plagiarized homeworkfirst case –100 (minus hundred), second fails the course!detailed policy is on the web site of the course

Page 5: Gülşen Demiröz Fall 2011 CS 201 Introduction to Computing

Course Policy (cont’d)Make-ups (detailed policy is on the web)

reports must come before or during the examyou must be really sick to take a make-up examaccording to the by-laws, acceptance of report is up

to the instructora medical report does not guarantee taking a make-up

exammake-ups will be much more harder

Page 6: Gülşen Demiröz Fall 2011 CS 201 Introduction to Computing

Before CS 201

Maybe you are afraid of computers

Maybe you hate

Maybe you used computers just for fun before

Page 7: Gülşen Demiröz Fall 2011 CS 201 Introduction to Computing

During CS 201You may have bad dreams at the beginning

And you may think of you are going nuts

But if you work properly and spend considerable amount of time ...

Page 8: Gülşen Demiröz Fall 2011 CS 201 Introduction to Computing

At the End of CS 201

Success is yours!

Page 9: Gülşen Demiröz Fall 2011 CS 201 Introduction to Computing

MS Visual Studio .NET (2008) Necessary software to write and execute C++ programs You will install to your laptops Help will be available in first week labs Check website for instructions on how to install, if you prefer to install

before the labs You can install

over the network \\software\microsoft\VisualStudio\Visual_Studio_2010

step-by-step installation screenshots are on course web site:http://myweb.sabanciuniv.edu/gulsend/su_current_courses/cs-201-spring-2008/

VisualStudio2010_Installation_Upgrade_Guide

Page 10: Gülşen Demiröz Fall 2011 CS 201 Introduction to Computing

What is Computer Science?Computer science is the study and the science of the

theoretical foundations of information and computation and their implementation and application in computer systems.Information – dataComputation – processing, problem solvingA computer is a machine that manipulates data according to

a list of instructions.The discipline is called informatics in many countries

especially in EuropeComputer engineering is used for hardware-software

integration, circuit/chip design.

Page 11: Gülşen Demiröz Fall 2011 CS 201 Introduction to Computing

Computer ScienceComputer Science is not only programming

more than programmingComputer Science is a young discipline

More than 50 yearsFirst graduate program at CMU (then Carnegie Tech)

in 1965in Turkey first CS department in 1977

Turing machine (1937)abstract machinetheoretically capable of any computation that we can

do with modern computers today

Page 12: Gülşen Demiröz Fall 2011 CS 201 Introduction to Computing

Alan Turing (1912--1954)

A scientist and mathematician Instrumental in breaking a

German coding machine during WW II

Developed mathematical model of a computer called a Turing Machine (before computers)solves same problems as a

Pentium processor (more slowly)

Showed there are problems that cannot be solved by a computer

Was a long distance runner committed suicide

Page 13: Gülşen Demiröz Fall 2011 CS 201 Introduction to Computing

Computer ScienceArchitecture hardware-software interface

Software Engineering creating software products

Operating Systems Windows, Linux/UNIX, MacOS

Graphics animation, entertainment, games

Computer Security hacking, digital signatures

Computer Networking made internet a reality

Artificial Intelligence thinking machines, learning

Scientific Computing biocomputing

Theoretical CS analyze algorithms

…….

Page 14: Gülşen Demiröz Fall 2011 CS 201 Introduction to Computing

AlgorithmsArabic-originated wordStep-by-step process that solves a problem

do this, then do that, ...eventually stops with an answergeneral process rather than specific to a programming

languageIssues

correctness complexity and efficiency

I picked a number between 1 and 100You will guess itI’ll respond “high”, “low”, “correct”.how many guesses needed (worst case)?

Page 15: Gülşen Demiröz Fall 2011 CS 201 Introduction to Computing

Example Algorithm - Find the minimum

Initial list: 4 6 7 3 9 1 4 5

Should we sort? 1 3 4 4 5 6 7 9About (n.log(n)) operations, where n is the number

of elementsOptimal algorithm - About n operations

Pick 4 as the minimumCompare 4 to 6 - min is still 4Compare 4 to 7- min is still 4Compare 4 to 3 - Pick 3 as the minimumCompare 3 to 9- min is still 3Compare 3 to 1 - Pick 1 as the minimumCompare 1 to 4- min is still 1Compare 1 to 5 - We are done and the minimum is 1

Page 16: Gülşen Demiröz Fall 2011 CS 201 Introduction to Computing

Example Algorithm - Find the minimum

Page 17: Gülşen Demiröz Fall 2011 CS 201 Introduction to Computing

Data Representation in Computers

Computers are data processing machinesAll type of data are represented in numeric format

numbers – obviouscharacters – ASCII (Unicode) codes (‘A’=65, ‘Z’=90)colors – RGB values

Internal representation (at the lowest level) is in binary form0 and 1 (4=100, 5=101)all arithmetic in binary too

Low level instructions are also in binary machine languagenot human readable and programmable!

Page 18: Gülşen Demiröz Fall 2011 CS 201 Introduction to Computing

Problem Solving and Computers

Computerized problem solving explicitly or implicitly require computation

For examples:Arithmetic problemsComputer graphics (require geometric operations)Data mining (sorting through large amounts of data

to pick out relevant information)

Let’s develop our first programIn other words, let’s make use of computer for

computation

Page 19: Gülşen Demiröz Fall 2011 CS 201 Introduction to Computing

First Program

Problem: How many 3-digit positive numbers are there that are divisible by 7, but not divisible by 4?Think of an algorithm!

Try all 3-digit numbers between 100 and 999If a number is divisible by 7 but not by 4

Increment a counter

Display the value of the counter

Now let’s see the programmyfirstprogram.cpp

Page 20: Gülşen Demiröz Fall 2011 CS 201 Introduction to Computing

Themes and ConceptsTheory

developing algorithms and evaluating themhow fast?Works all the time? Tested?

Languageneeded to express the algorithms to the computers programming languages: C++, Java, C, C#, Perl,

Fortran, Lisp, Scheme, Visual BASIC, ...Assembly language, machine language

Architecturebuilding blocks of a computerMain memory, cache memory, disk, CPU, etc.

Page 21: Gülşen Demiröz Fall 2011 CS 201 Introduction to Computing

High-level Languages and Assembly

Rather than instruct computers at the level of 0’s and 1’s, higher level languages have been developed.Flexible and easier programming

Compilers translate a high level language, such as C++, into machine-specific executable program (0s and 1s)The compiler is a program, input is C++ program,

output is an executable programIn theory, C++ source code works on any machine

given a compiler for the machinefor other languages different compilers are needed

Between machine code and high-level languages: assembly languagehuman understandable form of machine code

instructions

Page 22: Gülşen Demiröz Fall 2011 CS 201 Introduction to Computing

Levels of Programming Language – High Level

int main(){int x, y, z;x = 7;y = 12;z = x * y;return 0;

}

Page 23: Gülşen Demiröz Fall 2011 CS 201 Introduction to Computing

Levels of Programming Language - assembly

Machine specific assembly language, Sparc on left, Pentium on right, both generated from the same C++ code

main: main: save %sp,-128,%sp pushl %ebp mov 7,%o0 movl %esp,%ebp st %o0,[%fp-20] subl $12,%esp mov 12,%o0 movl $7,-4(%ebp) st %o0,[%fp-24] movl $12,-8(%ebp) ld [%fp-20],%o0 movl -4(%ebp),%eax ld [%fp-24],%o1 imull -8(%ebp),%eax call .umul,0 movl %eax,-12(%ebp) nop xorl %eax,%eax st %o0,[%fp-28] jmp .L1 mov 0,%i0 .align 4 b .LL1 xorl %eax,%eax nop jmp .L1

Page 24: Gülşen Demiröz Fall 2011 CS 201 Introduction to Computing

Basic Program Development Steps

Analyze Problem

Develop Algorithm

Design Program

Write code on paper

Code over the computer

Source Code

Compile & Build

Syntax Errors?

Yes

Correct it

No

Run

Correct Results?

Yes - Done

No

Correct (Debug)

Page 25: Gülşen Demiröz Fall 2011 CS 201 Introduction to Computing

A Simple ProgramInput three integer numbers and display their sumAlgorithm

display a prompt for data entryinput (number1, number2, number3)

sum number1 + number2 + number3

output (sum)Program

First we will write the program and run it using MS Visual Studio (sum3num.cpp)

Then we will see an animation about the steps taken during the execution

Page 26: Gülşen Demiröz Fall 2011 CS 201 Introduction to Computing

A Simple Program – Execution steps

Page 27: Gülşen Demiröz Fall 2011 CS 201 Introduction to Computing

ArchitectureVon Neumann Model

John von Neumannfounder of game theorypart of the Manhattan Project (atomic bomb)ENIAC

Stored program conceptProgram is also stored as the data

Page 28: Gülşen Demiröz Fall 2011 CS 201 Introduction to Computing

Von Neumann Model

Page 29: Gülşen Demiröz Fall 2011 CS 201 Introduction to Computing

Von Neumann Model

Input UnitProvides

instructions and data to system

keyboardsmousescanners

Memory Unit

Arithmetic and Logical Unit (ALU)

Input Unit Output Unit

Control Unit

Page 30: Gülşen Demiröz Fall 2011 CS 201 Introduction to Computing

Von Neumann Model

Output UnitReturns

data from system

monitorsprinters

Memory Unit

Arithmetic and Logical Unit (ALU)

Input Unit Output Unit

Control Unit

Page 31: Gülşen Demiröz Fall 2011 CS 201 Introduction to Computing

Von Neumann Model

MemoryStorage for

instructions and data

Memory Unit

Arithmetic and Logical Unit (ALU)

Input Unit Output Unit

Control Unit

Page 32: Gülşen Demiröz Fall 2011 CS 201 Introduction to Computing

Von Neumann Model

ALUProcesses

data

Memory Unit

Arithmetic and Logical Unit (ALU)

Input Unit Output Unit

Control Unit

Page 33: Gülşen Demiröz Fall 2011 CS 201 Introduction to Computing

Von Neumann Model

Control UnitDirects

processing

Memory Unit

Arithmetic and Logical Unit (ALU)

Input Unit Output Unit

Control Unit

Page 34: Gülşen Demiröz Fall 2011 CS 201 Introduction to Computing

Von Neumann Model

CPUALU and

Control Unit combined

Memory Unit

Arithmetic and Logical Unit (ALU)

Input Unit Output Unit

Control Unit

CPU

Page 35: Gülşen Demiröz Fall 2011 CS 201 Introduction to Computing

MemoryPrimary memory is generally RAM (Random

Access Memory)fast data accessvolatile

electricity gone, data goneexpensive

Secondary memory (storage)Disks, tapes, CD-ROMs, floppiesnon-volatileslow data accesscheap

ROM (Read-only memory) - Flash memoryBIOS (Basic Input Output System) - to start the

system (before the operating system)

Page 36: Gülşen Demiröz Fall 2011 CS 201 Introduction to Computing

A Typical Computer System

Page 37: Gülşen Demiröz Fall 2011 CS 201 Introduction to Computing

A Motherboard

Page 38: Gülşen Demiröz Fall 2011 CS 201 Introduction to Computing

Central Processing Unit (CPU) CPU chips

Core 2 Duo (top)Intel 4004 (bottom)

Moore’s Lawchip “size” (# transistors) doubles

every 12--18 months for the same price (formulated in 1965)

processing power increases

Intel 4004: 2,300 transistorsIntel Core 2 Duo: 291,000,000

transistors

Intel 4004

Intel Core 2 Duo