COMP1511 17s1 Introduction to Programming
  1. What is a bit?

  2. What is a byte?

  3. How many distinct values can be represented with a single byte?

  4. Give a representation scheme that could be used to encode a subset of integers in 4 bits.

  5. What is a file?

  6. What is a directory?

  7. Give examples of information that is commonly stored inside the bytes of a file, and specify an encoding that might be used for the byte values.

  8. Which of the following are valid variable names in C?

    If they are valid, would they be a good name?

    • THX1138

    • 2for1

    • mrBean

    • my space

    • event_counter

    • ^oo^

    • _MEMLIMIT

    • return

  9. C is a typed language. What does this mean? Why is this useful?

  10. Write a program rectangle_area.c that reads in 2 integers which are the side-length of a rectangle, and then prints the area of the rectangle.

    For example:

    ./rectangle_area
    Please enter rectangle length: 3
    Please enter rectangle width: 5
    Area = 15
    ./rectangle_area
    Please enter rectangle length: 42
    Please enter rectangle width: 42
    Area = 1764
    

  11. Modify rectangle_area.c so that it reads floating-point (decimal) numbers and prints the area as a floating-point number.
    ./rectangle_area
    Please enter rectangle length: 3.14159
    Please enter rectangle width: 2.71828
    Area = 8.539721
    
    Note carefully the changes.

  12. What is the syntax of C if statements? What is the role of if statements in programs?

    Revision questions

    The remaining tutorial questions are primarily intended for revision - either this week or later in session.

    Your tutor may still choose to cover some of the questions time permitting.

  13. Write a program pass_fail.c that reads in an integer and prints out "PASS" if the integer is between 50 and 100 inclusive and fail if it is between 49 and 0, inclusive. It should print out ERROR if the number is less than 0, more than 100, or if the user does not enter a number. For example:
    ./pass_fail
    Please enter your mark: 42
    FAIL
    ./pass_fail
    Please enter your mark: 50
    PASS
    ./pass_fail
    Please enter your mark: 256
    ERROR
    

  14. Write a program that reads in an integer and determines if it is even or not. If the number is negative, print "NEGATIVE" instead. For example:
    ./even_or_odd
    Please enter a number: 42
    EVEN
    ./even_or_odd
    Please enter a number: 111
    ODD
    ./even_or_odd
    Please enter a number: -2
    NEGATIVE