Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Georgia Tech, IIC, GVU, 2006 MAGIC Lab Rossignac Programming Project 1 Truth Table Lecture 03, file P1 Due January.

Similar presentations


Presentation on theme: "1 Georgia Tech, IIC, GVU, 2006 MAGIC Lab Rossignac Programming Project 1 Truth Table Lecture 03, file P1 Due January."— Presentation transcript:

1 1 Georgia Tech, IIC, GVU, 2006 MAGIC Lab http://www.gvu.gatech.edu/~jarekJarek Rossignac Programming Project 1 Truth Table Lecture 03, file P1 Due January 24 before class as a link on your PPP Jarek Rossignac CS1050: Understanding and Constructing Proofs Spring 2006

2 2 Georgia Tech, IIC, GVU, 2006 MAGIC Lab http://www.gvu.gatech.edu/~jarekJarek Rossignac 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/processing/P1 Modify it to display the truth tables for –E=(A  B  C)  ¬ (A  B  B  C  C  A)  A  B  C –G=A  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 3 Georgia Tech, IIC, GVU, 2006 MAGIC Lab http://www.gvu.gatech.edu/~jarekJarek Rossignac Start with a similar program Go to my PPP –http://www.gvu.gatech.edu/~jarek/courses/1050/processing/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 4 Georgia Tech, IIC, GVU, 2006 MAGIC Lab http://www.gvu.gatech.edu/~jarekJarek Rossignac 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 5 Georgia Tech, IIC, GVU, 2006 MAGIC Lab http://www.gvu.gatech.edu/~jarekJarek Rossignac Global variables PFont fontUsed; // name of font used for writing numbers on the graphic screen int W=16, H=16; // width and height of the table int T[][] = new int[H][W]; // 2D table (array). Will contain integers boolean TF[][] = new boolean[H][W]; // 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 6 Georgia Tech, IIC, GVU, 2006 MAGIC Lab http://www.gvu.gatech.edu/~jarekJarek Rossignac 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 cw=int(0.9*width/W); // computes cell sizes (margin). Cast to integer ch=int(0.9*height/H); // (height and width of window are keywords) fontUsed = loadFont("Times-Roman-25.vlw"); // this font must be loaded (MENU-BAR > TOOLS > CREATE FONTS) textFont(fontUsed, 15); // selects font and assigns size }; // end of setup

7 7 Georgia Tech, IIC, GVU, 2006 MAGIC Lab http://www.gvu.gatech.edu/~jarekJarek Rossignac 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(width*0.05,height*0.05); // move origin, leave margin ShowTruthTable(); // Defined below: does all the work noLoop(); // stops the loop of draw() }; // end of draw

8 8 Georgia Tech, IIC, GVU, 2006 MAGIC Lab http://www.gvu.gatech.edu/~jarekJarek Rossignac 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 9 Georgia Tech, IIC, GVU, 2006 MAGIC Lab http://www.gvu.gatech.edu/~jarekJarek Rossignac ShowTruthTable void ShowTruthTable() { color cellColor = myGreen; // set cellColor to default green int v=0; // 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 h=0; h<H; h++) { // scan the rows using integer h for (int w=0; w<W; w++) { // scan the entries in each row using integer w T[h][w]=v; // store integer value to be displayed in cell B=byte(v % 256); // converts to a byte using modulo S=binary(B); // extracts bits into a string for (int j=0; j<S.length(); j++) { P[j] = S.charAt(j) == '1'; }; // sets T/F values for each bit if (expression(P[0],P[1],P[2],P[3],P[4],P[5],P[6],P[7])) // test expression {cellColor = myGreen;} // to set color else {cellColor = myRed; }; drawCell(w*cw,h*ch,cw,ch,cellColor,T[h][w]); // calls my DrawCell v++; // increment v }; }; // end of double loop };

10 10 Georgia Tech, IIC, GVU, 2006 MAGIC Lab http://www.gvu.gatech.edu/~jarekJarek Rossignac 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,wp+cwp/10,hp+chp*0.8);// writes int vp on the screen text(binary(vp,8),wp+cwp/10,hp+chp*0.8); // writes vp as binary in cell on the screen };

11 11 Georgia Tech, IIC, GVU, 2006 MAGIC Lab http://www.gvu.gatech.edu/~jarekJarek Rossignac 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 = A==B==C==D==E==F==G==H ; // what does this compute ??? return(res); };

12 12 Georgia Tech, IIC, GVU, 2006 MAGIC Lab http://www.gvu.gatech.edu/~jarekJarek Rossignac Resulting picture


Download ppt "1 Georgia Tech, IIC, GVU, 2006 MAGIC Lab Rossignac Programming Project 1 Truth Table Lecture 03, file P1 Due January."

Similar presentations


Ads by Google