1 / 69

CSC 131 - Introduction to Computer Science I

CSC 131 - Introduction to Computer Science I. Devon M. Simmonds Computer Science Department University of North Carolina Wilmington Wilmington, NC 28403 simmondsd@uncw.edu http://www.uncw.edu/people/simmondsd/ _____________________________________________________________. Overview.

efrem
Download Presentation

CSC 131 - Introduction to Computer Science I

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSC 131 - Introduction to Computer Science I Devon M. Simmonds Computer Science Department University of North Carolina Wilmington Wilmington, NC 28403 simmondsd@uncw.edu http://www.uncw.edu/people/simmondsd/ _____________________________________________________________

  2. Overview • To understand computer basics, programs, and operating systems • Course motivation • Introduction to algorithm design • Overview of Python programming language

  3. What is a Computer? A computer consists of a CPU, memory, hard disk, floppy disk, monitor, printer, and communication devices. M o t I v a t I o n

  4. CPU The central processing unit (CPU) is the brain of a computer. It retrieves instructions from memory and executes them. The CPU speed is measured in megahertz (MHz), with 1 megahertz equaling 1 million pulses per second. The speed of the CPU has been improved continuously. If you buy a PC now, you can get an Intel Pentium 4 Processor at 3 gigahertz (1 gigahertz is 1000 megahertz). M o t I v a t I o n

  5. Memory Memory is to store data and program instructions for CPU to execute. A memory unit is an ordered sequence of bytes, each holds eight bits. A program and its data must be brought to memory before they can be executed. A memory byte is never empty, but its initial content may be meaningless to your program. The current content of a memory byte is lost whenever new information is placed in it. M o t I v a t I o n

  6. How Data is Stored? Data of various kinds, such as numbers, characters, and strings, are encoded as a series of bits (zeros and ones). Computers use zeros and ones because digital devices have two stable states, which are referred to as zero and one by convention. The programmers need not to be concerned about the encoding and decoding of data, which is performed automatically by the system based on the encoding scheme. The encoding scheme varies. For example, character ‘J’ is represented by 01001010 in one byte. A small number such as three can be stored in a single byte. If computer needs to store a large number that cannot fit into a single byte, it uses a number of adjacent bytes. No two data can share or split a same byte. A byte is the minimum storage unit. M o t I v a t I o n

  7. Storage Devices Memory is volatile, because information is lost when the power is off. Programs and data are permanently stored on storage devices and are moved to memory when the computer actually uses them. There are three main types of storage devices:Disk drives (hard disks and floppy disks), CD drives (CD-R and CD-RW), and Tape drives. M o t I v a t I o n

  8. Output Devices: Monitor The monitor displays information (text and graphics). The resolution and dot pitch determine the quality of the display. M o t I v a t I o n

  9. Monitor Resolution and Dot Pitch resolution The resolution specifies the number of pixels per square inch. Pixels (short for “picture elements”) are tiny dots that form an image on the screen. The resolution can be set manually. The higher the resolution, the sharper and clearer the image is. However, the image may be very small if you set high resolution on a small screen monitor. PC monitors are usually 15-inch, 17-inch, 19-inch, or 21-inch. For a 15-inch monitor, a comfortable resolution setting would be 640480 (307,200 pixels). dot pitch The dot pitch is the amount of space between pixels. The smaller the dot pitch, the better the display. M o t I v a t I o n

  10. Communication Devices A regular modem uses a phone line and can transfer data in a speed up to 56,000 bps (bits per second). A DSL (digital subscriber line) also uses a phone line and can transfer data in a speed 20 times faster than a regular modem. A cable modem uses the TV cable line maintained by the cable company. A cable modem is as fast as a DSL. Network interface card (NIC) is a device to connect a computer to a local area network (LAN). The LAN is commonly used in business, universities, and government organizations. A typical type of NIC, called 10BaseT, can transfer data at 10 mbps (million bits per second). M o t I v a t I o n

  11. Motivation • Computer science, the science of solving problems with the aid of a computer • Artificial intelligence • Database management systems • Distributed systems • Computer graphics • Operating systems • Software engineering All of these areas of study revolve around one fundamental question: how can we solve problems using computers? M o t I v a t I o n

  12. ??? M o t I v a t I o n • Solving problems with the aid of a computer • instruct the computer to do what we want ? • Humans communicate through naturallanguages: English, Spanish, French, etc. • The computer has its own language! • Bits and bytes, 0’s and 1’s – machine language • So humans and computers speak different languages! • 1st Problem: • How do we give instructions to a computer to do what we want it to do if we speak different languages?

  13. ??? M o t I v a t I o n • What language should the interpreter speak? • Human language • Machine language • Interpreter translates human language into machine language • 2nd Problem: • Human language is ambiguous! Employ an Interpreter

  14. M o t I v a t I o n Human language Programming language Machine language • 2nd Problem: Human language is ambiguous: • Create a language for writing instructionsfor a computer – programming language • Interpreter translates instructions written in a programming language into machine code. • The process of writing instructions for a computer to execute is called programming. Interpreter

  15. M o t I v a t I o n Programming? • Programming - the process of using a programming language to write instructions for a computer. • There are two general steps involved in programming: algorithmic design, coding. • Algorithmic design: • Before you can ask a computer to solve a problem, you must figure out what the computer needs to do in order to reach a solution. • Algorithmic design is the process of describing in human terms what the computer needs to do to solve the problem. • An algorithm is a sequence of instructions to solve a problem. • Coding • After you have determined what the computer needs to do, and written it as an algorithm, you need to expressthe algorithm using a programming language (C, C++, Java, LISP, Prolog, Python, COBOL, etc.). • A sequence of instructions written in a programming language is called a program or code.

  16. What is this course about? • This course is about solving problems • Before solving a problem, we must first understand the problem • Many solutions are possible for a given problem • Each solution should be expressed as a separate algorithm before being converted into program code. • In this course programs will be written using the Python programming language. • This course is therefore an introduction to programming in Python. • i.e., the course is an introduction to expressing solutions to programming problems as written algorithms and converting written algorithms to Python programs.

  17. Course Details & Grading • Lectures • Labs • Homeworks • Programming Assignments • Quizzes • Tests Let’s Visit the Course Web Page

  18. The Man without a Face, oil on panel, 11x14, 2005 – Dae-Woong Nam The Getting to Know You Roll Call • Background • Where from • Previous school • Programming experience

  19. Your Questions? • What are your course expectations? Your Questions? • What are your course expectations? Let’s explore…. Welcome Come with me … let’s explore this wonderful world of programming

  20. CSC 131 - Introduction to Computer Science I Algorithm Design & Introduction To Programming in Python Devon M. Simmonds Computer Science Department University of North Carolina Wilmington Wilmington, NC 28403 simmondsd@uncw.edu http://www.uncw.edu/people/simmondsd/ _____________________________________________________________ Chapters 1 & 2 of course text

  21. Problem Solving • Understand the problem • Design a solution/algorithm • Consider alternatives • Implement the solution/algorithm • Test solution and fix problems Introduction to Algorithm Design

  22. Algorithm Design Example Travelling from UNC Chappell Hill to UNC Wilmington • Solution 1: • Pick up travellers at UNC Chappell Hill • Take travellers to airport • Board travels on aircraft to Wilmington • (Aircraft flies to Wilmington airport) • Deboard passengers from aircraft • Take travellers to UNC Wilmington • Solution 2: • Pick up travellers at UNC Chappell Hill • Take travellers to dock by bus • Board travels on ship • (Ship travels to Wilmington dock) • Deboard passengers from ship • Take travellers by bus to UNC Wilmington Introduction to Algorithm Design

  23. Solution 3: The language used to express our algorithm may vary Introduction to Algorithm Design

  24. Problem Solving • Understand the problem • Design a solution/algorithm • Consider alternatives • Implement the solution/algorithm • Test solution and fix problems Introduction to Algorithm Design

  25. CSC 121: Introduction to Computer Science I Algorithm Design Example 2

  26. An algorithm A step Or statement Algorithm Design: A Robot that Makes Coffee • Problem: writing instructions for a robot to make coffee • Take coffee jar from shelf • Open coffee jar • Tip one spoonful of coffee into cup • Pour hot water into cup • Stir coffee An algorithm is a finite set of instructions for solving a problem. Introduction to Algorithm Design

  27. Coffee Making Robot Algorithm Design • Algorithm for a robot to make coffee Step 1: Take coffee jar from shelf Step 2: Open coffee jar Step 3: Tip one spoonful of coffee into cup Step 4: Pour hot water into cup Step 5: Stir coffee Each step in our algorithm must be simple enough to be executed by the robot. Introduction to Algorithm Design

  28. Coffee Making Robot Algorithm Design • Algorithm for a robot to make coffee Step 1: Take coffee jar from shelf Step 2: Open coffee jar Step 3: Tip one spoonful of coffee into cup Step 4: Pour hot water into cup Step 5: Stir coffee We need to rewtite these steps Each step in our algorithm must be simple enough to be executed by the robot. Introduction to Algorithm Design

  29. Stepwise Refinement • A solution design technique that describes a solution to a problem at a high level, and then partitions it repeatedly into more detailed levels one level at a time until the detail is sufficient to allow execution by a processor or translation into the language of the processor. Introduction to Algorithm Design

  30. Stepwise Refinement of Statements 3 & 4 /* Tip one spoonful of coffee into cup */ Extract one teaspoonful of coffee Tip teaspoonful of coffee into cup Close coffee jar /* Pour hot water into cup */ Pour hot water into cup until cup is full Introduction to Algorithm Design

  31. Coffee Making Algorithm With Steps 3 and 4 refined • Algorithm for a robot to make coffee Step 1: Take coffee jar from shelf Step 2: Open coffee jar Step 3: /*Tip one spoonful of coffee into cup*/ Extract one teaspoonful of coffee Tip teaspoonful of coffee into cup Close coffee jar Step 4: /*Pour hot water into cup*/ Pour hot water into cup until cup is full Step 5: Stir coffee Introduction to Algorithm Design

  32. Top-down Design • A problem-solving technique that repeatedly divides a complex problem into simpler and simpler parts until the parts have sufficient detail to allow execution by a processor or translation into the language of the processor. Introduction to Algorithm Design

  33. Part A.1 Part A.2 Part A.3 Part A.4 Top-down Design: Divide & Conquer Problem Part C Part A Part D Part B Part D.1 Part B.1 Part D.2 Part B.2 Part D.3 Part B.3 Part D.4 Part B.4 Introduction to Algorithm Design

  34. Top-down Design & Stepwise Refinement • Specify solution to a problem as an algorithm with a sequence of steps • Refine the algorithm by defining a separate algorithm for each step • Refine each new step of the algorithm by defining a separate algorithm for the new step • Stop refining when the instruction can be directly converted into code Introduction to Algorithm Design

  35. Top-Down Design of Coffee Making Algorithm Give robot instructions to make coffee Step 3 Step 1 Step 4 Step 2 Step 5 Step 4.1 Step 3.1 Step 3.2 Step 3.3 Introduction to Algorithm Design

  36. Algorithms • Algorithm - a set of instructions (steps) for solving a problem. • E.g., a recipe for baking

  37. Syntax and Semantics of Algorithms • Syntax: the rules governing the use of symbols or constructs in a language. The rules of the grammar. • John are in town. • Semantics: the meaning of statements in a language. • The peanut ate the elephant.

  38. Functions of an algorithm • Input • Getting data from a user or a file • Storing data in memory • Processing • Performing calculations, make decisions • Output • Printing messages and data

  39. Algorithm Design: Control Structures • Algorithm for robot to make coffee Step 1: Take coffee jar from shelf Step 2: Open coffee jar Step 3: #Tip one spoonful of coffee into cup Extract one teaspoonful of coffee Tip teaspoonful of coffee into cup Close coffee jar Step 4: #Pour hot water into cup Pour hot water into cup until cup is full Step 5: Stir coffee Control structures are ways of organizing the statements in an algorithm. Introduction to Algorithm Design

  40. Algorithm Design: Control Structures • Algorithm for robot to make coffee Step 1: Take coffee jar from shelf Step 2: Open coffee jar Step 3: #Tip one spoonful of coffee into cup Extract one teaspoonful of coffee Tip teaspoonful of coffee into cup Close coffee jar Step 4: #Pour hot water into cup Pour hot water into cup until cup is full Step 5: Stir coffee Sequence: Steps are executed one after the other in the order listed. No steps are omitted. Execution of the last step signals the end of the algorithm. Introduction to Algorithm Design

  41. The Python Programming Language Human language Programming language Machine language Communication

  42. The Python Programming Language • Conceived in the late 1980s • Implementation was started in December 1989 by Guido van Rossum at CWI in the Netherlands • A successor to the ABC programming language capable of exception handling and interfacing with the Amoeba operating system.VanRossum is Python's principal author

  43. The Python Programming Language • Python 0.9 - February 1991 • Python 1.0 - January 1994 • Python 2.0 - October 16, 2000 • Python 2.7 - July 3, 2010 • Python 3.0 - December 3, 2008 • Python 3.1 - June 27, 2009 • Python 3.2 - February 20, 2011 • Python 3.3 - September 29, 2012

  44. The Python Programming Language # Hello World program in Java public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World"); } } • # Hello World program in Python • print "Hello, World!"

  45. Algorithm  Python (Sequence ) # Algorithm to add two numbers # and print the result. Get the first number Get the second number Add the two numbers together Print the result # Python program to add two #numbers and print the result. # Get the first number num1 = 4 # Get the second number num2 = 6 # Add the two numbers sum = num1 + num2 # Print the result print (sum)

  46. Programming Languages • A programming language is a special language used to write computer programs. • A program is a set of instructions a computer follows in order to perform a task. • A computer needs its instructions to be written in machine language. • Machine language is written using binary numbers. • The binary numbering system (base 2) only has two digits (0 and 1).

  47. Programming Languages • The binary numbers are encoded as a machine language. • Each CPU has its own machine language. • Motorola 68000 series processors • Intel x86 series processors • DEC Alpha processors, etc. • Example of a machine language instruction: 1011010000000101

  48. Development of Programming Languages • In the distant past, programmers wrote programs in machine language (1st generation). • Programmers developed assembly programming languages to make things easier (2nd generation). • …but assembler was processor dependent. • Next, 3rd generation or high-level languages were developed (3GL)

  49. Programming Languages • High level programming languages are not processor dependent. • Common high-level programming languages: • BASIC • COBOL • Pascal • C • C++ • Java • Python • Alice

  50. Programming LanguagesCommon Language Elements • There are some concepts that are common to virtually all programming languages. • Key words (if, while, class, etc.) • Operators • Arithmetic (+, -, *, /, etc.) • Relational (>, <, etc.) • Punctuation • Programmer-defined identifiers • Strict syntactic rules.

More Related