Program State and Program Execution CSE 1310 – Introduction to Computers and Programming 1.

Slides:



Advertisements
Similar presentations
Lecture 14 User-defined functions Function: concept, syntax, and examples © 2007 Daniel Valentine. All rights reserved. Published by Elsevier.
Advertisements

Chapter 8 Improving the User Interface
Advanced Database Projects In Access © Hodder Education 2008 Access Projects – Problem Specification.
Enter question text... 1.Enter answer text.... Enter question text... 1.Enter answer text...
Solving Problems with Repetition. Objectives At the end of this topic, students should be able to: Correctly use a while statement in a C# program Correctly.
Chapter 2: Problem Solving
Repetition Control Structures
Enter question text... 1.Enter answer text.... Enter question text... 1.Enter answer text...
Python Programming: An Introduction to Computer Science
Vahé Karamian Python Programming CS-110 CHAPTER 2 Writing Simple Programs.
Chapter 2 Writing Simple Programs
Python. What is Python? A programming language we can use to communicate with the computer and solve problems We give the computer instructions that it.
Software Engineering 1 (Chap. 1) Object-Centered Design.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Java Programs COMP 102 #3.
Introduction to Systems Analysis and Design Trisha Cummings.
Introduction CSE 1310 – Introduction to Computers and Programming
19/5/2015CS150 Introduction to Computer Science 1 Announcements  1st Assignment due next Monday, Sep 15, 2003  1st Exam next Friday, Sep 19, 2003  1st.
THE PROCESS OF WRITING SOFTWARE Python: System Engineering 1.
C Programming Lecture 3. The Three Stages of Compiling a Program b The preprocessor is invoked The source code is modified b The compiler itself is invoked.
Python Programming, 2/e1 Python Programming: An Introduction to Computer Science Chapter 2.
Introduction CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
A First Program CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington Credits: a significant part of.
Introduction to Algorithm Design and Documentation CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #002 (January 17, 2015)
CS 127 Writing Simple Programs.  Stages involved  Analyze the problem  Understand as much as possible what is trying to be solved  Determine Specifications.
PYTHON. Python is a high-level, interpreted, interactive and object- oriented scripting language. Python was designed to be highly readable which uses.
Introduction CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
Introduction to Computers and Java Chapter 1.3. A Sip of Java: Outline History of the Java Language Applets A First Java Program Compiling a Java Program.
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
Functions CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
Basics of Most C++ Programs // Programmer: Clayton Price date: 9/4/ // File: fahr2celc.cpp 03. // Purpose:
Overview of c++ Objectives 1. Understanding the use of the following elements in a c++ program variables constants assignment input output 2. Writing a.
Temperature conversions. C to F 1.Open excel 2. In cell "A1" type in "Celsius“ 3. In cell "B1" type in Fahrenheit 4. Since we are converting to celsius.
E-1 University of Washington Computer Programming I Lecture 5: Input and Output (I/O) © 2000 UW CSE.
CPSC 217 T03 Week VI Part #2: Midterm Review Session Hubert (Sathaporn) Hu.
2. WRITING SIMPLE PROGRAMS Rocky K. C. Chang September 10, 2015 (Adapted from John Zelle’s slides)
9/29/99B-1 CSE / ENGR 142 Programming I Variables, Values, and Types © 1998 UW CSE.
More on Functions Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Xiaojuan Cai Computational Thinking 1 Lecture 2 Simple Programs Xiaojuan Cai (蔡小娟) Fall, 2015.
INTRODUCTION TO PROGRAMMING. Program Development Life Cycle The program development life cycle is a model that describes the stages involved in a program.
Data Types and Conversions, Input from the Keyboard CS303E: Elements of Computers and Programming.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Java Programs COMP 102 #3.
H1-1 University of Washington Computer Programming I Lecture 9: Iteration © 2000 UW CSE.
Introduction CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
Variables, Types, Expressions Intro2CS – week 1b 1.
EGR 115 Introduction to Computing for Engineers Branching & Program Design – Part 3 Friday 03 Oct 2014 EGR 115 Introduction to Computing for Engineers.
Data Types and Conversions, Input from the Keyboard If you can't write it down in English, you can't code it. -- Peter Halpern If you lie to the computer,
Exercise 1 #include int main() { printf(“Hello C Programming!\n”); return 0; } 1.Run your Visual Studio 2008 or Create a new “project” and add.
Temperature. Temperature is measured using a thermometer. In the United States, we measure temperature in degrees Fahrenheit.
Introduction to Computing Concepts Note Set 14. What if… You had to print “I love Java” to the screen 125 times. How? 125 lines of ▫ System.out.println(“I.
© Peter Andreae Java Programs COMP 102 # T1 Peter Andreae Computer Science Victoria University of Wellington.
6. FUNCTIONS Rocky K. C. Chang October 4, 2015 (Adapted from John Zelle’s slides)
Solving Problems with Repetition Version 1.0. Objectives At the end of this topic, students should be able to: Correctly use a while statement in a C#
Python Programming, 2/e1 Python Programming: An Introduction to Computer Science Chapter 2.
COMPUTER PROGRAMMING Year 9 – lesson 1. Objective and Outcome Teaching Objective We are going to look at how to construct a computer program. We will.
More on Functions Intro to Computer Science CS1510 Dr. Sarah Diesburg.
2.5 Edit, Compile, and Execute Figure 2-3 illustrates the edit, compile and execute steps. Java bytecode.
AS Level Computing 8 CHAPTER: Fundamentals of structured programming The basics of good programming Algorithms System Flow Charts Symbol Conventions Steps.
Chapter 2 Writing Simple Programs
Python: Experiencing IDLE, writing simple programs
Data Types and Conversions, Input from the Keyboard
Functions CIS 40 – Introduction to Programming in Python
To write a Python program, you first need to open Pyscripter
ALGORITHMS & FLOWCHARTING II
Learning to Program in Python
CS 1111 Introduction to Programming Fall 2018
Chopin’s Nocturne.
Introduction to Python
Python Conditionals: The if statement
Module 3 Selection Structures 12/7/2019 CSE 1321 Module 3.
Presentation transcript:

Program State and Program Execution CSE 1310 – Introduction to Computers and Programming 1

Understanding a Line of Code To understand a line of the code, you must be able to answer the following three questions: – which variables does this line affect, and how? does it create any new variables? does it change the value of any existing variables? – what line of code will be executed NEXT? we have not seen examples yet, but in many cases the next line to be executed will NOT be simply be the next line in the text file. – what side effects does this line cause? printing to the screen (later) creating and modifying files (in future courses) playing audio/video, sending data to a network… 2

Determining the Effects of a Line What will this line do? celsius = (fahrenheit - 32) * 5/9 3

Determining the Effects of a Line What will this line do? celsius = (fahrenheit - 32) * 5/9 Clearly, it will change the value of the celsius variable. But, what will be the new value? 4

Determining the Effects of a Line What will this line do? celsius = (fahrenheit - 32) * 5/9 Clearly, it will change the value of the celsius variable. But, what will be the new value? We do not have enough information to determine that. To know EXACTLY the effects of a line, we need to know the program state. 5

Defining a Program State To figure out what a line of code does, we need to be able to answer these questions: – how the line will affect variables. – what the next line will be. – what side effects will be produced. At this early stage in the course, the state of the program consists of two things: – which line are we executing right now? – what variables exist right now, and what are the values of those variables? 6

Example of Tracing Program Execution 7 Line 1: fahrenheit_string = input("Enter the temperature in Fahrenheit: ") Line 2: fahrenheit = float(fahrenheit_string) Line 3: celsius = (fahrenheit - 32) * 5/9 Line 4: print("The temperature in celsius is", celsius) CURRENT PROGRAM STATE

Example of Tracing Program Execution 8 Line 1: fahrenheit_string = input("Enter the temperature in Fahrenheit: ") Line 2: fahrenheit = float(fahrenheit_string) Line 3: celsius = (fahrenheit - 32) * 5/9 Line 4: print("The temperature in celsius is", celsius) TABLE OF VARIABLES current line: 1 CURRENT PROGRAM STATE What does this line do?

Example of Tracing Program Execution 9 Line 1: fahrenheit_string = input("Enter the temperature in Fahrenheit: ") Line 2: fahrenheit = float(fahrenheit_string) Line 3: celsius = (fahrenheit - 32) * 5/9 Line 4: print("The temperature in celsius is", celsius) TABLE OF VARIABLES current line: 1 CURRENT PROGRAM STATE What does this line do? Since this line receives user input, we need to make up some value for this input. So, let's assume that the user enters "59".

Example of Tracing Program Execution 10 Line 1: fahrenheit_string = input("Enter the temperature in Fahrenheit: ") Line 2: fahrenheit = float(fahrenheit_string) Line 3: celsius = (fahrenheit - 32) * 5/9 Line 4: print("The temperature in celsius is", celsius) TABLE OF VARIABLES current line: 1 CURRENT PROGRAM STATE SIDE EFFECT: prints "Enter the temperature in Fahrenheit:" TABLE OF VARIABLES fahrenheit_string = '59' current line: 2 NEXT PROGRAM STATE

Example of Tracing Program Execution 11 Line 1: fahrenheit_string = input("Enter the temperature in Fahrenheit: ") Line 2: fahrenheit = float(fahrenheit_string) Line 3: celsius = (fahrenheit - 32) * 5/9 Line 4: print("The temperature in celsius is", celsius) TABLE OF VARIABLES fahrenheit_string = '59' current line: 2 CURRENT PROGRAM STATE What does this line do?

Example of Tracing Program Execution 12 Line 1: fahrenheit_string = input("Enter the temperature in Fahrenheit: ") Line 2: fahrenheit = float(fahrenheit_string) Line 3: celsius = (fahrenheit - 32) * 5/9 Line 4: print("The temperature in celsius is", celsius) TABLE OF VARIABLES fahrenheit_string = '59' current line: 2 CURRENT PROGRAM STATE TABLE OF VARIABLES fahrenheit_string = '59' fahrenheit = 59 current line: 3 NEXT PROGRAM STATE

Example of Tracing Program Execution 13 Line 1: fahrenheit_string = input("Enter the temperature in Fahrenheit: ") Line 2: fahrenheit = float(fahrenheit_string) Line 3: celsius = (fahrenheit - 32) * 5/9 Line 4: print("The temperature in celsius is", celsius) TABLE OF VARIABLES fahrenheit_string = '59' fahrenheit = 59 current line: 3 CURRENT PROGRAM STATE What does this line do?

Example of Tracing Program Execution 14 Line 1: fahrenheit_string = input("Enter the temperature in Fahrenheit: ") Line 2: fahrenheit = float(fahrenheit_string) Line 3: celsius = (fahrenheit - 32) * 5/9 Line 4: print("The temperature in celsius is", celsius) TABLE OF VARIABLES fahrenheit_string = '59' fahrenheit = 59 current line: 3 CURRENT PROGRAM STATE TABLE OF VARIABLES fahrenheit_string = '59' fahrenheit = 59 celsius = 15 current line: 4 NEXT PROGRAM STATE

Example of Tracing Program Execution 15 Line 1: fahrenheit_string = input("Enter the temperature in Fahrenheit: ") Line 2: fahrenheit = float(fahrenheit_string) Line 3: celsius = (fahrenheit - 32) * 5/9 Line 4: print("The temperature in celsius is", celsius) TABLE OF VARIABLES fahrenheit_string = '59' fahrenheit = 59 celsius = 15 current line: 4 CURRENT PROGRAM STATE What does this line do?

Example of Tracing Program Execution 16 Line 1: fahrenheit_string = input("Enter the temperature in Fahrenheit: ") Line 2: fahrenheit = float(fahrenheit_string) Line 3: celsius = (fahrenheit - 32) * 5/9 Line 4: print("The temperature in celsius is", celsius) TABLE OF VARIABLES fahrenheit_string = '59' fahrenheit = 59 celsius = 15 current line: 4 CURRENT PROGRAM STATE SIDE EFFECT: prints "The temperature in celsius is 15.0" TABLE OF VARIABLES fahrenheit_string = '59' fahrenheit = 59 celsius = 15 current line: end of program NEXT PROGRAM STATE

Understanding a Line of Code Understanding a line of code means that, given the current program state, you can describe: – how the line will change the program state. – what side effects the line will produce. 17

Understanding a Program Understanding a program means that you understand how every single line of the program affects the program state. Conversely, if you do not understand precisely how a specific line changes program state, you do not understand the program. 18

Understanding a Program Understanding a program means that you understand how every single line of the program affects the program state. Conversely, if you do not understand precisely how a specific line changes program state, you do not understand the program. If this ever happens, it is a sign that you are falling behind, and need to catch up. 19