Difference between revisions of "CSC103 Take-Home Final Exam Fall 2012"

From dftwiki3
Jump to: navigation, search
Line 18: Line 18:
  
 
=Problem #3: Processing Language=  
 
=Problem #3: Processing Language=  
 +
=Problem 2: Programming in Processing=
 +
[[Image:CSC103ProcessingFinal2012.png|right|150px]]
 +
==Initial Program==
 +
* Copy/Paste this program into the Processing editor.
 +
<br />
 +
<code><pre>
 +
// declare a variable called diameter that will contain
 +
// real numbers.
 +
float diameter;
  
=Problem #4: Von Neumann's Bottleneck=
+
void setup() {
 +
  size( 500, 500 );
 +
  smooth();
 +
}
  
 +
void draw() {
 +
  // put a random number less than 200 into variable diameter
 +
  diameter = random( 200 );
 +
 +
  // pick a color with a random amount of red, 100 units of green, and 200 units of blue
 +
  fill( random(255),100, 200 ); 
 +
 +
  // draw 10 circles at random position in the window, with the same diameter.
 +
  for ( int i=1; i<=10; i++ ) {
 +
      ellipse( random( 500 ), random( 500 ), diameter, diameter );
 +
  }
 +
     
 +
}
 +
</pre></code>
 +
<br />
 +
* Run it and observe how it works.
 +
==Some Explanations==
 +
 +
* There are 2 new elements in the program:
 +
** <tt>float diameter</tt>, and
 +
** <tt>random( )</tt>.
 +
* <tt>float diameter</tt> simply says that '''diameter''' is used in the program as a ''variable'' that will contain a real number (real numbers are numbers with a decimal point).
 +
* <tt>random()</tt> is a function that returns a random number.  If you call <tt>random(10)</tt>, it will return a random number between 0 and 10, not inclusive.  So, when we write:
 +
 +
  diameter = random( 200 );
 +
 +
:we make the sketch store a random number into the variable diameter, and we force this random number to be larger than or equal to 0, and less than 200.
 +
:When we call '''ellipse()''' and write <tt>random(500)</tt> for both the ''x'' and ''y'' coordinates, we make the sketch put a circle in the window at a random position, but we force the center of the circle to remain inside the window.
 +
