Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 4: Enhancing Your Program.

Slides:



Advertisements
Similar presentations
Topics Introduction Types of Errors Exceptions Exception Handling
Advertisements

Chapter 3: Editing and Debugging SAS Programs. Some useful tips of using Program Editor Add line number: In the Command Box, type num, enter. Save SAS.
Introduction to C Programming
CS 6301 Lecture 2: First Program1. CS Topics of this lecture Introduce first program  Explore inputs and outputs of a program Arithmetic using.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
Debugging Introduction to Computing Science and Programming I.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 2: Your First Program.
Finding and Debugging Errors
Java Review 2 – Errors, Exceptions, Debugging Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Moving To Code 3 More on the Problem-Solving Process §The final step in the problem-solving process is to evaluate and modify (if necessary) the program.
Chapter 1: Introduction To Computer | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 | Last Updated: July 2005 Slide 1 Introduction To Computers.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Java Programs COMP 102 #3.
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering.
Variables in Java Part 2. ICS-3M1 - Mr. Martens - Variables Part 2 Recall the “int” Data Types When you divide one integer by another – you always get.
© Janice Regan, CMPT 128, Jan CMPT 128 Introduction to Computing Science for Engineering Students Creating a program.
CHAPTER:14 Programming Methodology Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
UNIT 3 TEMPLATE AND EXCEPTION HANDLING. Introduction  Program errors are also referred to as program bugs.  A C program may have one or more of four.
Programming Translators.
General Programming Introduction to Computing Science and Programming I.
Lecture 2 Fundamental Data Types. Variable Declaration.
ITP © Ron Poet Lecture 3 1 Comments. ITP © Ron Poet Lecture 3 2 Legibility  It is important that programs are easy to read.  It is easier to find bugs.
Input, Output, and Processing
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
Jaeki Song ISQS6337 Lecture 01 Introduction. Jaeki Song ISQS6337 Instructor Name: Jaeki Song Office: BA 712 Office Hours Tuesday & Thursday 2:00-3:20.
1 C++ Programming Basics Chapter 2 Lecture CSIS 10A.
Arithmetic Operations. Review function statement input/output comment #include data type variable identifier constant declaration.
Chapter 3 Assignment, Formatting, and Interactive Input C++ for Engineers and Scientists Third Edition.
Beginning C++ Through Game Programming, Second Edition
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Java Programming: From Problem Analysis to Program Design, 5e Chapter 2 Basic Elements of Java.
FIRST JAVA PROGRAM. JAVA PROGRAMS Every program may consist of 1 or more classes. Syntax of a class: Each class can contain 1 or more methods. public.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
6/3/2016 CSI Chapter 02 1 Introduction of Flow of Control There are times when you need to vary the way your program executes based on given input.
Chapter 2 Overview of C++. 2 Overview  2.1 Language Elements  2.2 Reserved Words & Identifiers  2.3 Data Types & Declarations  2.4 Input/Output 
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
A FIRST BOOK OF C++ CHAPTER 3 ASSIGNMENT AND INTERACTIVE INPUT.
Chapter 3: Assignment, Formatting, and Interactive Input.
The Software Development Process
Introduction to Visual Basic Programming. Introduction Simple Program: Printing a Line of Text Another Simple Program: Adding Integers Memory Concepts.
1 CS161 Introduction to Computer Science Topic #9.
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
PROGRAMMING GUIDELINES. SYLISTIC GUIDELINES  Meaningful names for identifiers Identifiers identify different parts of C++ programs. Identifiers should.
Program Development C# Programming January 30, 2007 Professor J. Sciame.
School of Computer Science & Information Technology G6DICP - Lecture 6 Errors, bugs and debugging.
TCU CoSc Introduction to Programming (with Java) Java Language Overview.
EGR 115 Introduction to Computing for Engineers MATLAB Basics 6: Debugging in MATLAB Monday 15 Sept 2014 EGR 115 Introduction to Computing for Engineers.
1 Homework Done the reading? –K&R –Glass Chapters 1 and 2 Applied for cs240? (If not, keep at it!) Gotten a UNIX account? (If not, keep at it!)
PROGRAM ESSENTIALS. TOKENS  SMALLEST UNITS OF A PROGRAM LANGUAGE  Special Symbols  Mathematical Operators  Punctuation  Word Symbols  Key Words.
Chapter 3 Assignment, Formatting, and Interactive Input C++ for Engineers and Scientists Third Edition.
Error Handling Tonga Institute of Higher Education.
Programming & Debugging. Key Programming Issues Modularity Modifiability Ease of Use Fail-safe programming Style Debugging.
Controlling Program Flow with Decision Structures.
Exception Handling How to handle the runtime errors.
1 1 Chapter 2 Elementary Programming. 2 2 Motivations In the preceding chapter, you learned how to create, compile, and run a Java program. Starting from.
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
Slide 1 Chapter 3 Variables  A variable is a name for a value stored in memory.  Variables are used in programs so that values can be represented with.
© 2006 Lawrenceville Press Slide 1 Chapter 4 Variables  A variable is a name for a value stored in memory.  Variables are created using a declaration.
Slide 1 Chapter 3 Variables  A variable is a name for a value stored in memory.  Variables are created using a declaration statement. For example: Dim.
Debuggers. Errors in Computer Code Errors in computer programs are commonly known as bugs. Three types of errors in computer programs –Syntax errors –Runtime.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
Last week: We talked about: History of C Compiler for C programming
Completing the Problem-Solving Process
PROGRAMMING METHODOLOGY
Homework Applied for cs240? (If not, keep at it!) 8/10 Done with HW1?
Core Objects, Variables, Input, and Output
Software Development Process
PROGRAMMING FUNDAMENTALS Lecture # 03. Programming Language A Programming language used to write computer programs. Its mean of communication between.
Functions, Part 2 of 42 Topics Functions That Return a Value
CHAPTER 6 Testing and Debugging.
Presentation transcript:

Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 4: Enhancing Your Program

