You are here:   ArielOrtiz.com > Software Design and Architecture > Lab 9: Pascal's Triangle

Lab 9: Pascal's Triangle

Objectives

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.

Activity Description

The lab activities can be developed individually or in pairs.

The lab report must be developed individually.

  1. 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 9: Pascal's Triangle
    # Date: 29-Mar-2011
    # Authors:
    # 456654  Anthony Stark 
    # 1160611 Thursday Rubinstein
  2. Create a layout file for the application with the following content:

    <!DOCTYPE html>
    <html>
    <head>  
      <%= stylesheet_link_tag :all %>
      <%= javascript_include_tag :defaults %>
      <%= csrf_meta_tag %>
      <title><%= yield :title %></title>
    </head>
    <body>    
      <%= yield :layout %>    
      <hr/>    
      <p class="footer">
        Software Design and Architecture              
      </p>
    </body>
    </html>
    

    Create a stylesheet file with the following content:

    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;
    }
  3. 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:

    Input page

    When the submit button labeled "Send" is pressed, the action draw should be requested.

  4. 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:

    Output page

Deliverables

To hand in your individual lab work, follow these instructions.

Due date is Monday, April 4.

Evaluation

This activity will be evaluated using the following criteria:

50% Implementation of functional requirements.
50% Lab report.
DA The program and/or report was plagiarized.
© 1996-2011 by Ariel Ortiz (ariel.ortiz@itesm.mx)
Made with Django | Licensed under Creative Commons | Valid XHTML | Valid CSS