Windows Systems Programming: Spring 2004

[ Home | Syllabus | Course Notes | Assignments | Search]


Mid Term Exam (revision 1: February 28, 2003)

Rules of taking this test

  • This will be a take home exam which you will have 1 week to complete. Answers must be submitted no later than midnight Thursday March 4th.
  • You must work on your own, the only person you can ask for help is Dr. Wild.
  • This is open book, open note, open compiler (that is you can use a compiler to check your answers)
  • You can ask me questions or send e-mail.
  • You must return the test by e-mail.
  • You must sign the honor pledge and either fax or return original to me (even though you e-mail the answers).
    However, you will not get your grade until the honor pledge is turned in.

Honor Pledge: I pledge that I have neither given nor received unauthorized help in taking this exam.
You signature must be delivered to

Dr. Wild
Department of Computer Science
Old Dominion University
Norfolk, VA 23529-0162
FAX 757 6834900

Signature: __________________________________________________________

Printed Name:  __________________________________________________________

 

  1. . Net contains a garbage collection system
    a) Suppose you are running a small .NET program on a computer with a lot of memory so that there is no garbage collection performed while the program is running. Are there any circumstances where such a program could get into trouble? justify your answer (5)
    b) The imageview (fig 4.11) program contains the following code

    Bitmap bitmap = new Bitmap (FileName);
    if (MyBitmap != null)
    MyBitmap.Dispose (); // Important!
    MyBitmap = bitmap;

    //// Would the program still work if you replaced this code with the following statement? explain any differences in behavior if any (5 points)

    MyBitmap = new Bitmap (FileName);

  2. CIL Given the following program in CIL (Common Intermediate Language),
    a) generate a plausible c# program that might have generated this program (this process is called "reverse engineering") Your solution should be able to be compiled. (8)
    b) What observations can you make about the architecture of CIL? (2)

    .method private hidebysig static void  Main() cil managed
    {
      .entrypoint
      // Code size       28 (0x1c)
      .maxstack  4
      .locals init ([0] int32 x,
               [1] int32 a,
               [2] int32 e,
               [3] int32 b,
               [4] int32 z,
               [5] int32 d)
      IL_0000:  ldc.i4.3
      IL_0001:  stloc.1
      IL_0002:  ldc.i4.5
      IL_0003:  stloc.2
      IL_0004:  ldc.i4.s   71
      IL_0006:  stloc.3
      IL_0007:  ldc.i4.2
      IL_0008:  stloc.s    z
      IL_000a:  ldc.i4.6
      IL_000b:  stloc.s    d
      IL_000d:  ldloc.1
      IL_000e:  ldloc.2
      IL_000f:  mul
      IL_0010:  ldloc.3
      IL_0011:  ldloc.s    d
      IL_0013:  ldloc.s    z
      IL_0015:  mul
      IL_0016:  ldc.i4.3
      IL_0017:  div
      IL_0018:  add
      IL_0019:  mul
      IL_001a:  stloc.0
      IL_001b:  ret
    } // end of method class1::Main
    
    
  3. Consider the following code

    using System;
    struct Point {
    	public int X;
    	public int Y;
    	public Point (int x, int y){
    		this.X = x;
    		this.Y = y;	
    	}
    }
    class Rectangle {
    	public 	Point CornerTopLeft = new Point();
            public  Point CornerBottomRight = new Point();
    	public Rectangle () {} 
    }
    class Class1 {
    	static void Main(string[] args)	{
    		Point p1 = new Point(4,3);
    		Point p2;
    		p2 = p1;
    		p1.X = 56; p1.Y = 85;
    		Rectangle r1 = new Rectangle();
    		Rectangle r2;
    		r1.CornerTopLeft = p1;
    		r1.CornerBottomRight = p2;
    		r2 = r1;
    		r2.CornerTopLeft = new Point(1,0);
    		Console.WriteLine("({0},{1})",p2.X,p2.Y);
    		Console.WriteLine("({0},{1})",p1.X,p1.Y);
    		Console.WriteLine("({0},{1}) and ({2},{3})",
    			r1.CornerTopLeft.X,r1.CornerTopLeft.Y, r1.CornerBottomRight.X,r1.CornerBottomRight.Y);
    		Console.WriteLine("({0},{1}) and ({2},{3})",
    			r2.CornerTopLeft.X,r2.CornerTopLeft.Y,r2.CornerBottomRight.X,r2.CornerBottomRight.Y);
    	}
    }
    a) what will this program print? (5)
    b) explain why the program behaves this way (5)
     
  4. Consider figure 4.11 (the imageview program)
    a) There are three calls to "invalidate" in this program. Describe the changes in behavior if they are removed (describe each effect separately) (3)
    b) Is there a way to see the image even though these "invalidate" statements are removed? Explain (3)
    c) Change this program to remove the OnPaint function and instead write code to draw the image in place of the removed "Invalidate" statements. (4) 

  5. Suppose you have a plain text file containing "key=value" pairs one per line (e.g. Telephone=(757)683-4679). Write a program which will extract all the key/value pairs putting them into a Hashtable using a regular expression to extract the information from each line of the text file. Then print all values whose key is "Telephone". Also use a regular expression to verify that the value has the proper format (that is area code in parentheses, a single dash ('-') before the last four digits. there can be any number of spaces after the right parenthesis - for example (757)    683-4679 is valid, (757) 6834679 and (757) callodu are not valid). If the value does not have the proper format, print the message "does not have the correct format" after the value. (10)
    -------
    Clarification: a Hash Table only allows one entry for a given key. I will accept any reasonable solution that using a regular expression to verify the format of the phone number value. You can verify before or after the hash table entry. Your solution should not crash if there is a multiple entry.

  6. MyComicsDataList.aspx (figure 6.7), contains the following statement

    <asp:LinkButton CommandName="Select" RunAt="server"
       CommandArgument='<%# DataBinder.Eval
       (Container.DataItem, "Comment") %>'
       Text='<%# DataBinder.Eval (Container.DataItem,
          "Title") + " " +
          DataBinder.Eval (Container.DataItem,
         "Number") %>' />
    a) what would the effect be of changing this statement to (5 points)
    <asp:LinkButton  RunAt="server"
       CommandArgument='<%# DataBinder.Eval
       (Container.DataItem, "Comment") %>'
       Text='<%# DataBinder.Eval (Container.DataItem,
          "Title") + " " +
          DataBinder.Eval (Container.DataItem,
         "Number") %>' />
    b) what would be effect of changing this statement to(5 points)
    <asp:LinkButton CommandName="Select" RunAt="server"
       Text='<%# DataBinder.Eval (Container.DataItem,
          "Title") + " " +
          DataBinder.Eval (Container.DataItem,
         "Number") %>' />
  7. Change the data source for MyComicsRepeater.aspx to use an XML file instead of the SQL data base. Show the code changes and show one entry in the XML file (10)

  8. In testlist2.cs change the "Enumerator" class so that the states are enumerated in reverse (alphabetic) order (but don't change the values of the "states" array (10)

  9. In convert2.aspx
    a) what would be effect(s) if you changed the following two statements

    Currencies.DataTextField = "Currency";
    Currencies.DataValueField = "Exchange";

    //// to (5 points)

    Currencies.DataTextField = "Exchange";
    Currencies.DataValueField = "Currency";


Copyright chris wild 1999-2004.
For problems or questions regarding this web contact [Dr. Wild].
Last updated: February 28, 2004.