What does a computer program look like: a general overview.

Slides:



Advertisements
Similar presentations
Intermediate Code Generation
Advertisements

IT253: Computer Organization Lecture 6: Assembly Language and MIPS: Programming Tonga Institute of Higher Education.
Introduction to Computing Concepts Note Set 7. Overview Variables Data Types Basic Arithmetic Expressions ▫ Arithmetic.
1 Chapter Six Algorithms. 2 Algorithms An algorithm is an abstract strategy for solving a problem and is often expressed in English A function is the.
Conditional statements and Boolean expressions. The if-statement in Java (1) The if-statement is a conditional statement The statement is executed only.
Computer Algorithms. Fact: computers are dumb machines Basic property of a computer (a machine): Computers do what we tell them to do Unfortunately, computer.
 2005 Pearson Education, Inc. All rights reserved Introduction.
The computer memory and the binary number system.
A Review. a review of lessons learned so far… ( 2 steps forward - 1 step back) Software Development Cycle: design, implement, test, debug, document Large.
Numeric literals and named constants. Numeric literals Numeric literal: Example: A numeric literal is a constant value that appears in a Java program.
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
10-Jun-15 Introduction to Primitives. 2 Overview Today we will discuss: The eight primitive types, especially int and double Declaring the types of variables.
COMP 14 Introduction to Programming Miguel A. Otaduy May 25, 2004.
Program Design and Development
Introduction to Computers and Programming Lecture 5 Boolean type; if statement Professor: Evan Korth New York University.
CS 201 Functions Debzani Deb.
COMP 14: Primitive Data and Objects May 24, 2000 Nick Vallidis.
Writing algorithms using the while-statement. Previously discussed Syntax of while-statement:
Programming a computer. What does programming a computer mean ? Programming a computer: Since a computer can only execute machine instructions (encoded.
Concept of Computer Programming November 2, 2011.
Week 2 - Friday.  What did we talk about last time?  Data representation  Binary numbers  Types  int  boolean  double  char  String.
The computer memory and the binary number system.
Floating point variables of different lengths. Trade-off: accuracy vs. memory space Recall that the computer can combine adjacent bytes in the RAM memory.
Simple Program Design Third Edition A Step-by-Step Approach
CIS Computer Programming Logic
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
The string data type String. String (in general) A string is a sequence of characters enclosed between the double quotes "..." Example: Each character.
The Java Programming Language
Input, Output, and Processing
CIS 260: App Dev I. 2 Programs and Programming n Program  A sequence of steps designed to accomplish a task n Program design  A detailed _____ for implementing.
The basics of the array data structure. Storing information Computer programs (and humans) cannot operate without information. Example: The array data.
Floating point numerical information. Previously discussed Recall that: A byte is a memory cell consisting of 8 switches and can store a binary number.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 5: Software Design & Testing; Revision Session.
5 BASIC CONCEPTS OF ANY PROGRAMMING LANGUAGE Let’s get started …
Problem Solving using the Science of Computing MSE 2400 EaLiCaRA Spring 2015 Dr. Tom Way.
Property of Jack Wilson, Cerritos College1 CIS Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College.
CIS 260: App Dev I. 2 Programs and Programming n Program  A sequence of steps designed to accomplish a task n Program design  A detailed _____ for implementing.
Introduction to programming in the Java programming language.
Assignment statements using the same variable in LHS and RHS.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
CMP-MX21: Lecture 4 Selections Steve Hordley. Overview 1. The if-else selection in JAVA 2. More useful JAVA operators 4. Other selection constructs in.
Chapter 7 Selection Dept of Computer Engineering Khon Kaen University.
© 2004 Pearson Addison-Wesley. All rights reserved ComS 207: Programming I Instructor: Alexander Stoytchev
VARIABLES, CONSTANTS, OPERATORS ANS EXPRESSION
Introduction to Methods. Previously discussed There are similarities in make up of that can help you remember the construct of a class a class in the.
The life time of local variables (in a method). Local variables Local variable: A local variable is used to store information that is relevant for the.
The while-statement. The loop statements in Java What is a loop-statement: A loop-statement is a statement that repeatedly executes statements contained.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
Reading input from the console input. Java's console input The console is the terminal window that is running the Java program I.e., that's the terminal.
1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
Boolean expressions, part 1: Compare operators. Compare operators Compare operators compare 2 numerical values and return a Boolean (logical) value A.
Simple algorithms on an array - compute sum and min.
Repetition Statements (Loops). 2 Introduction to Loops We all know that much of the work a computer does is repeated many times. When a program repeats.
Programming. In your own words, explain what an algorithm is, and give an example of how people use algorithms every day.
Introduction to Algorithmic Processes CMPSC 201C Fall 2000.
Chapter 1: Preliminaries Lecture # 2. Chapter 1: Preliminaries Reasons for Studying Concepts of Programming Languages Programming Domains Language Evaluation.
Review A program is… a set of instructions that tell a computer what to do. Programs can also be called… software. Hardware refers to… the physical components.
Click to edit Master title style Click to edit Master text styles –Second level Third level –Fourth level »Fifth level 1 Fundamentals of Programming Most.
CSE 110: Programming Language I Matin Saad Abdullah UB 1222.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Java Programming: Guided Learning with Early Objects Chapter 1 Basic Elements of Java.
ALGORITHMS CONDITIONAL BRANCH CONTROL STRUCTURE
CS 240 – Lecture 11 Pseudocode.
Chapter 1: Computer Systems
Building Java Programs
ICT Gaming Lesson 2.
Computer Algorithms.
Presentation transcript:

What does a computer program look like: a general overview

Computer programming: solving a problem with a computer Goal of computer programming: We write a computer program to solve a problem or perform a task

Computer programming: solving a problem with a computer (cont.) In order to solve a problem, we need: The basic fact of life is that without information, we cannot complete the task !!! An algorithm (detailed steps that solve the problem) Information !!!

Computer programming: solving a problem with a computer (cont.) Example: compute the sum of 2 numbers Without the value of the 2 numbers, we cannot perform the addition operation !!! Algorithm: perform an addition Information: the value of the 2 numbers

Computer program = an algorithm + (lots of) information A computer program consists of: computer instructions that tells a computer precisely what to do to accomplish the job (Lots of) information to guide the algorithm to do the job

Computer program = an algorithm + (lots of) information (cont.) This fact is expressed in the title of a classical Computer Science book:

Computer program = an algorithm + (lots of) information (cont.) The title of this classical Computer Science book reflects the fact that to solve a problem (write a program) with a computer, you need: An algorithm, and Information (that is stored in data structure)

Statements: expressing the steps in an algorithm Statements Statement = an instruction written in a (High level) Programming Language A statement tells a computer in very precise terms what exactly it must do

Statements: expressing the steps in an algorithm (cont.) Example of statements Store the value 26 in the memory cell named "A" Add the number A to the number B If the number A ≥ 0 then do this otherwise do that

Variable: storing the information Variables A variable = a identifiable memory cell stores information that is necessary to solve a problem A variable behaves like a piece of paper that is identified by a unique name where we can record (a small amount of) information Example:

Variable: storing the information (cont.) Data structure: Example A data structure = a collection of variables that store related information One variable stores the name of a person Another variable stores the phone number of a same person These 2 variables together would form a data structure

Data types There are different types of data: Numerical data, such as: age, salary, and so on. Textual data (or alpha-numerical data) such as books, news paper articles, webpages, and so on. Etc.

Data types (cont.) A programming language always provides a number of built-in data types to get your started Common built-in data types: The built-in data types are called primitive data types Single precision floating point numbers Double precision floating point numbers Integer numbers A character type A logical data type

Data types (cont.) In addition, a modern programming language allows the programmer to define his/her own data types These are called user-defined types.

Variable definition In modern programming languages, we must "define" every variable in the computer program Effect of a variable definition: Each variable definition must use a unique name to identify the variable. A variable definition will tell the computer to create the variable that will be identified by that (unique) name This is like telling the computer to: 1.get a new sheet of paper and 2.tag the new sheet of paper with the name of the variable

Starting point of the execution of a computer program Every computer program written in a high level programming language has a starting point of execution Each programming language has its own convention of where a program will start execution

Starting point of the execution of a computer program (cont.) Example starting point in some popular programming languages:

Execution of a computer program How a computer program is executed: The execution will start at the statement at the starting point of the execution (In Java, this will be the first statement in main()) After a statement is executed, the next statement executed depends on the flow of control

Execution of a computer program Flow of control: Normal flow of control is: There are control statements in a programming language that can change the normal flow of control After executing a statement, the next statement that will be executed is the statement following the last executed statement

A taste of "flow of control" (program execution): the Euler algorithm in Java Recall the Euclid Algorithm: We saw the execution of the Euclid algorithm using 2 pieces of paper: html#exec As long as one of the number is not zero (0) do { if ( number on A ≥ number on B ) replace the number on A by the value (A - B) otherwise replace the number on B by the value (B - A) } The Greatest Common Divisor (GCD) = B

A taste of "flow of control": the Euler algorithm in Java (cont.) We have also seen a Java program that implements the Euclid algorithm: public class Euclid { public static void main(String args[]) { int A; // Memory cell named "A" int B; // Memory cell named "B" // These memory cells are like the 2 pieces of paper // we used above. They can store and recall a value A = 28; // Write "28" on the piece of paper named "A" B = 36; // Write "36" on the piece of paper named "B" // ================================ // This is the Euclid Algorithm: // ================================ while ( A != 0 && B != 0 ) { if ( A >= B ) A = A - B; // Replace the number on A by (A-B) else B = B - A; // Replace the number on B by (B-A) } System.out.println("GCD = " + B); }

A taste of "flow of control": the Euler algorithm in Java (cont.) When the Java program is run on a computer, the computer will be doing pretty much the same thing as the execution on 2 pieces of paper that we saw here: alg.html#exec

A taste of "flow of control": the Euler algorithm in Java (cont.) I will illustrate how a computer executes the Euclid algorithm with a series of diagram: The program execution of a Java program starts at beginning of main(...)

A taste of "flow of control": the Euler algorithm in Java (cont.) Executing the line "int A;" tells the computer to create a new variable name A This is like getting a new sheet of paper and tag it with the name A Result: The flow of control goes to the next line

A taste of "flow of control": the Euler algorithm in Java (cont.) Executing the line "int B;" tells the computer to create a new variable name B This is like getting a new sheet of paper and tag it with the name B Result: The flow of control goes to the next line

A taste of "flow of control": the Euler algorithm in Java (cont.) Executing the line "A=28;" tells the computer to put the number 28 in the variable A This is like writing "28" on the sheet of paper tagged with the name A Result:

A taste of "flow of control": the Euler algorithm in Java (cont.) Executing the line "B=36;" tells the computer to put the number 36 in the variable B This is like writing "36" on the sheet of paper tagged with the name B Result:

A taste of "flow of control": the Euler algorithm in Java (cont.) Executing the line "while (A≠0 && B≠0)" tells the computer only continue inside the statements inside {...} if the condition is true. The symbol && means "and". Since 28 (A) ≠ 0 and 36 (B) ≠ 0, the condition is true and the execution continues inside {...} Result:

A taste of "flow of control": the Euler algorithm in Java (cont.) Executing the line "if (A≥B)" tells the computer to: continue inside the first {...} if the condition is true and continue inside the second {...} if the condition is false Since 28 (A) < 36 (B), the condition is false and the execution continues inside the second {...} (after the word else) Result:

A taste of "flow of control": the Euler algorithm in Java (cont.) Executing the line "B=B−A;" tells the computer to put the difference (36−28) in the variable B This is like writing the difference (36−28) on the sheet of paper tagged with the name B Result:

A taste of "flow of control": the Euler algorithm in Java (cont.) When the execution reaches the line "}", the flow of control will go back to up to the while line and execute the steps all over again !!! In other words:

A taste of "flow of control": the Euler algorithm in Java (cont.) The computer executing the Euclid algorithm written in the Java programming language is doing the exact same steps as what a human would do using 2 pieces of paper. A computer program is nothing more than a precise sequence of steps (that a human would use) to solve a problem that is expressed in a programming language Conclusion:

A programming language is a language It is important to realize that a programming language is like any of the human languages Important facts about programming languages: 1. A programming language has syntax rules that govern the correctness of the "sentences" 2.The compiler (translator) is extremely inflexible on the syntax rules: If the compiler finds any syntax error in a program, it will not compile (translate) the entire program

A programming language is a language (cont.) Important advice: (Don't worry, the syntax rules are very simple; still, you need to remember them well !) Remember the syntax rules of the programming language carefully