next_inactive up previous


CISC 105 sections 018-021 (Conrad) Midterm October 06, 2004

Name



Circle one:



Freshman Sophomore Junior Senior Other



Please circle your section number (refer to table below if you are not sure):



018 019 020 021



General Instructions

Multiple Choice

NOTE: You may want to work on the programming questions first--since they are worth more points, and will require more time--and come back to the multiple choice at the end.

The programming questions start with number 18.

  1. (2 pts) Which of the following tests whether x is odd?

    (a) if (x % 2 = 0) (b) if (x % 2 == 0) (c) if (x % 2 = 1)
    (d) if (x % 2 == 1) (e) if (x / 2 == 1)

  2. (2 pts) How many operands does a ternary operator have

    (a) none (b) one (c) two (d) three

  3. (2 pts) Which of the following is both a logical operator and a unary operator?

    (a) || (b) && (c) ++ (d) !  

  4. (2 pts) Each of the relational operators in C also happens to be this kind of operator:

    (a) unary (b) binary (c) ternary (d) assignment      

  5. (2 pts) What type of C variable is used with the converstion specifier %d?

    (a) printf (b) float (c) int (d) double      

  6. (2 pts) If you had the following lines of code in a C program:
           int score;
           FILE *studentFile;
           studentFile = fopen("students.dat","r");
    
    then which of the following is a correct line of code you might expect to find later in that same program?

    (a)
    fscanf("%d", &score);
    (b)
    fprintf(studentFile, "%d", score);
    (c)
    fscanf(studentFile,"%lf", &score);
    (d)
    fscanf(studentFile,"%d", &score);
    (e)
    fscanf(studentFile,"%d", score);

  7. (2 pts) Which of the following is a correct conversion specified for a variable of type double, with 5 spaces before the decimal point, and two afterwards?

    (a) %8.2lf (b) %5.2d (c) %7.2lf (d) %5.2lf (e) %8.2d  

  8. (2 pts) Which of the following tests whether x is equal to 10?
    (a) if (x == 10) (b) if (x = 10) (c) if (x?10:0)

  9. (2 pts) Which expression means the opposite of x<0

    (a) x>0 (b) x>=0 (c) x==0

  10. (2 pts) Given the number 11111 in binary, what is the equivalent in decimal?

    (a) 15 (b) 16 (c) 21 (d) 31 (e) 32

  11. (2 pts) Given the number 11111111 in binary, what is the equivalent in octal?

    (a) 777 (b) 377 (c) 773 (d) 333 (e) 8

  12. (2 pts) Which of the following assigns the value of 2 times y to x?

    (a)x == 2 * x; (b) 2 * y = x; (c) x = 2 x y; (d) x = 2 * y;    



  13. (2 pts) In the expression , which part is the mantissa?

    (a) (b) (c) (d)  

  14. (2 pts) The C statement x = x / 2; is equivalent to which of the follwoing statements?

    (a) x /= 2; (b) x += 2; (c) x = 2; (d) x = 2 / x ;  

  15. (2 pts) The C expression (25 % 8) evaluates to which of the following:

    (a) 0 (b) 1 (c) 2 (d) 3 (e) 4  

  16. (2 pts) The C expression ( 4 % 50 ) evaluates to which of the following:

    (a) 0 (b) 2 (c) 4 (d) 12 (e) 50  

  17. (2 pts) The C expression ( 50 / 4 ) evaluates to which of the following:

    (a) 12 (b) 12.5 (c) 13 (d) 50  

C Programming

(30 pts) Write a C program to solve the following problem.

(based in part on problem 3.10 in Tan and D'Orazio).

The period of one swing of a simple pendulum is given by:



where:
= period (seconds)
= length of pendulum (meters)
= gravitational acceleration (9.81 )

Write a complete C program that does all of the following steps. The program should be designed to be interactive; that is, to interact with a human user.

Be sure your program contains appropriate comments and all necessary statements to be a complete C program, ready to compile. Use ``constant macros'' the value of the gravitational acceleration, and for . You may use the value . You may use the sqrt() function from the math library. Be sure to add the necessary statement at the top of your program that is needed when using the math library.

Extra space in case you need it.

(10 pts) Write a C function (just a C function, not a complete program) called maxOfThree that takes three integers as parameters, and returns the maximum of those three integers.

Optional: If it will help you, you may write a function maxOfTwo first, and then write maxOfThree in terms of the maxOfTwo function. However, that is not required, nor will it earn you extra credit. It is just an option that you have.

Unix Commands

Suppose you have a C program in a file named lab02.c
What Unix command do you enter to perform each of the following operations?

  1. (2 pts) Enter a text editor to make changes to the program



  2. (2 pts) Display the contents of the source code on your screen.



  3. (2 pts) Compile the program



  4. (2 pts) Copy the program to a new file called lab02a.c.



Number Conversions

(4 pts) Convert 357 from decimal to binary




















(4 pts) Convert 1010 1100 1010 1011 0100 1101 1010 1101 from hexadecimal to binary








What is the output of each of the segments of C code below? Assume that each one occurs in the context of the main function of a valid, complete C program.

Place your answer in the grid provided, one character or space per box. You might not need all the spaces in the grid provided.

If you make a mistake, and want to start over, there are extra grids on the next page; just cross out the grid above, and indicate that your answer is on the next page.

  1. (5 pts)

    /* q1.c an example program that lacks comments */
    #include <stdio.h>
    int main (void)
    {
       int a, b, c, d, e;
       a = 5;
       b = 7;
       c = a * 3 - 4 * b;
       d = b / 2;
       e = a++; 
    
       printf("a=%d\n", a);
       printf("b=%d\n", b);
       printf("c=%d\n", c);
       printf("d=%d\n", d);
       printf("e=%d\n", e);
    
    }
    

    unit=18pt

  2. (5 pts)

    /* q2.c Another program with no comments */
    #include <stdio.h>
    int main (void)
    {
      int count;
      count = 0;
      while (count <= 2)
      {
        printf("*");
        count++;
      }
      printf("\n");
      printf("Done\n");
      return 0;
    }
    

    unit=18pt

Extra grids in case you need them for answering ``what is the output'' type problems. Indicate which problem you are answering.

unit=18pt



unit=18pt

End of Exam. Total Points: 100

About this document ...

This document was generated using the LaTeX2HTML translator Version 2002-2 (1.70)

Copyright © 1993, 1994, 1995, 1996, Nikos Drakos, Computer Based Learning Unit, University of Leeds.
Copyright © 1997, 1998, 1999, Ross Moore, Mathematics Department, Macquarie University, Sydney.

The command line arguments were:
latex2html -split 0 E01_F04.tex

The translation was initiated by Phillip Conrad on 2004-10-14


next_inactive up previous
Phillip Conrad 2004-10-14