Fall-06 201-Midterm 2

 

 

Problem 1: fundamental questions   12 points

 

IP address:  154.16.52.16
subnet mask:  255.255.240.0
 
Please answer the following question
Which class?
Number of bits for subnets (excluding bits for global)
What is the default subnet mask for the ip address?
Number of subnets possible on this network.
Number of hosts possible on each subnet:
Which subnet this address is on:
Range of addresses on that subnet:

 

 

 

Problem 2: Run-time Calling Stack, stack frame (15 points)

 

 

 

 

Problem 3: Pass by value, pass by reference and pass by address value. (10 points)

 

 

 

 

Problem 4: Unix commands

 

 

 

Problem 5: Socket programming

 

 

Problem 6: Scheduling

 

 

Problem 7: Harddisk capacity calculation

           

 

 

Problem 8: basic concepts.

Five components of the von Neumann architecture

 

 

 

 

 


Problem 3 Image representation:  (5 points)

 

#define BYTE unsigned char

#define WORD unsigned short int

#define DWORD unsigned int

#define LONG int

 

typedef struct tagBITMAPFILEHEADER {

  WORD    bfType;

  DWORD   bfSize;

  WORD    bfReserved1;

  WORD    bfReserved2;

  DWORD   bfOffBits;

} BITMAPFILEHEADER, *PBITMAPFILEHEADER;

 

typedef struct tagBITMAPINFOHEADER{

  DWORD  biSize; // header size - must be at least 40

  LONG   biWidth;

  LONG   biHeight;

  WORD   biPlanes;

  WORD   biBitCount;

  DWORD  biCompression;

  DWORD  biSizeImage;

  LONG   biXPelsPerMeter;

  LONG   biYPelsPerMeter;

  DWORD  biClrUsed;

  DWORD  biClrImportant;

} BITMAPINFOHEADER, *PBITMAPINFOHEADER;

 

How many bytes does it take to store a bitmap file for a picture that has a size of 32*32 pixels and color depth is the 24 bits.

Assuming no RLE compression used you already know struct tagBITMAPINFOHEADER,

struct tagBITMAPINFOHEADER definitions given in the above. Show calculation. An answer without

steps is questionable.

 

 

 

 

 

 

 


Problem 4. Huffman encoding (15 points)  + 5 extra credit

 

  1. Given a text “aabbbaaccaaammk”, how many bits does the text take if characters are using ASCII character set (2 points)

 

 

 

  1. How many bits does it take if represented by Unicode character set (2 points)

 

 

 

  1. Please find out Huffman encoding for the characters appearing in the above text  (5 points)

 

 

 

 

 

 

 

 

 

 

 

 

  1. Please encode the text using the Huffman coding, showing the bit values.(2 points)

 

 

 

 

 

  1. Can A 0, B 1, C 10, D 11 be a Huffman coding for a certain text string? If yes, why, if not why? (4 points)

Huffman code

Character

0

A

1

B

10

C

11

D

 

  1. Extra credit question (What is the benefit of ASCII encode compared with Huffman coding )? (3 points)
  2. Is the compression ratio formula on book precise or not ? Why your answer? (2 points)

 

 

Problem 5. Gates & Combinatorial and sequential circuits (35 points)

 

Please draw a three input OR gate and show its truth table. (5 points)

 

 

 

 

 

 

 

Please draw two equivalence circuits for A(B+C) (5 points)

 

 

 

 

 

 

 

 

Please draw a 1 bit half adder (sum and carray out), show its truth table(5 points)

 

 

 

 

 

 

 

 

Please draw a 1 bit full adder ( 5 points)

 

 

 

 

 

 

 

 

 

Please use the above 1 bit full adder to concatenate a 4 bits full adder, (5 points) You can use a blackbox to replace the above 1 bit full adder in this small-scale integrated circuit.

 

 

 

 

 

 

 

 

Please draw a 4 to 1 multiplexer (5 points)

 

 

 

 

 

 

 

 

 

Please draw a S-R latch memory sequential circuit and briefly explain how to set it 0, how to set it 1 and how to maintain the current status.( 5 points)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


Problem 6 Code deciphering   5 points.

Code deciphering and result predicting. Attention please, we assume the following coding has no typos and runs perfectly. If you found any typos, just fix them reasonably. But I won’t expect you to find any typos.

 

     

 

int main()

{

      double *array2;

     

      array2=new double[10];

     

      *array2=10;

      *(array2+1)=100;

     

      for(int i=0;i<10;i++)

            cout<<*(array2+i)<<endl;

     

      cout<<array2<<endl;

      cout<<(array2+1)<<endl;

 

      delete []array2;

      return 0;

}

Notice that, each cout will print out something.

What will be printed out? If a printout is unpredictable, please indicate that using U, otherwise use the value it is supposed to print out.

 

 

 

 

 

 

What is the value difference between the last two cout statements.

 

 

 

 

 

 

 


Problem 7 Code authoring  (20 points)

 

Please write a program named as checkdiagnals which will accept an integer from command line, say 10 or 5, first, then create a N*N array of int datatype,.then your program will get input from keyboard for every element for the array. Then your program should be able to check whether the average (integer average) of the forward principle diagonal is the same as the average (integer average) of the backward principle diagonal. If they are equal, print out “yes”, otherwise, “no”. If yes, you need to perform another functionality to find out where in the array there are numbers equal to the average value. Then the program stops.

Requirements:

 

      1. N is not predictable when you design this piece of code, it could be 10 or 100 or even larger. Therefore if you use static array, it can cause a lost of at least 30% credit.

            2. Need to use OOD and OOP, not using it causes a lost of at least 30% credit.

            3. should get input from command line.

            4. int  atoi ( const char * string ) is one function you want to use

            5. Since this is a take-home version, you can consider to use a random function to replace manual typing-in the 2-d array. If you decide to use it, here is a link for it. http://employees.oneonta.edu/zhangs/csci201/randominteger.htm

Of course, if you want to manually type possibly 10000 numbers, you do not need it. But I suggest you spend 5 minutes to understand how to generate a random integer, it should be useful to knw.

 

 

 

 

Please use the above 1 bit full adder to concatenate a 4 bits full adder, (5 points) You can use a blackbox to replace the above 1 bit full adder in this small-scale integrated circuit.

 

 

 

 

Please draw a S-R latch memory sequential circuit and briefly explain how to set it 0, how to set it 1 and how to maintain the current status.( 5 points)