Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSC 107 – Programming For Science. Follow-Up From Last Lecture.

Similar presentations


Presentation on theme: "CSC 107 – Programming For Science. Follow-Up From Last Lecture."— Presentation transcript:

1 CSC 107 – Programming For Science

2 Follow-Up From Last Lecture

3 Announcements

4 George Boole  Mathematician from English middle-class  Lived from 1815 – 1864  Started work at age 16 as a teaching assistant  Held two assistantships to support family  Opened own school after many years of work  In 1847 wrote Mathematical Analysis of Logic

5 Mathematical Analysis of Logic  Boole’s book proposed new logical system  World began with 2 values– though more created  Devised rules to add, subtract, & multiply  Work ignored during Boole’s lifetime  System only had 2 values, so what was the point?  What is done with developer of pointless knowledge?  Basis for most technology in the modern age  All it took was a simple little discovery…

6 Gate  Combines input(s) to generate output signal  Like most electronics, uses “on-off” state  Input is "off", if line drops below 3.3 volts  From 3.3 - 5 volts, an input is considered on  Gate is deep fried silicon if line goes above 5 volts,  Like Boole’s logic, electronics have 2 values  Simple gates combine to make modern circuitry  All initially part of Boolean algebra  Basis of programming at the lowest, rawest level

7 Truth Table  Normal way that Boolean functions presented  All combinations of inputs shown in this table  This is really easy, inputs must be true or false  Output shown for each of the possible inputs  Given how it sounds, not at all complicated  Very simple rules to follow to construct  Does requires you count up to 2

8 NOT Gate  Simplest gate: computes opposite of input  Output false when input true;  Output true when input false; !a  Written in C++ as !a  a is gate’s input a !a!a!a!a true false a !a!a

9 OR Gate  Equivalent to addition in Boolean algebra  If either input is true is going to be checked  true when either a OR b are true; false otherwise a || b  Written in C++ as a || b  a & b are both inputs to gate ab a || b false true false true a b a || b

10 AND Gate  Equivalent to multiplication in Boolean algebra  If both inputs are true is going to be checked  True when a AND b are true; false otherwise a && b  Written in C++ as a && b  a & b are both inputs to gate a b a && b ab false true false true

11 Boolean Values  3 boolean functions can combine into computer  Billions of gates combined by engineers to make CPU (a && b) || (a && !c)  Could use, for example: (a && b) || (a && !c)  But how to generate inputs for these functions  First need boolean values of true and false  Easy in hardware (true is any signal > 3.3V)  But how could we do get values within our program?

12 Relational Operators  < ( less than)  > ( greater than)  <= ( less than of equal to)  >= ( greater than of equal to)  != ( inequality ≠)  == ( equality – if two things have same value)

13 Relational Operators

14 Assignment vs. Comparison

15 Relational Operators  Relational operators compute bool  Like any expression, can be used in any statements int nfl = 32; bool team = 0 > 6; bool group = 45 <= nfl; bool gang = nfl == 32; team = sqrt(144) == 12.0; group = (133 == pow(12, 2)); gang = (group == team);

16 Your Turn  Get in groups & work on following activity

17 For Next Lecture  Read sections 2.1 – 2.9 for Monday  Why do programmers never wash their hair?  How do we discuss & display program ideas?  Why do coders have flow? How can we chart this?  Week #3 weekly assignment due Tuesday  Problems available on Angel  If problem takes more than 10 minutes, TALK TO ME!


Download ppt "CSC 107 – Programming For Science. Follow-Up From Last Lecture."

Similar presentations


Ads by Google