Presentation is loading. Please wait.

Presentation is loading. Please wait.

 Monday, 9/9/02, Slide #1 CS106 Introduction to CS1 Monday, 9/9/02  QUESTIONS?? (Exercises, Lab #1, etc.)  Today:  More on float objects  C++ concept:

Similar presentations


Presentation on theme: " Monday, 9/9/02, Slide #1 CS106 Introduction to CS1 Monday, 9/9/02  QUESTIONS?? (Exercises, Lab #1, etc.)  Today:  More on float objects  C++ concept:"— Presentation transcript:

1  Monday, 9/9/02, Slide #1 CS106 Introduction to CS1 Monday, 9/9/02  QUESTIONS?? (Exercises, Lab #1, etc.)  Today:  More on float objects  C++ concept: Assignment statement  Operators and Precedence  Using the VCPP Debugger  Reading: Rest of Chapter 1  Exercises: p. 24 #12-14  New files/handouts: DebugMe.cpp

2  Monday, 9/9/02, Slide #2 Some more about float objects  For now, all our program will use float objects  C++ also has int objects -- integers, or whole numbers.  What are the values of the C++ expressions:  10.0 / 4.0  10 / 4  Moral: To be sure a whole number constant is type float, use a decimal point

3  Monday, 9/9/02, Slide #3 A New C++ operator: assignment  To convert feet to meters, a program could use the statement: meters =.3048 * feet; where meters and feet are float objects.  The symbol = is the assignment operator:  First the expression on the right is evaluated;  Then the computed value is assigned to the object named on the left.

4  Monday, 9/9/02, Slide #4 Rules for using the assignment operator  Left side must be an object name  BAD: a + b = c;  Right side must be a valid expression whose type is compatible with left side (e.g., both numbers).  Any objects in right side must already have values (they’re “initialized”)  BAD: float x, y, z; x = y + z; //What’s x??

5  Monday, 9/9/02, Slide #5 Using multiple operators in one expression  We have seen the following operators so far:  >> ><<+-* /=  We can also use parentheses ( )  If an expression uses more than one operator, C++ uses rules of precedence to decide the order of calculation:  Ex: cout << 2 * 3 + 10 / 5; //What gets output?

6  Monday, 9/9/02, Slide #6 Basic rules of operator precedence  C++ rules of precedence generally correspond to standard rules from algebra. From highest to lowest:  Parenthesized expressions  “Multiplicative” operations: * /  “Additive” operations: + -  Insertion, extraction: >  Assignment: =  Generally operators with equal precedence are evaluated left-to-right: x = 12 / 3 * 4

7  Monday, 9/9/02, Slide #7 Using the VCPP Debugger, part 1  The VCPP Debugger is a tool which lets you trace the execution of a (compiled) program. Here are explanations of some of the buttons.  Run program up to cursor location  “Step over:” Execute line, don’t go inside function calls.  Stop debugging.  “Step into:” Execute line, do go inside function calls.  “Step out of: ”Execute rest of current function.  While it’s running the Debugger also displays two extra windows:  Variables Window: Shows values of current objects (variables)  Watch Window: Lets you type in objects or expressions that may not be displayed in the Variables Window.

8  Monday, 9/9/02, Slide #8 Using the VCPP Debugger, part 2  To start the debugger:  Your program must be compiled.  Select Build-Start Debug-Step Into to start at beginning of main()  Or, first position cursor where you want it, and select Build-Start Debug-Run To Cursor.  The Debug Toolbar should appear -- if not, right-click on a gray border and then left-click on ‘Debug.’  For now use either:  Step over -- to execute one line at a time  Run to cursor -- to execute entire segments  Look for  The console window -- showing the progress of program output  The watch and variable windows

9  Monday, 9/9/02, Slide #9 Example: DebugMe.cpp  Example based on program from text to convert feet to meters, with bugs added.  What are some good test data?  Which errors are syntax errors, semantic errors,run-time errors?


Download ppt " Monday, 9/9/02, Slide #1 CS106 Introduction to CS1 Monday, 9/9/02  QUESTIONS?? (Exercises, Lab #1, etc.)  Today:  More on float objects  C++ concept:"

Similar presentations


Ads by Google