Department of Computer Science

University of Illinois at Urbana-Champaign

Computer Science 101: Mid Term Exam II (60 minutes)

 


Name:                                                                         NetID:
 

Lab Section:                                                               Date: April 3rd, 2008

 


No questions will be answered during this examination.  If you do not understand a question, read it again.  If you still do not understand it, make reasonable assumptions and write them down. (Points will be deducted if unreasonable assumptions are made.)

DO NOT CHEAT: Cheating includes not only copying from another person but also allowing someone to copy from you.  Anyone who copies or allows someone to copy will receive a score of zero.  So be defensive and protect your work.

This examination contains 10 pages including this page. Check that your copy is complete, and ask for a replacement if it is not. Do all your work on these pages. For your own protection, in case pages come apart, write your NetID at the TOP of each page before beginning work.

The number of points for a question is roughly proportional to the amount of time you may need for it. Don’t spend too much time on any one question.

Do not forget to sign the attendance list. If your exam is misplaced and you did not sign the attendance list then you will receive a zero score for the exam.

You may not use any electronic devices, book, notes or other references during this examination.

DO NOT WRITE IN THIS SPACE

Section

Possible Score

Deduction

Grader

1

6

 

 

2

6

 

 

3

6

 

 

4

6

 

 

5

6

 

 

6

5

 

 

7

5

 

 

8

10

 

 

9

8

 

 

10

8

 

 

11

8

 

 

12

9

 

 

13

8

 

 

14

6

 

 

15

5

 

 

16

10

 

 

17

13

 

 

Total

125

 

 

 

 

Exam Scoreà

 

A

  1. Assume that in your home directory there is a directory named "Dir1" and inside "Dir1" there is a directory named "Dir2".

 

Write a single Unix command to make "Dir2" your current directory. This command should work regardless of what the current directory is at the time you are typing it at the Unix prompt.

 

 

_______________________________________________________________________

 

 

 

 

  1. Write a single Unix command that would display the name of your current (working) directory when typed at the Unix terminal.  

 

 

______________________________________________________________________

 

 

 

 

  1. Assume your current directory has a subdirectory called "Sdir".  Write a single Unix command to list the names of all the files located in "Sdir" without changing directory.

 

 

______________________________________________________________________

 

 

 

 

 

 

  1. Circle the only true statement about the Unix command "mv" listed below.

(Circle only one choice.)

 

a)         It can be used to copy a file without deleting the original version.



b)          It cannot be used to move files from one directory into another.



c)         It can be used to rename a file.


 

d)         It launches a program called "my voicemail".

 

 

 

 

  1. The following program compiles and runs without errors. Write the output produced by the following program.

 

#include <stdio.h>

#define LARGE 20

#define SMALL 10

 

void main(void)

{

   int value = 7;

   if (value > LARGE)

       printf("large\n");

   if (value > SMALL)

         printf("med\n");

   else

         printf("small\n");

}

 

 

______________________________________________________________________

 

 

 

 

  1. Write the correct results of evaluating the following C language expressions:

 

a)      5 / 3     =   _____________________
            

b)      5 / 6     =   _____________________

c)      5 % 3     =   _____________________

             

d)     3 % 5     =   _____________________

 

e)      6 + 3 / 2 =   _____________________

 

 

 

 

  1. Complete the following line of C code to declare a 3x3 matrix named "wow" so that the matrix holds the following values at each position:

 

 

int wow[ __ ] [ ___ ] = { ___________________________________________________ };

 

 

 

 

  1. Consider the following C program:

#include <stdio.h>

 

void main(void)

{

     int x;

     scanf("%i", &x);

     switch (x/32)

{

          case 0:

               printf("Too cold!\n");

              break;

          case 3:

              printf("Too hot!\n");

              break;

          case 2:
          case 1:

              printf("Just right!\n");

              break;

          default:

              printf("Weird weather!\n");

              break;

     }

    

}

 

Fill in the blanks below to re-implement the program using if statements. After you enter your code below the program should be equivalent to the program above.

#include <stdio.h>

 

void main(void)

{

     int x;

     scanf("%i", &x);

 

     if (_____________________________________)

printf("Too cold!\n");

     else if (____________________________________________) 

               printf("Too hot!\n");

          else if (_____________________________________________) 

                    printf("Just right!\n");

               else

                    printf("Weird weather!\n");

}

 

 

  1. For each set of variable values given below, write the output that the following code fragment would produce if the fragment was included in a complete C program and compiled and run without errors.

 

if (a < b)

if (c < d)

      printf("A");

   else

if (a <= c && a != d)