CMPT 120 Introduction to Computer Science and Programming

  • Slides: 19
Download presentation
CMPT 120 Introduction to Computer Science and Programming I Chris Schmidt

CMPT 120 Introduction to Computer Science and Programming I Chris Schmidt

CMPT 120 n What will you learn? n Basic concepts of Computing Science How

CMPT 120 n What will you learn? n Basic concepts of Computing Science How computers store some types of data n Algorithms (methods of solving problems) n Data Structures (how to store complex data) n How to analyze and compare algorithms n How to write programs in Python n

Computing Science n Comput-ing Science The majority of the time we aren’t concerned with

Computing Science n Comput-ing Science The majority of the time we aren’t concerned with the computer itself (hardware) n The main concern is the creation, analysis, and application of algorithms n Hard to pin down a good definition n

Computing Science n Computing Science is an extremely diverse field ranging from the completely

Computing Science n Computing Science is an extremely diverse field ranging from the completely theoretical to the very practical n Logic, Complexity and Computability, Database Management, Artificial Intelligence, Human-Computer Interaction, Graphics, Natural Language Processing, Operating Systems, Programming Languages, Networking, Bioinformatics, Computer Architecture, Software Engineering

The Basics n Hardware Physical equipment (processor, monitor, keyboard, printer…) n If you can

The Basics n Hardware Physical equipment (processor, monitor, keyboard, printer…) n If you can touch it, it’s hardware n n Software n Programs (sets of instructions) that run on the hardware

Hardware n Some Basic Computer Components n CPU: Central Processing Unit n n n

Hardware n Some Basic Computer Components n CPU: Central Processing Unit n n n Memory n n n Hard Disk, CD-Rom, etc. Input n n ROM: Read Only Memory RAM: Random Access Memory Storage n n The computer’s central “brain” ALU: Arithmetic and Logic Unit Keyboard, Mouse… Output n Monitor, Printer…

Software n Computer Program n n A set of instructions that the computer will

Software n Computer Program n n A set of instructions that the computer will complete The instructions that are used are defined by a programming language

Programming Languages n High Level Languages The languages you usually here about are high

Programming Languages n High Level Languages The languages you usually here about are high level languages (Python, C++, Java, Visual Basic. . n These languages are used to write the everyday applications we see n Use complex instructions that can’t be “directly” understood by a computer’s hardware n

High Level Code (Python) metres = float(raw_input(  "Enter your height (in metres): "))

High Level Code (Python) metres = float(raw_input( "Enter your height (in metres): ")) total_inches = 39. 37 * metres feet = int(total_inches/12) inches = total_inches - feet*12 print "You are " + str(feet) + " feet and " + str(inches) + " inches tall. "

Programming Languages n Machine Language n Processors have a small set of simple instructions

Programming Languages n Machine Language n Processors have a small set of simple instructions they understand n Access/store a value, add two values, compare two values, … Different processor types have different instructions n Each instruction is identified by a unique number n

Programming Languages n Assembly Language Machine language is difficult for humans to work with

Programming Languages n Assembly Language Machine language is difficult for humans to work with directly (its all numbers) n Assembly Language is one step higher n The instructions are given short names (mnemonics) so it is readable n A compiler converts the text of a program in assembly language into the appropriate Machine Language n

Assembly Language Code ORG $0000 N 1 DB %11110100 N 2 DB !41 ANS

Assembly Language Code ORG $0000 N 1 DB %11110100 N 2 DB !41 ANS 1 RMB 1 ANS 2 RMB 1 ORG $0010 START LDS #00 FF LDD #!0 LDX #!0 LDY #!0 PSHA LDAA N 1 PSHA. .

Programming Languages n Back to High Level Languages Instead of using the simple instructions

Programming Languages n Back to High Level Languages Instead of using the simple instructions of assembly language we work with more readable high level languages n As with assembly language a compiler or interpreter is needed to convert the code to the machine language n

Python n Interpreted vs Compiled languages (C++, Java) are written as text and then

Python n Interpreted vs Compiled languages (C++, Java) are written as text and then must be compiled into machine code n Interpreted languages (Python) are written as text, but do not need to be compiled. When run, an interpreter, converts the code line by line n

Advantages n Compiling n n Faster at runtime, no translation to machine code needed

Advantages n Compiling n n Faster at runtime, no translation to machine code needed Interpreting More flexibility when editing, don’t have to recompile every time you want to test a change n More flexible at runtime (though we probably won’t take advantage of this in 120) n

Hello World! n n The first program people often write simply tells the computer

Hello World! n n The first program people often write simply tells the computer to print the phrase “Hello World!” The simplicity of a language can be seen to some extent by how complex the code needed to do this is.

Hello World! n n Python print "Hello World!" C++ #include <iostream> using namespace std;

Hello World! n n Python print "Hello World!" C++ #include <iostream> using namespace std; int main (){ cout << "Hello World!"; return 0; } n Java public class Hello. World { public static void main(String[] args) { System. out. print("Hello World!"); } }

Python Powers of Two print "The first ten powers of 2. " x=1 for

Python Powers of Two print "The first ten powers of 2. " x=1 for i in range(10): print x, x=x*2

C++ Powers of Two #include <iostream> using namespace std; int main (){ int x

C++ Powers of Two #include <iostream> using namespace std; int main (){ int x = 1; cout << "The first ten powers of 2. n"; for (int i=0; i < 10; i++){ cout << x << " "; x = x*2; } return 0; }