introduction introduction to computer science i - comp 1005, 1405 instructor : behnam hajian...

61
INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian [email protected]

Post on 19-Dec-2015

231 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca

INTRODUCTION

Introduction to Computer Science I - COMP 1005, 1405

Instructor : Behnam Hajian

[email protected]

Page 2: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca

Attention: A large amount of material in this set of

slides has gotten from course notes prepared by Dr. Mark Lanthier.

Page 3: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca

Objectives and syllabus

The objectives in this course is To indentify the basic view of architecture of

a computer. To expose students to a high level

programming language (i.e., java). To make students learn the basic

programming concepts.

Page 4: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca

Where are you?

Where you are?

What you learn?

Page 5: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca

Objectives and syllabus

An introduction to Computer Science and Problem Solving.

Variables and Object. Data Structure. Control statements (if-else, switch-case). Loops (while, for). 2D graphics. Array, and list. Methods and Functions. Calculations, Formatting and Conversions. Sorting. Recursion. Shared data

Page 6: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca

Evaluation, Course information:Evaluation: 6 programming assignments:30% 3 Quizzes (in-class exams):30% Tutorials participation 10% Final Exam: 30%Website: Course material will be available on WebCT or the course

link in my webpage. https://lms.carleton.ca/webct OR

http://people.scs.carleton.ca/~bhajian/comp1005/winter2012

Lectures: Monday&Wednesday 14:35 PM – 15:55 PM@ 103

Steacie Building (SC).

Page 7: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca

Course information

Office hours: Monday & Wednesday 4PM - 5 PM @

HP 5331TextBook: Course notes of Introduction to

Computer Science 1 mainained by Mark Lantier uploaded in WebCT.

References: Getting Started with Processing,

Casey Reas and Ben Fry http://processing.org/shop/

Page 8: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca

Computers

What is a computer? A computational device Logical decisions billions of times faster than

humans Hardware

keyboard, screen, disks, memory, CPU Software

email, word processing, spreadsheets, OS

Page 9: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca

What are Computers Used For? Communications: Internet, e-mail, cell

phones Word Processing: typing/printing documents Business Applications: accounting,

spreadsheets Engineering Applications: scientific analysis,

simulations Database Management: police records, stock

market Entertainment: games, multimedia

applications Manufacturing: CAD/CAM, robotics, assembly ... many more ...

Page 10: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca

Who is Involved With Computers ?

System/Hardware Designers = people that design computers and related products.

Manufacturers = people that actually build and assemble computers.

Software Designers = people that design applications to be used with the computers.

Programmers = people that write computer programs to achieve working applications, games and other software packages.

End User = people that buy and use the software when it is done. We are going to play the role of the Programmer in

this course.

Page 11: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca
Page 12: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca

Computer Organization

Input unit keyboard, microphone

Output unit screen, printer

Memory unit Random Access Memory (RAM)

short-term, rapid access, low capacity warehouse Read only memory ROM

Smaller amount of memory stable when power off. Stores enough code to boot system

Page 13: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca

Computer Organization

Secondary storage unit disks, tapes

long-term, slow access, high capacity warehouse

Central Processing Unit (CPU): Microprocessor (Intel Pentium, Motorola power PC): fetches machine instructions from memory, executes them Arithmetic and logic unit (ALU)

calculations, comparisons CU (Control Unit)

coordinator, administrator,

Page 14: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca

Computer Architecture

CPU

Program Control Unit

ALU

Memory I/O

Page 15: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca

What is a program ?

A program is traditionally known as: a sequence of instructions that can be

executed by a computer to solve some problem.

In this course, we will learn to write our own programs to solve some very simple problems.

Page 16: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca

How do we write good programs ?

Page 17: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca

What is a programming language ?

Page 18: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca

What is Procedural programming ?

Page 19: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca

What is Object-Oriented programming ?

Page 20: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca

Processing

Page 21: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca
Page 22: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca
Page 23: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca

Each program is called a “sketch” in Processing. The top left play button starts your program which brings up a window (shown yellow here with a picture of a teddy bear). Since, many processing programs are meant to be animations, there is also a stop button beside the play button to stop the program. You should explore the Processing IDE (i.e., Integrated Development Environment) a little to get used to it.

Processing uses the same syntax as JAVA. That means, Processing code looks almost exactly like JAVA code. So when you are programming in Processing, you are actually learning JAVA as well. However, Processing has been designed in a way that makes it easier to get you started because some of the overhead in getting your first program working is hidden.

As you may recall, Processing is a graphics-based language and therefore we will spend a lot of time and effort drawing various things on the screen. When drawing anything, it is important to specify where you want to draw.

Page 24: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca

The JAVA Programming Language

JAVA is a very popular object-oriented programming language from SUN Microsystems. It has become a basis for new technologies such as: Enterprise Java Beans (EJB’s), Servlets and Java Server Pages (JSPs) , etc. In addition, many packages have been added which extend the language to provide special features:

Java Media Framework (for video streaming, webcams, MP3 files, etc)

Java 3D (for 3D graphics) J2ME (for wireless communications such as cell

phones, PDAs)

Page 25: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca

Why java?

Page 26: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca

Writing a program in Processing Use Java syntax. In order to tell computer what to do, we

have to use Instructions. They are called statements.

Each statement follow a specific syntax. Each statement end with Semicolons ; Compiling is the process of converting a

program into instructions that can be understood by the computer.

Page 27: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca

As you may recall, Processing is a graphics-based language and therefore we will spend a lot of time and effort drawing various things on the screen. When drawing anything, it is important to specify where you want to draw.

Page 28: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca
Page 29: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca
Page 30: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca
Page 31: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca
Page 32: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca
Page 33: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca
Page 34: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca

Colors in Processing

Page 35: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca

More graphical functions

Page 36: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca

Some important comments on java Java is a case sensitive language. Most of the library names start with capital letters. In order to complete your code in netbeans you can

use control + space keys.

Page 37: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca

Problem Solving

Page 38: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca
Page 39: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca

Understand the Problem

Page 40: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca

Formulation of Problem

Page 41: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca

Example

Page 42: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca

Develop and Algorithm

Page 43: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca
Page 44: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca
Page 45: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca
Page 46: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca
Page 47: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca

Write the program

Page 48: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca
Page 49: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca

Test the Program

Page 50: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca

Solution evaluation

Page 51: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca

Abstraction

Abstraction is the process of reducing or factoring out details that are not necessary in order to describe an algorithm

Page 52: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca
Page 53: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca

Algorithm efficiency

Algorithm efficiency is used to describe properties of an algorithm relating to how much of various types of resources it consumes. (Wikipedia)

Page 54: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca
Page 55: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca
Page 56: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca
Page 57: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca
Page 58: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca
Page 59: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca

Difference between print and println The first line uses print while the second

line uses println. When using just print, the next text to be printed will be immediately to the right of this text.

When using println, a line feed and carriage return is printed, which means that the text to follow will appear at the beginning of the next line of the console (i.e., output window).

Page 60: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca

Example:

Page 61: INTRODUCTION Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian bhajian@scs.carleton.ca

QUESTIONS?