next up previous
Up: APS105F Home

University of Toronto
Faculty of Applied Science and Engineering

Midterm Examination - October 1996
  
APS105F - Computer Fundamentals

Examiner - Paul Chow

  1. There are 6 questions and 10 pages. Do all questions. The total number of marks is 100.
  2. ALL WORK IS TO BE DONE ON THESE SHEETS! Use the back of the pages if you need more space. Be sure to indicate clearly if your work continues elsewhere.
  3. Please put your final solution in the box if one is provided.
  4. No calculators or other computing devices allowed.
  5. Paper Type A - No Aids permitted.

1 [15] -10pttex2html_wrap138(100,25) 
2 [20] -10pttex2html_wrap138(100,25) 
3 [20] -10pttex2html_wrap138(100,25) 
4 [15] -10pttex2html_wrap138(100,25) 
5 [10] -10pttex2html_wrap138(100,25) 
6 [20] -10pttex2html_wrap138(100,25) 
Total [100] -10pttex2html_wrap138(100,25) 

Print:
First Name:tex2html_wrap152Last Name:tex2html_wrap152
 
Login ID:tex2html_wrap156
 
Student Number:tex2html_wrap156

    1. The Unix directory tree shown below gives a part of the structure of the ECF file system. Assume that you are user smith and you have just logged onto your account. By adding to the figure, show the structure of the file system after you execute the following commands:

      mkdir assignments
      cd assignments
      cp /usr/copy/aps105/sort.t mysort.t
      mkdir ~/stuff
      cp /usr/copy/aps105/faces.t ~/stuff/myfaces.t
      cd ..
      mv ~/stuff/myfaces.t ~/assignments/newfaces.t
      rmdir ~/stuff
      pwd

      What is the output of the last command? Hint: It starts with `/'.

      -10pttex2html_wrap138(300,25) 

    2. Unix uses a one-way cipher for encrypting passwords. What does it mean for a cipher to be one-way?

      After you type in your password, what does the system do before you are allowed to login?

    3. What are the three basic types of interfaces used by a computer to communicate with the outside world? Give an example of each.

    4. List three data types in Turing.

    5. What is the difference between semantics and syntax?

  1. Consider the following fragment of a program:

    procedure P(x : int)
        ...
    end P
    
    procedure Q(var y : int)
        ...
    end Q
    
    var A,B,C : int
    
    A := 5
    B := 7
    P(A)
    Q(B)
    Q(B-A)
    P(A+B)
    Q(P)
    P(12)
    Q(10)

    1. Explain the mechanics of how var and non var parameters are handled. Show all of the relevant memory locations and indicate when they are created and/or destroyed. Use the calls P(A) and Q(B) in the above program as examples.

    2. In the program above, which procedure calls are not valid in Turing? Why?

    3. For the following program, draw lines to indicate the scope of all variables.

      var A : int
      var B : int
      var D : int
      
      procedure P (A : int, var C : int)
          var tmp : int
      
          B := B + 30
          if A < B then
              tmp := A
          else
              tmp := B
          end if
      
          C := tmp
      end P
      
      A := 5
      B := 42
      P (A, D)
      put A, ",", B, ",", D

      What is the final value of A? -10pttex2html_wrap138(100,25) 

      What is the final value of B? -10pttex2html_wrap138(100,25) 

      What is the final value of D? -10pttex2html_wrap138(100,25) 

  2. Write a pseudo code program (using a Turing-like language) that can be used to help someone convert between the Celsius and Fahrenheit temperature scales. Your program should prompt the user for input and output the temperature in the other scale. You can assume the input will be of the form:
    0 F
    17 C
    where there is an integer followed by a letter, which will be an F or a C for Fahrenheit and Celsius, respectively. The number and letter will be separated by a space. The program ends when the letter is not F or C. Note that tex2html_wrap_inline134.

  3. Assume that x and N are variables that have values assigned to them.

    1. Translate the following for loop into a semantically equivalent while loop.
      for i : 1 .. 12
          x := x + 1
      end for

    2. Translate the following for loop into a semantically equivalent repeat/until loop.
      for decreasing j : N .. 1 by 2
        x := x + 1
      end for

    3. Translate the following for loop into a semantically equivalent Turing loop/end loop loop.
      for i : 1 .. N by 7
        x := x + 1
      end for

  4. The algorithm for multiplying two tex2html_wrap_inline136 matrices is shown below.

    for i : 1 .. N
        for j : 1 .. N
            sum := 0
            for k : 1 .. N
                sum := sum + A(i,k) * B(k,j)
            end for
            C(i,j) := sum
        end for
    end for

    What is the computational complexity of this algorithm using the ``O'' notation?

    -10pttex2html_wrap138(100,50) 

    Explain/show how you derived your answer.

    1. When is it appropriate to use a function and when should you use a procedure?

    2. Using pseudo code, write a recursive function, FindSum, that calculates the sum of successive integers starting at 1 and ending at N. For example:
      FindSum(N) returns the sum of 1 + 2 + ... + N.

      Question 6 continued...

    3. Write an iterative version of FindSum.

next up previous
Up: APS105F Home

Paul Chow
Tue Oct 21 09:31:47 EDT 1997