* Make sure you read the documentation on '''random()''' in the [http://processing.org/reference/ reference section] of [http://processing.org/ processing.org] to fully understand what it does.
 +
 +
==Your Assignment==
 +
 +
# make your sketch display circles on the window '''only''' when the mouse button is ''pressed''.  If the mouse isn't pressed, nothing happens in the window
 +
# make the circles shrink in size if the mouse moves toward the left side of the window.  The circles will grow in size if the mouse moves toward the right side of the window.  The circles are still random in size, but their maximum size depends on the mouse position.
 +
# make the circles more random in color and not with this strong ''blue'' tint.  Moreover, instead of having 10 circles the same color every time ''draw()'' is called, make each of the 10 a different (random) color.
 +
 +
==Example==
 +
* Here is an example below showing the final sketch running.  It is not possible to hear the mouse click but you will see that the generation of circles is interrupted regularly when the user releases the mouse button.
 +
<br />
 +
<center><videoflash>1g_S8ekD0nk</videoflash></center>
 +
<br />
 +
 +
==Submitting the Program (<font color="red">NEW SECTION</font>)==
 +
(Section added on 3/8/12: --[[User:Thiebaut|D. Thiebaut]] 09:56, 8 March 2012 (EST))
 +
 +
* Please submit the code of your sketch the same way you did for [[CSC103_Homework_5_2012 | Homework 5]].
 +
* Go to this URL: http://maven.smith.edu/~103b/submitfinal.htm
 +
* Enter your 2-letter Id (same as the one you used in Homework 5)
 +
* Add your name in the top of the text area, prefixed with two slashes (to make it a comment)
 +
* Paste your code in the text area, and
 +
* Submit it!
 +
<br /><br /><br />
 +
<tanbox>You should still submit a copy of your sketch on paper with your final exam.</tanbox>
 +
<br /><br /><br /><br />
  
  

Revision as of 20:34, 17 October 2012

--D. Thiebaut 11:34, 16 October 2012 (EDT)


This exam is given under the rule of the Smith College honor code. Your work has to be done individually. You cannot discuss ANY of this material with anybody, with the exception of your instructor. TAs are not allowed to give help about this final exam.
Once the last lecture of the 1/2 semester is over, questions can only be addressed via email. Whenever you send your instructor a question, the question and the answer will be broadcast back to the whole class within a short time period (between 7:00 a.m. - 9:00 p.m.).

<onlydft>

Problem #1: Logic Gates and Boolean Algebra

  • What is the boolean equation for the output Y of the circuit shown below?

CSC103LogicCircuitFinal.png

Problem #2: Assembly Language

  • Write an assembly language program that contains a loop and at least one variable called sum. Before the loop starts the variable sum contains 0. Once the loop ends the variable sum contains the sum of all the multiples of 3 between 0 and 30. In other words, your program computes 0 + 3 + 6 + 9 + 12 + 15 + 18 + 21 + 24 + 27 + 30 and stores the result in the variable sum.

Problem #3: Processing Language

Problem 2: Programming in Processing

CSC103ProcessingFinal2012.png

Initial Program

  • Copy/Paste this program into the Processing editor.


// declare a variable called diameter that will contain
// real numbers.
float diameter;

void setup() {
  size( 500, 500 );
  smooth();
}

void draw() {
   // put a random number less than 200 into variable diameter
   diameter = random( 200 ); 

   // pick a color with a random amount of red, 100 units of green, and 200 units of blue
   fill( random(255),100, 200 );  

   // draw 10 circles at random position in the window, with the same diameter.
   for ( int i=1; i<=10; i++ ) {
      ellipse( random( 500 ), random( 500 ), diameter, diameter );
   }
       
}


  • Run it and observe how it works.

Some Explanations

  • There are 2 new elements in the program:
    • float diameter, and
    • random( ).
  • float diameter simply says that diameter is used in the program as a variable that will contain a real number (real numbers are numbers with a decimal point).
  • random() is a function that returns a random number. If you call random(10), it will return a random number between 0 and 10, not inclusive. So, when we write:
  diameter = random( 200 );
we make the sketch store a random number into the variable diameter, and we force this random number to be larger than or equal to 0, and less than 200.
When we call ellipse() and write random(500) for both the x and y coordinates, we make the sketch put a circle in the window at a random position, but we force the center of the circle to remain inside the window.

Your Assignment

  1. make your sketch display circles on the window only when the mouse button is pressed. If the mouse isn't pressed, nothing happens in the window
  2. make the circles shrink in size if the mouse moves toward the left side of the window. The circles will grow in size if the mouse moves toward the right side of the window. The circles are still random in size, but their maximum size depends on the mouse position.
  3. make the circles more random in color and not with this strong blue tint. Moreover, instead of having 10 circles the same color every time draw() is called, make each of the 10 a different (random) color.

Example

  • Here is an example below showing the final sketch running. It is not possible to hear the mouse click but you will see that the generation of circles is interrupted regularly when the user releases the mouse button.



Submitting the Program (NEW SECTION)

(Section added on 3/8/12: --D. Thiebaut 09:56, 8 March 2012 (EST))

  • Please submit the code of your sketch the same way you did for Homework 5.
  • Go to this URL: http://maven.smith.edu/~103b/submitfinal.htm
  • Enter your 2-letter Id (same as the one you used in Homework 5)
  • Add your name in the top of the text area, prefixed with two slashes (to make it a comment)
  • Paste your code in the text area, and
  • Submit it!




You should still submit a copy of your sketch on paper with your final exam.






<onlydft>