Algorithms and Programming Languages CS 1 Rick Graziani Cabrillo College Spring 2011.

Slides:



Advertisements
Similar presentations
ICS103 Programming in C Lecture 1: Overview of Computers & Programming
Advertisements

Lecture 1: Overview of Computers & Programming
Prof. B. I. Khodanpur HOD – Dept. of CSE R. V. College of Engineering. ID: Subject: Computer Fundamentals (For EDUSAT) Common.
A Good Manager? Find and explain on an example
Mr Manesh T Dept. of CSE College of Arts and Science Chapter 3 Types of Softwares Code: 1400 Tech.
Programming Creating programs that run on your PC
The Analytical Engine Module 6 Program Translation.
Computers: Tools for an Information Age
CS 104 Introduction to Computer Science and Graphics Problems Software and Programming Language (2) Programming Languages 09/26/2008 Yang Song (Prepared.
Chapter 3 Software Two major types of software
Programming. Software is made by programmers Computers need all kinds of software, from operating systems to applications People learn how to tell the.
Software Development CS 1 Rick Graziani Spring 2007.
1 Programming Languages Examples: C, Java, HTML, Haskell, Prolog, SAS Also known as formal languages Completely described and rigidly governed by formal.
COMPUTER SOFTWARE Chapter 3. Software & Hardware? Computer Instructions or data, anything that can be stored electronically is Software. Hardware is one.
CS102 Introduction to Computer Programming
© Paradigm Publishing Inc Chapter 12 Programming Concepts and Languages.
Principles of Programming Chapter 1: Introduction  In this chapter you will learn about:  Overview of Computer Component  Overview of Programming 
PROGRAMMING LANGUAGES The Study of Programming Languages.
Programming Languages – Coding schemes used to write both systems and application software A programming language is an abstraction mechanism. It enables.
Introduction to Computer Programming itc-314
Introduction to Programming Lecture Number:. What is Programming Programming is to instruct the computer on what it has to do in a language that the computer.
 2008 Pearson Education, Inc. All rights reserved Introduction to Computers, the Internet and World Wide Web.
COMPUTER SOFTWARE Section 2 “System Software: Computer System Management ” CHAPTER 4 Lecture-6/ T. Nouf Almujally 1.
Topics Introduction Hardware and Software How Computers Store Data
Programming Languages Part 2 CS 1 Rick Graziani Spring 2008.
COMPUTER PROGRAMMING Source: Computing Concepts (the I-series) by Haag, Cummings, and Rhea, McGraw-Hill/Irwin, 2002.
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
4 - 1 Copyright © 2006, The McGraw-Hill Companies, Inc. All rights reserved.
Evolution of Programming Languages Generations of PLs.
COMPUTER PROGRAMS AND LANGUAGES Chapter 4. Developing a computer program Programs are a set (series) of instructions Programmers determine The instructions.
Programming Languages: History & Traditional Concepts CSC 2001.
TMF1013 : Introduction To Computing Lecture 1 : Fundamental of Computer ComputerFoudamentals.
Just as there are many human languages, there are many computer programming languages that can be used to develop software. Some are named after people,
Copyright © 2007 Addison-Wesley. All rights reserved.1-1 Reasons for Studying Concepts of Programming Languages Increased ability to express ideas Improved.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 1- 1 October 20, October 20, 2015October 20, 2015October 20,
Lead Black Slide. © 2001 Business & Information Systems 2/e2 Chapter 5 Information System Software.
Problem Solving Techniques. Compiler n Is a computer program whose purpose is to take a description of a desired program coded in a programming language.
INTRODUCTION TO COMPUTING CHAPTER NO. 04. Programming Languages Program Algorithms and Pseudo Code Properties and Advantages of Algorithms Flowchart (Symbols.
Liang, Introduction to C++ Programming, (c) Chapter 1 Introduction to Computers, Programs, and C++
What is Programming? A program is a list of instructions that is executed by a computer to accomplish a particular task. Creating those instructions is.
Computer Programming CS 1 Introduction to Computers and Computer Technology Rick Graziani Fall 2015.
Principles of Programming Chapter 1: Introduction  In this chapter you will learn about:  Overview of Computer Component  Overview of Programming 
Introduction to Computer Programming itc-314 Lecture 04.
Lecture #1: Introduction to Algorithms and Problem Solving Dr. Hmood Al-Dossari King Saud University Department of Computer Science 6 February 2012.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
PROGRAMMING (1) LECTURE # 1 Programming and Languages: Telling the Computer What to Do.
Programming Logic and Design Seventh Edition Chapter 1 An Overview of Computers and Programming.
Evolution and History of Programming Languages
Basic Concepts: computer, program, programming …
CS 1 Introduction to Computers and Computer Technology
CSCI-235 Micro-Computer Applications
Introduction of Programming Languages
Contents Todays Topic: Introduction to Computer Software We will learn
Computer Programming.
Chapter 12 Programming Concepts and Languages.
Software Programming J. Holvikivi 2014.
Chapter 1 Introduction(1.1)
High Level Programming Languages
Introduction to Computer Programming
Lecture 8 Programming Paradigm & Languages. Programming Languages The process of telling the computer what to do Also known as coding.
Tonga Institute of Higher Education IT 141: Information Systems
Tonga Institute of Higher Education IT 141: Information Systems
Programming Logic and Design Eighth Edition
Presentation transcript:

Algorithms and Programming Languages CS 1 Rick Graziani Cabrillo College Spring 2011

Rick Graziani Algorithm An algorithm is an ordered set of unambiguous, executable steps that defines a terminating process. Algorithms are part of many activities, even mundane ones. Note: Researchers believe that the human mind including imagination, creativity, and decision making, is actually the result of algorithm execution. –This is used in artificial intelligence

Rick Graziani Example Obtain a basket of unshelled peas and an empty bowl. As long as there are unshelled peas in the basket continue to execute the following steps: a. Take a pea from the basket b. Break open the pea pod c. Dump the peas from the pod into the bowl d. Discard the pod

Rick Graziani Defining the Algorithm An algorithm is an ordered set of unambiguous, executable steps that defines a terminating process. –Steps do not have to be executed in sequence. Non-Terminating Sequence: –Make a list of positive integers. –The above requirement could not be performed in an algorithm, because it does not terminate (it is infinite). Unambiguous –The instructions must be clear, specific and direct –No room for creativity or interpretation … (this could go on for ever!) Non-terminating sequence Ambiguous Organize the CDs(By title? By artist? By genre?)

Rick Graziani Abstract Nature of Algorithms An algorithm can represented in several ways. Example: Algorithm to convert temperatures from Celsius to Fahrenheit: –As an algebraic formula: F = (9/5)C + 32 –As a written instruction: Multiply the temperature reading in Celsius by 9/5 and then add 32

Rick Graziani Algorithm Representation Algorithm requires some form of a language. Algorithm is a form of communication –Don’t want misunderstandings –Proper level of detail –Proper level of difficulty Problems arise when: –Steps not precisely defined –Not enough detail

Rick Graziani Primitive – A well defined set of building blocks (terms) used in computer science. –Arithmetic and logic operations built into the language –Removes any ambiguity –Includes its own syntax Programming language – A collection of primitives (terms) and the rules that state how the primitives can be combined to represent more complex ideas. Algorithm Representation LOAD reg. R from cell XY Op-code Description 1LOAD reg. R from cell XY. 2LOAD reg. R with XY. 3STORE reg. R at XY. 4MOVE R to S. 5ADD S and T into R. (2’s comp.) 6ADD S and T into R. (floating pt.) 7OR S and T into R. 8AND S and T into R. 9XOR S and T into R. AROTATE reg. R X times. BJUMP to XY if R = reg. 0. CHALT.

Rick Graziani Machine language uses primitives High-level programming languages (C++, Java) use higher-level primitives, constructed from the lower-level machine language primitives. This results in an easier set of instructions to write. More later. Store the bits found in register 5 in main memory cell A7 Op-code OperandDescription 1LOAD reg. R from cell XY. 2LOAD reg. R with XY. 3STORE reg. R at XY. 4MOVE R to S. 5ADD S and T into R. (2’s comp.) 6ADD S and T into R. (floating pt.) 7OR S and T into R. 8AND S and T into R. 9XOR S and T into R. AROTATE reg. R X times. BJUMP to XY if R = reg. 0. CHALT.

Rick Graziani Pseudocode Pseudocode – A notational system in which ideas can be expressed informally during the algorithm development process. (written sentence) Used independently of the programming language. –Each programming language has its own primitives and rules. Pseudocode 1. Enter two numbers. 2. Add the numbers together. 3. Display the result.

Rick Graziani Pseudocode Conditional selection The selection of one of two possible activities depending upon the truth or falseness of some condition if condition then action or if condition then (activity) else (activity) If this condition is true, perform this activity. If (sunny) then (put on sunscreen) If this condition is true, perform this activity, otherwise perform a different activity. If (sunny) then (go swimming) else (go bowling)

Rick Graziani Repeating structure Another common semantic structure is the repeated execution of a statement or sequence of statements as long as some condition remains true. while condition do activity Also known as a while loop Examples: while (tickets remain to be sold) do (sell a ticket)

Rick Graziani Repeating structure Task: Write Hello 500 times. Pseudocode Counter = 1 While counter is less than or equal to 500, write the word “Hello” and add 1 to Counter. Programming Code Counter = 1 While (counter <= 500) do (print “Hello”; Counter  Counter + 1) Counter 1 Hello Hello …

Rick Graziani For loop A for loop can be used to accomplish the same thing as a while loop. Note: There are some differences between while and for loops. Counter = 1 For (Counter <= 500) do (print the message “Hello”; Counter  Counter + 1) Counter 1 Hello Hello …

Rick Graziani “I want you to write on the chalk board, ‘I will not throw paper airplanes in class’, 500 times.”

Software Development

Rick Graziani Definitions Software or Program Instructions that tell the computer what to do Programmer Someone who writes computer programs

Rick Graziani Instruction Set A vocabulary (list) of instructions which can be executed by the CPU The only instructions the CPU can run or execute Example of a CPU’s Instruction Set CPU Instruction Set

Rick Graziani First Generation Languages (Machine Language) Programming computers using the CPU’s instruction set Also known as Machine Language (timeline) Machine Code File A software file which contains the instructions from the CPU’s instruction set.

Rick Graziani Advantages of First Gen. Software programs execute (run) relatively very quickly Software programs are relatively small in size (Insignificant advantages today) Disadvantages of First Gen. Difficult to write, very detailed and takes a long time Difficult to read Difficult to debug debug = the process to find mistakes in a software program First Generation Languages (Machine Language)

Rick Graziani Second Generation Languages (Assembly Language) Assembly Language = The English-like instructions which are equivalent to the CPU’s instruction set Source Code= The actual instructions written by a programmer Compiler = Software which translates source code instructions of a particular language into machine code Op-code Description 1LOAD reg. R from cell XY. 2LOAD reg. R with XY. 3STORE reg. R at XY. 4MOVE R to S. 5ADD S and T into R. (2’s comp.) 6ADD S and T into R. (floating pt.) 7OR S and T into R. 8AND S and T into R. 9XOR S and T into R. AROTATE reg. R X times. BJUMP to XY if R = reg. 0. CHALT.

Rick Graziani Question: Which of these two files (source code file or machine code file) will the user need to run this software program? Advantages of Second Gen. Easier to read than first gen. Easier to write than first gen. Easier to debug than first gen. Disadvantages of Second Gen. Still very difficult to write programs Second Generation Languages (Assembly Language)

Rick Graziani Using a compiler

Rick Graziani Third Generation Languages (High level languages) Languages which are somewhere between machine language and the human language. FORTRAN (Formula Translation) 's Language to allow scientists and engineers to program computers. COBOL (Common Business Oriented Language) Language primarily designed for US government and defense contractors to program business applications on the computer. Grace Hopper was one of the developers of COBOL. BASIC (Beginner's All-purpose Symbolic Code) 's Alternative language to FORTRAN for beginning programming students.

Rick Graziani Pascal (named after Blaise Pascal, 17th century French mathematician) 's Language to teach proper structured programming. Structured programming = Programming technique used to make programming more productive and easier to write. Stresses simplistic, modular programs. ADA (named after Ada Lovelace (programmed the 19th century 'analytical engine') - late 1970's Language developed to replace COBOL. Third Generation Languages (High level languages)

Rick Graziani C (successor to BCPL or "B") 's Popular programming language on computers from microcomputers to super computers. Faster and more efficient language. Very powerful language. Source code example of a C Program (Displays Hello World! on the screen.) #include main() { printf("Hello World!"); } C++ (pronounced "C plus plus") 's Object oriented language which is compatible with C. JAVA Third Generation Languages (High level languages)

Rick Graziani Advantages Easier to read, write and debug Faster creation of programs Disadvantages Still not a tool for the average user to create software programs Requires very good knowledge of programming and of the language Third Generation Languages (High level languages)

Rick Graziani Writing a Software Program Steps in writing a software program 1. Hardware (CPU) 2. Operating System 3. Programming Language 4. Brand of Compiler 5. Writing the Program

Rick Graziani Task Write a program to convert binary numbers to decimal and decimal numbers to binary Writing a Software Program

Rick Graziani 1. Determine what kind of computer you want your program to run on Macintosh? PC? Writing a Software Program

Rick Graziani 2. Determine which operating system this computer (and the user) will be using Windows Vista? Mac OSX? Linux? Writing a Software Program

Rick Graziani 3. Determine which language you will be programming in. C? C++? Java? C++ Writing a Software Program

Rick Graziani 4. Determine the compiler for your language, operating system and hardware Microsoft Visual C++? Borland C++? Watkins C++? Microsoft Visual C++ Writing a Software Program

Rick Graziani 5. Write the program Writing a Software Program

Rick Graziani Compile the program into a machine code file and distribute it to the users via floppy diskette. Writing a Software Program

Rick Graziani Fourth Generation Languages Languages which are more like natural human languages uses English phrases common with data base languages search for name equals “graziani” and state equals “ca” Examples dBase FoxPro Access Oracle Informix SQL

Rick Graziani Fourth Generation Languages Advantages Average users can quickly learn to “query” the database Average users can easily learn how to write programs Programs are written faster Disadvantages Can not write sophisticate programs like word processors, graphics, etc. Mostly for data base applications like phone information.

Rick Graziani The Year 2000 What is the big deal? Older computer systems limited RAM memory limited disk storage slower processors (CPUs) The YEAR was stored using two bytes instead of four bytes, in order to save bytes in RAM and storage 67 instead of 1967

Rick Graziani Example: 500,000 records Save 1 million bytes 500,000 x 4 bytes (19xx) = 2 million bytes 500,000 x 2 bytes (xx) = 1 million bytes less storage on disk less RAM memory needed faster processing The Year 2000 What is the big deal?

Rick Graziani Problem The year 2000 will be “00” or looked at by the computers as the year “1900” Will cause miscalculations for everything from pension funds to horoscopes. The Year 2000 What is the big deal?

Databases and Relationships

Rick Graziani Relationships One-to-One One-to-Many Many-to-Many

Rick Graziani One-to-One Relationships

Rick Graziani One-to-Many Relationships

Rick Graziani Many-to-Many Relationships (Not recommended)

Programming Languages Part 2

Rick Graziani Goal of third generation languages Goal of third generation languages (C, C++, Java): –Statements (language) do not refer to the attributes of any particular machine Statements not part of the CPU’s machine language Program written an a third generation language could theoretically be compiled to run on any other computer. –In reality this is not completely accurate Op-code OperandDescription 1LOAD reg. R from cell XY. 2LOAD reg. R with XY. 3STORE reg. R at XY. 4MOVE R to S. 5ADD S and T into R. (2’s comp.) 6ADD S and T into R. (floating pt.) 7OR S and T into R. 8AND S and T into R. 9XOR S and T into R. AROTATE reg. R X times. BJUMP to XY if R = reg. 0. CHALT.

Rick Graziani

Rick Graziani

Rick Graziani Programming language standards Programming language (C, C++, Java): –Standard commands –Vendor’s options Standard organizations: –ANSI (American National Standards Institute) –ISO (International Organization for Standardization) ISO is not a TLA but meaning “equal” in Greek

Rick Graziani Vendor Compiler Options Vendor compiler options: –Language extensions –Features to make it easier to program –Not compatible with other vendor’s compilers –Makes it difficult to change to another vendor’s compiler

Rick Graziani Evolution of Programming Languages Lineage does not represent that one language evolved from another, although this is the case with some languages.

Rick Graziani Evolution of Programming Languages

Rick Graziani Evolution of Programming Languages

Rick Graziani Procedural Languages –Traditional approach to programming. –Procedure is a sequence of commands which can be used multiple times by the main set of instructions. Procedural Languages include: –Fortran, COBOL, BASIC, ADA, Pascal, C Main Program Procedure 1 Procedure 2 Procedure 3

Rick Graziani Object Oriented Programming Object Oriented Programming (OOP) –Software system is viewed as a collection of units, called objects. –Object – has the capability of performing certain actions and to call other objects. Example: Screen icons –Each icon is an object –Each object encompasses a collection of procedures known as methods –Each method describes how that object will respond to events such as: Double left click (run the program) Right click (display a series of options) Example OOP Languages: C++, Visual Basic, Java Left click Right click

Rick Graziani Other types of languages Other types of languages include: –Functional languages: LISP, Scheme –Declarative languages: Prolog –Scripting languages: Perl, PHP, shell scripts, HTML

Rick Graziani Programming Concepts Program consists of: –Declarative statements Variables and data types –Imperative statements Procedures, instructions, and algorithms –Comments Enhance readability Used throughout the program

Rick Graziani Variables and Data Types Variable – A location in RAM (main memory), given a descriptive name, which stores information. Data type – Variables are a type of day which can be: –Number Integer: 0, 1, 2, 3, 4, 5, 6, etc. Real (floating point): 9.75, –Character: a, b, c, A, B, C, etc. –String of text: “123 Main Street” Working area or scratch pad for the program d Integer Float Character Variable

Rick Graziani Programming Concepts Count 1 I will not throw paper airplanes in class. 2 3 … 499 I will not throw paper airplanes in class. 500 I will not throw paper airplanes in class. 501 Variable Count which is type integer

Rick Graziani Variables Variables are declared, defined in the declaration section of the program. –Usually at the beginning of the program –Examples: int height_in_inches char first_initial float price

Rick Graziani Variables Variables: –Can be given an initial value within the program –Value may change from: Program instructions User input Count 1 I will not throw paper airplanes in class. 2 3 … 499 I will not throw paper airplanes in class. 500 I will not throw paper airplanes in class. 501

Rick Graziani Data structure Variables are often associated with a data structure. Data structure – A conceptual shape of arrangement of data Homogeneous Array –Block of values of the same type –Such as a one dimensional list or a two dimensional array (row, column) Example: String or array of characters –char Last_Name[25] … … B o o l o o char Last_Name[25]

Rick Graziani Data structure Two dimensional array –Row and column –Integer pins [bowler, frame] Dan Sue Gary Mary Integer pins [bowler, frame] Frame pins [Mary, 2] = 7

Rick Graziani Assigning Value Assignment statement – Statement which assigns a value to a variable. –Value assigned from user input –Value assigned from another variable –Value assigned from a specific value –Value assigned from a calculation that can include both variables and assigned values d Integer Float Character Fahrenheit = (9/5)Celcius + 32

Rick Graziani Open Source Software Open source software is computer software for which the human-readable source code is made available under a copyright license (or arrangement such as the public domain) that meets the Open Source Definition. This permits users to: –Use the software –Change the software –Improve the software –Redistribute it in modified or unmodified form It is often developed in a public, collaborative manner. Wikipedia

Rick Graziani Open Source Definition 1. Free Redistribution: the software can be freely given away or sold. 2. Source Code: the source code must either be included or freely obtainable. (Without source code, making changes or modifications can be impossible.) 3. Derived Works: redistribution of modifications must be allowed. 4. Integrity of The Author's Source Code: licenses may require that modifications are redistributed only as patches. 5. No Discrimination Against Persons or Groups: no one can be locked out. 6. No Discrimination Against Fields of Endeavor: commercial users cannot be excluded. 7. Distribution of License: The rights attached to the program must apply to all to whom the program is redistributed without the need for execution of an additional license by those parties. 8. License Must Not Be Specific to a Product: the program cannot be licensed only as part of a larger distribution. 9. License Must Not Restrict Other Software: the license cannot insist that any other software it is distributed with must also be open source. 10. License Must Be Technology-Neutral: no click-wrap licenses or other medium-specific ways of accepting the license must be required.

Rick Graziani Projects Apache Software Foundation Audacity Blender -- 3d animation CodePlex Debian Drupal -- Content Management System Eclipse Foundation Fedora Project FreeBSD Freedesktop.org Free Software Foundation FUSE ESB, FUSE Message Broker, FUSE Services Framework and FUSE Mediation Router - Supported versions of Apache projects GIMP -- Image Editing similar to photoshop GNU Inkscape -- Vector tool similar to illustrator Java JBoss Joomla! -- Content Management System KnowledgeTree -- Document Management for Teams and Small to Medium-sized Organizations LibreSource Linux Macaulay2 -- algebraic geometry and commutative algebra Miranda IM -- multiprotocol IM Mozilla Foundation MySQL NetBSD OpenBSD Open-Xchange Open Market For Internet Content Accessibility OpenOffice.org -- Word processor, spreadsheet, presentation tool, database, equation editor OpenSees -- open system for earthquake engineering simulation OpenSuse Open Solutions Alliance Open Source Development Labs Open Source Initiative Open Source Geospatial Foundation PHP -- Hypertext preprocessor Povray -- Ray Tracer Python Restore -- RESTORE is an open source project for heterogeneous system backup and restore. SAGE -- Magma computer algebra system Scribus -- Desktop publishing similar to pagemaker SourceForge -- Repository of open source software Subversion (software) -- version control Synfig -- 2d vector graphic and animation TYPO3 -- Enterprise Level Content Management System ubuntu Zenoss Zimbra

Algorithms and Programming Languages CS 1 Rick Graziani Cabrillo College Spring 2011