Today We Are Going To: Demonstrate the use of constants Demonstrate the use of constants Discuss the importance of programming style for preventing and resolving errors Discuss the importance of programming style for preventing and resolving errors Work with integer arithmetic Work with integer arithmetic Introduce the concept of type casting Introduce the concept of type casting

Topic Constants

Constants Used these last time Used these last time Values that do not change Values that do not change Giving symbolic names makes program easier to write, to change, and to understand Giving symbolic names makes program easier to write, to change, and to understand Declaration: ordinary variable with addition of the keyword const Declaration: ordinary variable with addition of the keyword const

Topic Errors and Debugging

Syntax Errors These are the easiest errors to find and fix; compiler finds them and gives a hint These are the easiest errors to find and fix; compiler finds them and gives a hint Often one mistake produces several errors - “cascading” errors - so fix first ones first Often one mistake produces several errors - “cascading” errors - so fix first ones first Error message will help, but you should also know yourself, know what mistakes you have a tendency to make Error message will help, but you should also know yourself, know what mistakes you have a tendency to make

Runtime Errors Cause abnormal termination of program Cause abnormal termination of program The runtime environment will give some information about the exception The runtime environment will give some information about the exception Harder to track down because the place where the error shows up is not always the same as the place that caused it Harder to track down because the place where the error shows up is not always the same as the place that caused it

Logic Errors Program runs normally but gives the wrong result Program runs normally but gives the wrong result These are very hard to find; you must know the calculation you are trying to perform very well These are very hard to find; you must know the calculation you are trying to perform very well

Error Prevention Follow good programming practices Follow good programming practices Use naming conventions Use naming conventions Indent properly Indent properly Comment clearly (esp. for logic errors) Comment clearly (esp. for logic errors) Write code in small steps, test each one Write code in small steps, test each one Use the compiler often (Recall: Why does C++ make use of a compiler?) Use the compiler often (Recall: Why does C++ make use of a compiler?)

Error Detection Compiler errors are easy to detect: the compiler tells you about them Compiler errors are easy to detect: the compiler tells you about them Run-time errors and logic errors require that the program be tested Run-time errors and logic errors require that the program be tested Develop a broad set of test cases Develop a broad set of test cases Make sure to include potential special cases Make sure to include potential special cases

Error Correction Most code-generation applications include a debugging tool Most code-generation applications include a debugging tool Use this to stop execution at a place that is suspicious Use this to stop execution at a place that is suspicious Once stopped you can step through the instructions one at a time Once stopped you can step through the instructions one at a time Displays variables and other information to help identify the source of the problem Displays variables and other information to help identify the source of the problem

Topic Working From the Command Line

DOS Prompts Find a DOS prompt: Start/Accessories Find a DOS prompt: Start/Accessories Navigate to the location of your executable Navigate to the location of your executable Execute it by invoking it as a command Execute it by invoking it as a command Watch installation of Borland compiler Watch installation of Borland compiler

Topic Integer Arithmetic and An Introduction to Type Casting

Project 2.2 Open your book Open your book Read Project 2.2 Read Project 2.2 Discuss the program’s requirements Discuss the program’s requirements Analyze input and output Analyze input and output Design a solution Design a solution

Quotient Calculation Notice the way the quotient is truncated Notice the way the quotient is truncated Integer division must produce an integer result; the fractional part is LOST Integer division must produce an integer result; the fractional part is LOST Recall: division and modulus operators for integer data Recall: division and modulus operators for integer data

Type Casting In order to overcome this problem we must tell the compiler NOT to do integer division In order to overcome this problem we must tell the compiler NOT to do integer division Do this by specifying that it should treat the arguments as type float Do this by specifying that it should treat the arguments as type float This is called “type casting” This is called “type casting”