David Stotts Computer Science Department UNC Chapel Hill.

Slides:



Advertisements
Similar presentations
Why not just use Arrays? Java ArrayLists.
Advertisements

Chapter 5 Errors Bjarne Stroustrup
Introduction to C Programming
CATHERINE AND ANNIE Python: Part 3. Intro to Loops Do you remember in Alice when you could use a loop to make a character perform an action multiple times?
Prompts to Support the Use of Strategies To support the control of early reading behaviors: – Read it with your finger. – Did you have enough (or too many)
Introduction to Programming using Matlab Session 2 P DuffourJan 2008.
CS 206 Introduction to Computer Science II 01 / 20 / 2009 Instructor: Michael Eckmann.
David Stotts Computer Science Department UNC Chapel Hill.
Exception Handling Chapter 12.  Errors- the various bugs, blunders, typos and other problems that stop a program from running successfully  Natural.
Introduction to Computing Science and Programming I
CHAPTER 30 THE HTML 5 FORMS PROCESSING. LEARNING OBJECTIVES What the three form elements are How to use the HTML 5 tag to specify a list of words’ form.
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
1 10/25/06CS150 Introduction to Computer Science 1 Reading from and Writing to Files.
100 Most Common Words.
11 Chapter 4 LOOPS AND FILES. 22 THE INCREMENT AND DECREMENT OPERATORS To increment a variable means to increase its value by one. To decrement a variable.
28/08/2015SJF L31 F21SF Software Engineering Foundations ASSUMPTIONS AND TESTING Monica Farrow EM G30 Material available on Vision.
More on Functions CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
Chapter 6 – Repetition Statements : Objectives After you have read and studied this chapter, you should be able to Implement repetition control in a program.
ICAPRG301A Week 4Buggy Programming ICAPRG301A Apply introductory programming techniques Program Bugs US Navy Admiral Grace Hopper is often credited with.
High-Frequency Sight Words (end of Grade 1)
1 Conditions Logical Expressions Selection Control Structures Chapter 5.
Testing and Debugging Version 1.0. All kinds of things can go wrong when you are developing a program. The compiler discovers syntax errors in your code.
David Stotts Computer Science Department UNC Chapel Hill.
David Stotts Computer Science Department UNC Chapel Hill.
Making Decisions uCode: October Review What are the differences between: o BlueJ o Java Computer objects represent some thing or idea in the real.
Chapter 3: Formatted Input/Output Copyright © 2008 W. W. Norton & Company. All rights reserved. 1 Chapter 3 Formatted Input/Output.
David Stotts Computer Science Department UNC Chapel Hill.
The Software Development Process
Verification & Validation. Batch processing In a batch processing system, documents such as sales orders are collected into batches of typically 50 documents.
REVIEW No curveballs this time …. PROBLEM TYPE #1: EVALUATIONS.
Exceptions Chapter 16 This chapter explains: What as exception is Why they are useful Java exception facilities.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Using variable Variables are used to store values.
Fall 2014 (both sections) Assignment #1 Feedback Elapsed time (How long): –Ranged from 45 minutes to 10 days –About 1/4 said less than 1 day –About 1/2.
Iteration. Iteration: Review  If you wanted to display all the numbers from 1 to 1000, you wouldn’t want to do this, would you? Start display 1 display.
CPSC 217 T03 Week V Part #1: Iteration Hubert (Sathaporn) Hu.
REVIEW No curveballs this time …. PROBLEM TYPE #1: EVALUATIONS.
1 The Software Development Process ► Systems analysis ► Systems design ► Implementation ► Testing ► Documentation ► Evaluation ► Maintenance.
Copyright 2006 Addison-Wesley Brief Version of Starting Out with C++ Chapter 5 Looping.
AVCE ICT – Unit 7 - Programming Session 12 - Debugging.
© 2015 albert-learning.com How to talk to your boss How to talk to your boss!!
Java I/O Basics MIS 3023 Business Programming Concepts II The University of Tulsa Professor: Akhilesh Bajaj All slides in this presentation ©Akhilesh Bajaj,
First Grade Sight Words see Getting Started the.
Announcements Assignment 2 Out Today Quiz today - so I need to shut up at 4:25 1.
Week91 APCS-A: Java Problem Solving November 2, 2005.
For Loop GCSE Computer Science – Python. For Loop The for loop iterates over the items in a sequence, which can be a string or a list (we will discuss.
Chapter 3: Formatted Input/Output 1 Chapter 3 Formatted Input/Output.
JavaScript: Conditionals contd.
Last week: We talked about: History of C Compiler for C programming
How to compose a message to a teacher
Data Types Variables are used in programs to store items of data e.g a name, a high score, an exam mark. The data stored in a variable is entered from.
CS 115 Lecture Flags.
Testing and Debugging.
Chapter 2 Assignment and Interactive Input
Understand the Programming Process
Little work is accurate
While loops The while loop executes the statement over and over as long as the boolean expression is true. The expression is evaluated first, so the statement.
Chapter 4 LOOPS © Bobby Hoggard, Department of Computer Science, East Carolina University / These slides may not be used or duplicated without permission.
Conditions and Ifs BIS1523 – Lecture 8.
Value returning Functions
CISC101 Reminders Assn 3 due tomorrow, 7pm.
Understand the Programming Process
Problem Solving Skill Area 305.1
Python programming exercise
Software Development Process
Chapter 7: Input Validation
Data Types and Maths Programming Guides.
Imagine It! High Frequency Word Practice
CSCE 206 Lab Structured Programming in C
CISC101 Reminders Assignment 3 due today.
Presentation transcript:

David Stotts Computer Science Department UNC Chapel Hill

My Mom said, “Dear, please go to the store and get a bottle of milk. If they have eggs, bring a dozen.” I came home and put her 12 bottles of milk on the table. “What in the world …” She was truly confused. “Why did you bring 12 bottles of milk??” “Because… THEY HAD EGGS !” Programmers loose in the Real World

Use parentheses to be clear and unambiguous Also, watch rules in making boolean conditions if (x == 100 || 200) { … } wrong What happens here? Try it … if (x == 100 || x == 200) { … } correct Watch out for mistakes like this if (x = 100) { … } wrong assignment, but you meant “==“ equality if (x == 100) { … } correct

 Programs should be robust … meaning they should be written to survive mistakes as best they can  Robust means not delicate … we don’t want a program to just quit or crash due to problems we could have anticipated and perhaps repaired or remedied.  One area we will check is user input data Users can, and will, make mistakes  When asking for input, data from a user must be examined to make sure it matches the expected type, format and range

When asking for input, data from a user must be examined to make sure it matches the expected type, format and range var num = prompt (“give an int between 1 and 100”) ; What can go wrong? ◦ Type: user might give “five” or “what?” or just a blank (return key) ◦ Format: user might type “34.2” ◦ Range: user might type “105”, or “-12”

What can we do about it? Write conditionals after the prompt to check for the various possible problems If problems are detected, then we either  Alert the user to the error and quit gracefully  Alert the user to the problem and ask for new input (a loop)  Alert the user to the error, then make correct data out of the bad data and continue the program (and be sure to inform the user what you did)

Code examples This is a good use for functions, our next item in the big six