next up previous
Up: APS105F Home

University of Toronto
Faculty of Applied Science and Engineering

Final Examination - December 1996
  
APS105F - Computer Fundamentals

Examiner - Paul Chow

  1. There are 6 questions and 22 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. Appendix B describes the basic OOT syntax you will require and Appendix C describes the basic C syntax you will require.
  6. Place your student card on your desk.

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

Print:
First Name:tex2html_wrap768Last Name:tex2html_wrap768
 
Login ID:tex2html_wrap772
 
Student Number:tex2html_wrap772

    1. What is the purpose of the program counter inside the CPU?

    2. What are the three basic steps of CPU operation carried out for each instruction? Give a short description of what happens in each step.

    3. Why does a fast CPU need to have caches?

    4. You have been made chief designer of the Intel Pentium Super Pro Plus Plus processor. Give a very general overview of the kinds of experiments or studies that you would do to figure out the size of caches that you require.

  1.  
    1. Consider the following C program.

      #include <stdio.h>
      
      int mystery(int, int, int);
      
      main()
      {
        int a, b, c;
        do
          {
            printf("Enter three integers: ");
            scanf("%d%d%d", &a, &b, &c);
            printf("The result is: %d\n",mystery(a,b,c));
          } while (a > 0);
      }
      
      int mystery(int x, int y, int z)
      {
        int this = x;
      
        if (y > this)
          this = y;
        if (z > this)
          this = z;
        return this;
      }

      What does the program do?

      Continued...

      Question 2 continued...

      Write an equivalent OOT program.

    2. Write an equivalent C program for the following OOT program:

      procedure Order (var X, Y : real)
          var temp : real
          if X > Y then
              temp := X
              X := Y
              Y := temp
          end if
      end Order
      
      var a, b : real
      
      for i : 1 .. 10
          put "Enter a pair of numbers: "..
          get a, b
          Order(a,b)
          put "In order, the numbers are: ",a," ",b
      end for

  2.  
    1. Define a pointer.

    2. Consider the following code fragment. Recall that &varname means addr(varname) and *varname means deref(varname).

          int ivar, jvar;
          int *iptr;
      
          iptr = &ivar;
          ivar = 5;
          jvar = 20;
      
          /* A */
      
          *iptr = jvar + ivar;
      
          /* B */

      Assume that the variables are stored in memory at the following addresses:


      tabular62

      What are the values of the variables at points A and B?


      tabular74

      Question 3 continued...

    3. Consider the part of a binary tree shown below:

       tex2html_wrap776

      1. Write an OOT declaration for a node in the tree. Assume the node needs to store a string variable.
      2. Assume that new, cur, and prev are pointers to the nodes shown. Write OOT code to delete node A and replace it with node B.

      Question 3 continued...

    4. Draw the sorted binary tree that results when the letters c,o,m,p,u,t,i,n and g are inserted in the order shown.

  3. You have been asked to lead the development of a new software product. For a status report that you are writing, you need to include a few paragraphs describing the programming language that you have chosen to use and the reasons for selecting it. Write those paragraphs here, and include in your discussion at least two arguments for and two against the use of strongly-typed languages such as Turing versus C. Finally give your choice and the reasons.

    Marks will be given for both the technical content and the style of presentation.

  4.  

    Consider the following program:

    #include <stdio.h>
    #define SIZE 5
    
    void someFunction(int b[ ],int size);
    
    main()
    {
      int a[SIZE] = {32,27,64,18,95};
    
      printf("Here is the output:\n");
      someFunction(a,SIZE);
      printf("\n");
      return 0;
    }
    
    void someFunction(int b[ ], int size)
    {
      /* Enter the values of b[0] and size at this point */
      if (size > 0)
        {
          someFunction(&b[1], size-1);
          printf("%d ",b[0]);
        }
    }

    Continued on next page...

    Question 5 continued...

    1. Trace the execution of the program by filling in the values of b[0] and size just after the entry to each call of someFunction. Note that the table may be larger than necessary.


      tabular112

    2. What does this program do?
    3. Show the final output of the program.

  5.  

    In this question you will develop part of a program that implements a part of a language called Logo. Logo was famous for the concept called turtle graphics. Imagine a mechanical turtle that walks around the room under the control of a Turing program. The turtle holds a pen in either the up position or the down position. While the pen is down, the turtle draws on the surface as it moves; while the pen is up, the turtle moves without writing anything. The program being developed will simulate the operation of the turtle and create a computerized drawing.

    Assume the turtle moves about an array called World that is initialized to be all zeroes. The size of the world is determined by two constants called EndOfWorldX and EndOfWorldY. Commands are read from the terminal as a series of integer numbers. The program keeps track of the position of the turtle using the variables CurX and CurY. Whenever the turtle hits the edge of the world, it will stop at the edge. (Otherwise, we will lose too many turtles due to bad driving!)

    There are four variables (N, S, E, W) that determine the direction of travel, corresponding to north (up), south (down) , east (right), and west (left).

    The turtle is initially placed approximately at the middle of the World with the pen up. The variable PenIsDown is used to keep track of the position of the pen. When the turtle moves with the pen down, the appropriate elements of the World array are set to 1.

    When the print command is given, the array is printed on the terminal. Wherever a 1 is encountered in the array, print an `x', otherwise print a blank.

    The set of commands to be processed by the turtle are:


    tabular140

    Continued...

    Question 6 continued...

    In the following example, the turtle is assumed to be near the middle of the world. The commands will cause it to draw a 6 by 6 square and print the output.

    2
    5 6
    3
    5 6
    3
    5 6
    3
    5 6
    1
    6
    9

    The skeleton of the program you are to complete is shown in Appendix A on page gif. Study this code to see how it works.

    1. You will write the appropriate Turing code for the functions below: You only need to write the code that goes inside the procedure declarations, which are shown in Appendix A.

      PenUp
       
      PenDown
        Continued...

      Question 6 continued...

      RightTurn
       
      PrintArray
        Question 6 continued...

      Forward(Distance)
        You only need to write the code for the directions N and W, but indicate with comments where the code for E and S should be.

      Continued...

      Question 6 continued...

    2. Starting with the example program but omitting the End command (9), add the code needed to draw a vertical line through the middle of the box that ends at the top and bottom edges of the box. Print the result and leave the pen up. Please put comments beside your program!

      The resulting figure would look something like this: tex2html_wrap778

A Turtle Code

 

var PenIsDown : boolean	 % true means pen is down, false means up
var CurX : int           % X,Y coordinate of the turtle
var CurY : int
const EndOfWorldX := 20
const EndOfWorldY := 20
var World : array 1 .. EndOfWorldX, 1 .. EndOfWorldY of int
var N,S,E,W : boolean    % direction variables.  Only one can be true.

procedure PenUp
    % Your code here
end PenUp

procedure PenDown
    % Your code here
end PenDown

procedure RightTurn
    % Your code here
end RightTurn

procedure LeftTurn
    % Has been done, not shown here.
end LeftTurn

procedure Forward(Distance : int)
    % Your code here
end Forward

procedure PrintArray
    % Your code here
end PrintArray

function ParseCommands : int
    var Command : int
    var Distance : int

    put "Instruction? "..
    get Command

    if Command = 1 then
        PenUp
        result 1
    elsif Command = 2 then
        PenDown
        result 1
    elsif Command = 3 then
        RightTurn
        result 1
    elsif Command = 4 then
        LeftTurn
        result 1
    elsif Command = 5 then
        get Distance
        Forward(Distance)
        result 1
    elsif Command = 6 then
        PrintArray
        result 1
    elsif Command = 9 then
        result 0
    else
        put "Illegal instruction: ",Command
        result -1
    end if
end ParseCommands

% Main program

    CurX := EndOfWorldX div 2    % start in the middle
    CurY := EndOfWorldY div 2
    PenIsDown := false

    % start with a blank world
    for row : 1..EndOfWorldX
        for col : 1..EndOfWorldY
            World(row,col) := 0
        end for
    end for

    N := true
    S := false
    E := false
    W := false

    loop
        var ret_code : int
        ret_code := ParseCommands
        if ret_code = 0 then
            exit
        end if
    end loop

B OOT Syntax

 


tabular275

Continued...


tabular300

C C Syntax

 


tabular482

Continued...


tabular513


next up previous
Up: APS105F Home

Paul Chow
Mon Dec 15 08:40:22 EST 1997