CSCI N201: Programming Concepts Copyright ©2005  Department of Computer & Information Science Introducing Programming.

  • Published on
    23-Dec-2015

  • View
    220

  • Download
    4

Embed Size (px)

Transcript

  • Slide 1
  • CSCI N201: Programming Concepts Copyright 2005 Department of Computer & Information Science Introducing Programming
  • Slide 2
  • CSCI N201: Programming Concepts Copyright 2004 Department of Computer & Information Science Goals By the end of this lecture, you should Understand the different types of programming languages.Understand the different types of programming languages. Understand the basic procedures in a program as input, processing and output.Understand the basic procedures in a program as input, processing and output. Understand the importance of variables.Understand the importance of variables. Understand a basic map of the program development cycle.Understand a basic map of the program development cycle.
  • Slide 3
  • CSCI N201: Programming Concepts Copyright 2004 Department of Computer & Information Science Computer Components CPU Central Processing UnitCPU Central Processing Unit RAM (Random Access Memory)RAM (Random Access Memory) Mass storage devicesMass storage devices Input devicesInput devices Output DevicesOutput Devices
  • Slide 4
  • CSCI N201: Programming Concepts Copyright 2004 Department of Computer & Information Science Storage Capacities bit smallest capacitybit smallest capacity nibble = 4 bitsnibble = 4 bits byte = 2 nibbles = 8 bitsbyte = 2 nibbles = 8 bits storage for one character 1 kilobyte (KB) = 1024 bytes1 kilobyte (KB) = 1024 bytes 1 megabyte (MB) = 1024 KB1 megabyte (MB) = 1024 KB 1 gigabyte (GB) = 1024 MB1 gigabyte (GB) = 1024 MB
  • Slide 5
  • CSCI N201: Programming Concepts Copyright 2004 Department of Computer & Information Science Software Application SoftwareApplication Software Word Processors Database s/w Spreadsheets Painting programs Web browsers, email programs System SoftwareSystem Software Operating Systems WindowsWindows Macintosh OSMacintosh OS UnixUnix LinuxLinux Drivers Software is comprised of instructions that get a computer to perform a task.
  • Slide 6
  • CSCI N201: Programming Concepts Copyright 2004 Department of Computer & Information Science Programming Languages Programming languages allow programmers to code software.Programming languages allow programmers to code software. The three major families of languages are:The three major families of languages are: Machine languages Assembly languages High-Level languages
  • Slide 7
  • CSCI N201: Programming Concepts Copyright 2004 Department of Computer & Information Science Machine Languages Comprised of 1s and 0sComprised of 1s and 0s The native language of a computerThe native language of a computer Difficult to program one misplaced 1 or 0 will cause the program to fail.Difficult to program one misplaced 1 or 0 will cause the program to fail. Example of code: 1110100010101 111010101110 10111010110100 10100011110111Example of code: 1110100010101 111010101110 10111010110100 10100011110111
  • Slide 8
  • CSCI N201: Programming Concepts Copyright 2004 Department of Computer & Information Science Assembly Languages Assembly languages are a step towards easier programming.Assembly languages are a step towards easier programming. Assembly languages are comprised of a set of elemental commands which are tied to a specific processor.Assembly languages are comprised of a set of elemental commands which are tied to a specific processor. Assembly language code needs to be translated to machine language before the computer processes it.Assembly language code needs to be translated to machine language before the computer processes it. Example: ADD 1001010, 1011010Example: ADD 1001010, 1011010
  • Slide 9
  • CSCI N201: Programming Concepts Copyright 2004 Department of Computer & Information Science High-Level Languages High-level languages represent a giant leap towards easier programming.High-level languages represent a giant leap towards easier programming. The syntax of HL languages is similar to English.The syntax of HL languages is similar to English. Historically, we divide HL languages into two groups:Historically, we divide HL languages into two groups: Procedural languages Object-Oriented languages (OOP)
  • Slide 10
  • CSCI N201: Programming Concepts Copyright 2004 Department of Computer & Information Science Procedural Languages Early high-level languages are typically called procedural languages.Early high-level languages are typically called procedural languages. Procedural languages are characterized by sequential sets of linear commands. The focus of such languages is on structure.Procedural languages are characterized by sequential sets of linear commands. The focus of such languages is on structure. Examples include C, COBOL, Fortran, LISP, Perl, HTML, VBScriptExamples include C, COBOL, Fortran, LISP, Perl, HTML, VBScript
  • Slide 11
  • CSCI N201: Programming Concepts Copyright 2004 Department of Computer & Information Science Object-Oriented Languages Most object-oriented languages are high- level languages.Most object-oriented languages are high- level languages. The focus of OOP languages is not on structure, but on modeling data.The focus of OOP languages is not on structure, but on modeling data. Programmers code using blueprints of data models called classes.Programmers code using blueprints of data models called classes. Examples of OOP languages include C++, Visual Basic.NET and Java.Examples of OOP languages include C++, Visual Basic.NET and Java.
  • Slide 12
  • CSCI N201: Programming Concepts Copyright 2004 Department of Computer & Information Science Compiling Regardless of the HL Language, all HL programs need to be translated to machine code so that a computer can process the program.Regardless of the HL Language, all HL programs need to be translated to machine code so that a computer can process the program. Some programs are translated using a compiler. When programs are compiled, they are translated all at once. Compiled programs typically execute more quickly than interpreted programs, but have a slower translation speed.Some programs are translated using a compiler. When programs are compiled, they are translated all at once. Compiled programs typically execute more quickly than interpreted programs, but have a slower translation speed.
  • Slide 13
  • CSCI N201: Programming Concepts Copyright 2004 Department of Computer & Information Science Interpreting Some programs are translated using an interpreter. Such programs are translated line-by-line instead of all at once (like compiled programs). Interpreted programs generally translate quicker than compiled programs, but have a slower execution speed.Some programs are translated using an interpreter. Such programs are translated line-by-line instead of all at once (like compiled programs). Interpreted programs generally translate quicker than compiled programs, but have a slower execution speed.
  • Slide 14
  • CSCI N201: Programming Concepts Copyright 2004 Department of Computer & Information Science Programming Example Simple programming problem: Convert a price from British pounds into Dollars.Simple programming problem: Convert a price from British pounds into Dollars. PseudocodePseudocode Input the price of the item, PoundPrice, in pounds Compute the price of the item in dollars: Set DollarPrice = 1.62 * PoundPrice Write DollarPrice
  • Slide 15
  • CSCI N201: Programming Concepts Copyright 2004 Department of Computer & Information Science Programming Example Translating to Basic:Translating to Basic: INPUT PoundPrice LET DollarPrice = 1.62 * PoundPrice PRINT DollarPrice END
  • Slide 16
  • CSCI N201: Programming Concepts Copyright 2004 Department of Computer & Information Science Input & Variables Input operations get data into the programsInput operations get data into the programs A user is prompted to enter data:A user is prompted to enter data: Write Enter the price in pounds Input PoundPrice Computer programs store data in named sections of memory called variables. In the example above, the variable is named PoundPrice. The value of a variable can, and often does, change throughout a program.Computer programs store data in named sections of memory called variables. In the example above, the variable is named PoundPrice. The value of a variable can, and often does, change throughout a program.
  • Slide 17
  • CSCI N201: Programming Concepts Copyright 2004 Department of Computer & Information Science Types of Data Numeric DataNumeric Data Integer data, I.e., whole numbers, 10 25 -45 0 Floating point data have a decimal point 23.0, -5.0 Character data (alphanumeric)Character data (alphanumeric) All the characters you can type at the keyboard Letters & numbers not used in calculations Boolean dataBoolean data TRUE/FALSE
  • Slide 18
  • CSCI N201: Programming Concepts Copyright 2004 Department of Computer & Information Science Data Processing and Output Set DollarPrice = 1.62 * PoundPrice The above statement is a processing statement. Take the value in the variable PoundPrice, multiply by 1.62, and set the variable DollarPrice to the result of the multiplication.The above statement is a processing statement. Take the value in the variable PoundPrice, multiply by 1.62, and set the variable DollarPrice to the result of the multiplication. Write DollarPrice Output the value in DollarPrice to the monitor.Output the value in DollarPrice to the monitor.
  • Slide 19
  • CSCI N201: Programming Concepts Copyright 2004 Department of Computer & Information Science Assignment Operations Set counter = counter + 1 Assignment statements change the value in a variable Take the value of counter, add 1, and store the result back in the same variable.Assignment statements change the value in a variable Take the value of counter, add 1, and store the result back in the same variable.
  • Slide 20
  • CSCI N201: Programming Concepts Copyright 2004 Department of Computer & Information Science Arithmetic Operations NameSymbolExampleResult Exponentiation^4^216 Multiplication*16*232 Division/16/28 Addition+16+218 Subtraction-16-214
  • Slide 21
  • CSCI N201: Programming Concepts Copyright 2004 Department of Computer & Information Science Data Hierarchy 1.Parenthesis 2.Exponentiation 3.Multiplication/Division 4.Addition/Subtraction
  • Slide 22
  • CSCI N201: Programming Concepts Copyright 2004 Department of Computer & Information Science Hierarchy of Operations Example 3 * (6 + 2) / 12 (7 5) ^ 2 * 3 ( ) first = 3 * 8 / 12 2 ^ 2 * 3^ next = 3 * 8 / 12 4 * 3Mult/Div (L to R) = 24 / 12 4 * 3Mult/Div (L to R) = 2 12Add/Subtr = -10
  • Slide 23
  • CSCI N201: Programming Concepts Copyright 2004 Department of Computer & Information Science Data Output Send information from the program to the screen, or printer, or disk file.Send information from the program to the screen, or printer, or disk file. Write DollarPrice The computer displays the value of the variable DollarPrice to the screen and the cursor goes to the next line.The computer displays the value of the variable DollarPrice to the screen and the cursor goes to the next line.
  • Slide 24
  • CSCI N201: Programming Concepts Copyright 2004 Department of Computer & Information Science Data Output Write The price in Dollars is, DollarPrice The output looks like this:The output looks like this: The price in Dollars is 162 The text inside the is output to the user as is, and it is the value in the variable that is output.The text inside the is output to the user as is, and it is the value in the variable that is output.
  • Slide 25
  • CSCI N201: Programming Concepts Copyright 2004 Department of Computer & Information Science 2.1The Program Development Cycle
  • Slide 26
  • CSCI N201: Programming Concepts Copyright 2004 Department of Computer & Information Science Programming as Problem Solving Problem solving principles:Problem solving principles: 1.Completely understand the problem 2.Devise a plan to solve it 3.Carry out the plan 4.Review the results Developing a Program:Developing a Program: 1.Analyze the problem 2.Design the program 3.Code the program 4.Test the program An example of programming as problem solving, Brewsters Thousands follows
  • Slide 27
  • CSCI N201: Programming Concepts Copyright 2004 Department of Computer & Information Science 1) Analyze the Problem Brewsters ThousandsBrewsters Thousands The problem: Brewster wants to invest money at a local bank. There are many options such as interest rates, terms of deposit, compounding frequencies. He needs a program to compute, for any given initial investment, the final maturity (value) of the deposit. What are the inputs? (given data)What are the inputs? (given data) What are the outputs? (required data)What are the outputs? (required data) How will we calculate the required outputs from the given inputs?How will we calculate the required outputs from the given inputs?
  • Slide 28
  • CSCI N201: Programming Concepts Copyright 2004 Department of Computer & Information Science 2) Design the Program Create an outline of the programCreate an outline of the program An algorithm a step by step procedure that will provide the required results from the given inputs.An algorithm a step by step procedure that will provide the required results from the given inputs. Algorithm Examples: Instructions on how to make a cake, use the banks ATM, etc.Algorithm Examples: Instructions on how to make a cake, use the banks ATM, etc.
  • Slide 29
  • CSCI N201: Programming Concepts Copyright 2004 Department of Computer & Information Science 3) Code the Program Once the design is completed, write the program code.Once the design is completed, write the program code. Code is written in some programming language such as BASIC, Pascal, C++, Java, etc. In this course we write code in pseudo- code, developing the skills to be used when studying the specific languages.Code is written in some programming language such as BASIC, Pascal, C++, Java, etc. In this course we write code in pseudo- code, developing the skills to be used when studying the specific languages.
  • Slide 30
  • CSCI N201: Programming Concepts Copyright 2004 Department of Computer & Information Science 4) Testing the program Locate any errors (bugs)Locate any errors (bugs) Testing is done throughout the development cycleTesting is done throughout the development cycle Desk-checking, or code walkthrough is performed to locate errors in the code.Desk-checking, or code walkthrough is performed to locate errors in the code. Pretend you are the computer and execute your own code. Ultimate test is to run the program to see if the o...

Recommended

View more >