1 / 9

Administrative HW 3 due Friday, Jan 31 st @ 9pm 2 parts, each part is worth 100 points

CS 109 C/C++ Programming for Engineers with MATLAB. Administrative HW 3 due Friday, Jan 31 st @ 9pm 2 parts, each part is worth 100 points Lab sections are meeting, attendance mandatory Thursday : 8am and 9am, 2249 SELE Thursday: 10am and 11am, 2263 SELE (Mac lab)

susane
Download Presentation

Administrative HW 3 due Friday, Jan 31 st @ 9pm 2 parts, each part is worth 100 points

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS 109 C/C++ Programming for Engineers with MATLAB • Administrative • HW 3 due Friday, Jan 31st @ 9pm • 2 parts, each part is worth 100 points • Lab sections are meeting, attendance mandatory • Thursday: 8am and 9am, 2249 SELE • Thursday: 10am and 11am, 2263 SELE (Mac lab) • Friday: 8am, 9am and 10am, 2249 *F* SELE • Topics for today: • Finish up with selection • Computers are finite machines— implications? CS 109 -- 29 Jan 2014

  2. The many forms of selection… • if-then-else: • if-then: • single-stmt: if (condition) { then-part } else { else-part } if (condition) { then-part } if (condition) single-stmt; else single-stmt; if (condition) single-stmt; exception #2: { } are optional if they contain only 1 statement exception #1: else-part is optional, if condition is false ==> do nothing CS 109 -- 29 Jan 2014

  3. Common uses… nested or "chained" independent . . . if (...) { } else { if (...) { } else { } } . . . . . . if (...) { } if (...) { } if (...) { } . . . CS 109 -- 29 Jan 2014

  4. Computers are finite machines… • So? CS 109 -- 29 Jan 2014

  5. Computers are finite! • RAM (memory) is fixed size • Hard disks are fixed size • Numbers have fixed size • integers are 32 or 64 bits in size • real numbers are 64 or 128 bits in size • the "size" of your computer — 32-bit or64-bit — refers to max memory size andtypical integer size 00001101010101010101010101110001 32 bits ("binary digits") Finite machines have limits… CS 109 -- 29 Jan 2014

  6. Integer number line on a computer: • for 32-bit integers (int): • for 64-bit integers (long long) -231 0 231 - 1 -263 0 263 - 1 CS 109 -- 29 Jan 2014

  7. Implication: • What happens when you exceed endpoints? • For example, what if we add 1 to the maximum integer? #include <iostream> #include <climits> using namespace std; intmain() { inti; i = INT_MAX; cout << i << endl; i = i + 1; cout << i << endl; return 0; } output? output? CS 109 -- 29 Jan 2014

  8. Real numbers on a computer: • Consider the real number line from just 0.0 to 1.0… How many real numbers are there? 0.0 1.0 CS 109 -- 29 Jan 2014

  9. Implication? • No way to represent them all ― some must be approximated… double x, y, z; x = 0.9; y = 0.1; z = 1.0 - x - y; cout << z << endl; double x, y, z; x = 0.8; y = 0.2; z = 1.0 - x - y; cout << z << endl; output? output? CS 109 -- 29 Jan 2014

More Related