Department of Computer Science

University of Illinois at Urbana-Champaign

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

 


Name:                                                                         NetID:
 

Lab Section:                                                                Date: November 2, 2006

 


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.

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

 

This examination contains 13 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. 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 and to write your signature on the line below:

 

_______________________________________________________________________
(If your exam is misplaced and you did not sign the attendance list then you will receive a zero score for the exam.)

DO NOT WRITE IN THIS SPACE

Section

Possible Score

Missed Points

Grader

1

8

 

 

2

4

 

 

3

4

 

 

4

8

 

 

5

6

 

 

6

6

 

 

7

10

 

 

8

9

 

 

9

10

 

 

10

10

 

 

11

6

 

 

12

4

 

 

13

4

 

 

14

8

 

 

15

9

 

 

16

8

 

 

17

11

 

 

Total

125

 

 

A

 

 

 

 

1.      Assume that you are in your home directory. You have the following subdirectories:

 

subdirectory:   files in it

          -------------   ------------

          source          intro.c    test.c    test.m

     mp1             find_h.m   main.m

mp2             1cs101.c   Xcs121.c  cs.c   input.dat


a
) Write a single UNIX command to create another subdirectory with the name “backup”.

 

 

_________________mkdir    backup ___or ___mkdir     ~/backup_________or ______ numerous other solutions_____________

 

b) Write a single UNIX command to make “backup” your current directory.

 

 

_________________cd   backup_____ or _________cd   ~/backup________or______ numerous other solutions____________

 

c) Assume that you are in your “backup” directory. Write a single UNIX command to copy all the files in “source” subdirectory to “backup” directory.   (Hint:  You may use the wildcard "*").

 

 

_________________cp  ~/source/*   .    _____or ____cp   ../source/*   .  ___or ___numerous other solutions _____________


d) Assume that you are in your home directory. Write a single UNIX command to move all     files in the mp2 directory that have an extension (suffix) of  .c into the source directory.

  

  ________mv  mp2/*.c    source________or ____numerous other solutions___________________________________________________

  

 

2.      Choose the single correct UNIX command to rename a file name from “file1” to “file2”:

a)       cp file1 file2
b)       cp file2 file1
c)       rn file1 file2
d)       rn file2 file1
e)       mv file1 file2
f)         mv file2 file1

Correct answer: _____e____________________
 
 
 
 
 
3.      Circle the correct commands you would type at the UNIX prompt to compile and run the C program located in the file lab9.c . The program uses the math library. Circle only one choice.

a)         gcc lab9.c –lm
./a.out



b)        gcc lab9.c –include <math.h>
a.out



c)         gcc lab9.c –o math 
.\math



d)        gcc a.out -lm
lab9
 
 
 
 
 
 

 

4.      Fill in the blanks to correctly print the values of the variables w, x, y and the array z (not necessarily in this order).
 

   #include <stdio.h>

 

        void main(void)

   {
       int w = 4;

           float x = 2.345;

           char y = ‘a’;

           char z[] = “cat”;


      printf(“%c \n”, _______y_________);           



      printf(“%d \n”, _______w_________);           



      printf(“%s \n”, ______z__________);


 printf(“%f \n”, _______x_________);

    }

5.      Write the output the following programs produce.

     a)      
         
#include <stdio.h>


               void main(void){
                 int  num = 3, i = 0 , count = 0;

   while ( i < num )

 {

count++;

++i;

 }
  printf(“ %i ”, count);
}

_________________3____________________________

 

    b)
          #include <stdio.h>


              void main(void){
                 int num = 2, i = 0, count = 0;

  for ( i = 0; i < num; ++i )

  {

count++;

  }
  printf(“ %i ”, count);
}

 

_________________2____________________________


        c)    
              
#include <stdio.h>

           void main(void){
                 int num = 0, i = 0, count = 0;

 

   do

 {

 count++;

 ++i<