To Lecture Notes

IT 231 -- 8/13/12


Takehome Midterm

 

The Range Class

 

Review Questions

Pay particular attention to Questions 8 and 9. Similar questions will be on the final exam.

  1. Write a Ruby statement to create an empty array. Ans:
  2. What is the output?
  3. What is the output in each case? What does the Ruby code do?
  4. Write a Rails view that displays 1000 lines on a page like this: Use the range 1..1000 with a for loop.
  5. What does each of these Ruby code fragments do?
  6. What does this Ruby code do? Replace the for statement with one using the Array each method:
  7. What does the <pre> tag do?
     
    Ans: Anything between begin and end pre tags preserves whitespace. Newline characters (denoted as "\n" in Ruby) are not eliminated as they are in the browser if the pre tags are not present.
     
  8. * For a Student model with fields first_name, gender, year, gpa, write controller and view statements that will display these sentences with each ?? replaced by the correct number.
     
    1. The total number of students is ??. Ans:
        <p>The total number of students is 
        <%= Student.count %>.</p>
        
    2. The number of women students is ??.
        <p>The number of woman students is 
        <%= Student.find_all_by_gender('F').count %>.</p>
        
    3. The number of sophomore students is ??.
        <p>The number of sophomores is 
        <%= Student.find_all_by_gender(2).count %>.</p>
        
  9. * In a scaffold-based project with model Order and fields customer_name, credit_card_number, credit_card_type, and order_date, the file _form.html.erb contains this ERB code for inputing credit_card_type:
    1. Replace the textfield with a select control (dropdown menu) having options Discover, Master Card, and Visa. Ans:
      <%= f.label :credit_card_type %><br />
      <%= f.select :credit_card_type,
                [['Discover', 'D'],
                [['MasterCard', 'M'],
                [['Visa', 'V']]          %><br />
      
    2. Replace the textfield with three radio button controls that correspond to Discover, Master Card, and Visa.
        <%= f.label :credit_card_type %><br />
        Discover 
        <%= f.radio_button :credit_card_type, 'D', :checked => false %>
        MasterCard
        <%= f.radio_button :credit_card_type, 'M', :checked => false %>
        Visa 
        <%= f.radio_button :credit_card_type, 'D', :checked => true %>
        

 

Review for Final Exam