Programming Project 1 Truth Table Lecture 03, file P1 Due January 24 before class as a link on your PPP - PowerPoint PPT Presentation

About This Presentation
Title:

Programming Project 1 Truth Table Lecture 03, file P1 Due January 24 before class as a link on your PPP

Description:

... (A B C) (A B B C C A) ... // end of setup Draw void draw() { // will be executed continuously (loop) background (200 ... – PowerPoint PPT presentation

Number of Views:57
Avg rating:3.0/5.0
Slides: 13
Provided by: Jare83
Category:

less

Transcript and Presenter's Notes

Title: Programming Project 1 Truth Table Lecture 03, file P1 Due January 24 before class as a link on your PPP


1
Programming Project 1 Truth Table Lecture 03,
file P1Due January 24 before class as a link on
your PPP
CS1050 Understanding and Constructing Proofs
Spring 2006
  • Jarek Rossignac

2
Truth Tables
  • Write a program that will display the truth
    tables for Boolean expressions
  • A template is provided at
  • http//www.gvu.gatech.edu/jarek/courses/1050/pro
    cessing/P1
  • Modify it to display the truth tables for
  • E(A?B?C) ? (A?B ? B?C ? C?A) ? A?B?C
  • GA ? B ? C
  • Export it and post a web page for it
  • Details to include are described below (online
    report)
  • Add a link to it from your PPP
  • Email the TA by January 24
  • Subject 1050 P1
  • Remind the TA of the URL for the PPP

3
Start with a similar program
  • Go to my PPP
  • http//www.gvu.gatech.edu/jarek/courses/1050/proc
    essing/ppp.html
  • Access the source code for Project 1
  • Study it
  • Modify it to draw the truth table for
  • (A?B?C) ? (A?B ? B?C ? C?A) ? A?B?C
  • Run it and capture the image of the truth table
  • Comment out the above expression and modify it to
    draw the truth table for
  • A ? B ? C
  • Run it and capture the image of the truth table
  • Export the applet

4
Produce an online report
  • Modify the resulting index.html to include the
    usual info
  • As you did for P0
  • Name, P1, title, date completion, link to source
    code
  • Insert the images of the two truth tables with
    the corresponding formulae AND the corresponding
    Processing expression that you used to implement
    them
  • Conclude whether the two expressions are
    equivalent
  • Make sure that you have modified the header of
    the source file (Project no, title, your name,
    completion date)
  • Make sure to include a link to this page from
    your PPP

5
Global variables
  • PFont fontUsed // name of font used for writing
    numbers on the graphic screen
  • int W16, H16 // width and height of the
    table
  • int T new intHW // 2D table
    (array). Will contain integers
  • boolean TF new booleanHW // 2D table
    (array). Will contain booleans
  • color myRed color(250,100,100) // my
    colors (R,G,B) in 0,255
  • int cw, ch // cell width and height

6
Setup
  • void setup() // executed only once
    as initialization
  • size(500, 500) // opens graphic window
    of 600x600 pixels.
  • // X axis goes right, Y axis goes DOWN
  • cwint(0.9width/W) // computes cell sizes
    (margin). Cast to integer
  • chint(0.9height/H) // (height and
    width of window are keywords)
  • fontUsed loadFont("Times-Roman-25.vlw")
  • // this font must be loaded (MENU-BAR gt
    TOOLS gt CREATE FONTS)
  • textFont(fontUsed, 15) //
    selects font and assigns size
  • // end of setup

7
Draw
  • void draw() // will be executed
    continuously (loop)
  • background(200) // erases the screen and
  • // paints a light grey background (0 is black,
    255 is white)
  • strokeWeight(2) // lines will be drawn
    thicker
  • translate(width0.05,height0.05) // move
    origin, leave margin
  • ShowTruthTable() // Defined below does
    all the work
  • noLoop() // stops the loop of
    draw()
  • // end of draw

8
Control
  • // executed when a key is pressed
  • void keyPressed()
  • if (key'i')
  • saveFrame("squares-.tif")
  • // saves a tif image of the graphics window in
    the folder of this program, replaces by a
    different number each time

9
ShowTruthTable
  • void ShowTruthTable()
  • color cellColor myGreen //
    set cellColor to default green
  • int v0 // current
    value, will be incremented as we scan the table
  • byte B // byte
    equivalent of v
  • String S // string
    used to extract the bits of B
  • boolean P new boolean 8 // table
    of Booleans corresponding to these bits
  • for (int h0 hltH h) // scan
    the rows using integer h
  • for (int w0 wltW w) // scan the
    entries in each row using integer w
  • Thwv // store
    integer value to be displayed in cell
  • Bbyte(v 256) // converts
    to a byte using modulo
  • Sbinary(B) // extracts
    bits into a string
  • for (int j0 jltS.length() j) Pj
    S.charAt(j) '1' // sets T/F values for
    each bit
  • if (expression(P0,P1,P2,P3,P4,P
    5,P6,P7)) // test expression
  • cellColor myGreen
    // to set color
  • else cellColor myRed
  • drawCell(wcw,hch,cw,ch,cellColor,Thw
    ) // calls my DrawCell
  • v //
    increment v
  • // end of double loop

10
Draw a cell and print its value
  • // will draw cell (position, size, color, text)
  • void drawCell(int wp, int hp, int cwp, int chp,
    color cp, int vp)
  • fill(cp) // set color to be used for
    filling in regions
  • rect(wp,hp,cwp,chp) // draws and fills a
    rectangular region
  • fill(0) // to write in black
  • // text(vp,wpcwp/10,hpchp0.8)// writes int
    vp on the screen
  • text(binary(vp,8),wpcwp/10,hpchp0.8)
  • // writes vp as binary in cell on the screen

11
Proposition
  • // Function evaluating the Boolean expression
  • boolean expression
  • (boolean A, boolean B, boolean C, boolean D,
  • boolean E, boolean F, boolean G, boolean H)
  • boolean res ABCDEFGH
  • // what does this compute ???
  • return(res)

12
Resulting picture
Write a Comment
User Comments (0)
About PowerShow.com