During this lab session:
This activity helps students develop the following skills, values and attitudes: ability to analyze and synthesize, capacity for identifying and solving problems, and efficient use of computer systems.
This lab can be developed individually or in pairs.
Create a Ruby on Rails application called pascal
.
Inside this application, generate a controller called
triangle
with two actions: input
and
draw
.
The Ruby source file triangle_controller.rb
must
start with a comment containing the lab's title, date, and the
authors' personal information. For example:
# Lab 7: Pascal's Triangle # Date: 29-Oct-2009 # Authors: # 456654 Anthony Stark # 1160611 Thursday Rubinstein
Create a layout file for the application with the following content:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <style type="text/css"> body { background: #FFFFFF; color: #000080; font-family: sans-serif; font-size: medium; margin: 20px; } hr { border: 0; color: #B0C4DE; background-color: #B0C4DE; height: 1px; } table { border-collapse: collapse; border: 1px solid #000000; padding: 0px; margin-bottom: 10px; color: #000000; background: #E6E6FA; } td { border: 1px solid #000000; padding: 10px; text-align: center; } th { border: 1px solid #000000; padding: 10px; color: #008080; background: #B0E0E6; } .footer { font-size: 70%; color: #B0C4DE; text-align: center; } </style> <title><%= yield :title %></title> </head> <body> <%= yield :layout %> <hr/> <p class="footer"> Software Design and Architecture </p> </body> </html>
Modify the input.html.erb
file so that it contains
a web form with a text field that asks for a number n
between 0 and 99. It should look like this:
When the submit button labeled "Send" is pressed, the action
draw
should be requested.
The draw
action and view must work together in
order to display the diagonals 0 to n of Pascal's
triangle (using the <table>
,
<tr>
and <td>
tags).
This is how the triangle should be built: the first row and column are composed of ones; all other elements are computed by adding the element immediately above plus the element immediately to the left. In the resulting table, all cells that are not part of the triangle should be left blank. For example, for n = 5, the output should look something like this:
To hand in your lab work, follow these instructions:
pascal
directory. Call this file
pascal.zip
.
This activity will be evaluated using the following criteria:
100 | The code works as requested. |
---|---|
60-90 | The code works, but has some flaws. |
20-50 | The code doesn't work, but it seams that some amount of time was spent on it. |
DA | The program was plagiarized. |