prac1-soln-fall09

prac1-soln-fall09 - CMSC 330, Practice Problems 1...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CMSC 330, Practice Problems 1 (SOLUTIONS) 1. Programming languages a. Explain how goals for programming languages have changed since the 1960’s. Shifted from efficiency to ease-of-programming b. List 2 desirable attributes for a programming language where Ruby is better than C. Explain why. Naturalness of application – Text processing is easier in Ruby Cost of use – Small Ruby programs are simpler/quicker to write c. List 2 methods for executing a program. Which method is used by Ruby? Interpretation & compilation. Ruby is interpreted. 2. Ruby basics a. Write a Ruby method foo that takes an integer as a parameter. Call foo with 2 as its argument. Circle & label the formal and actual parameters in your code. def foo(x) … end ; foo(2) ; // x = formal param, 2 = actual parameter b. Using different Ruby control statements, write 4 code fragments that iterate from i=1 to i=10. 1.upto(10) {|i| puts i; } (1. .10).each {|i| puts i; } for i in (1. .10) do puts i; end i=1; while i<=10 do puts i; i+=1; end i=1; do puts i; break if (i+=1)>10 end c. Explain the difference between explicit and implicit variable declarations. Explicit – declaration statements declare type of each variable used
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

prac1-soln-fall09 - CMSC 330, Practice Problems 1...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online