CSCI 255 Homework 10

This assignment is due in class or to my office assistant in RRO 215 by 9:30 AM on 20 November.

Use the following structure and enumerated type C declarations in this assignment.

typedef struct {
  int lo ;
  int hi ;
} range ;

typedef enum { BELOW, INSIDE, ABOVE } position ;

Question 1

Write small sections of code to perform the following tasks.

  1. Declare i and j to be integer variables.
  2. Declare R to be a variable of type range.
  3. Declare P to be a variable of type position.
  4. Write statement(s) to initialize R.
  5. Write statement(s) to initialize P.
  6. Write statement(s) that set i to the value of field lo of R.
  7. Write statement(s) that set j to 1, if P has the value INSIDE.
  8. Write statement(s) that increase field hi of R by 3.
  9. Declare pR to be a pointer to a variable of type range.
  10. Set pR to be a pointer to R.

Question 2

Write a function that receives a variable of type position and returns an integer. The function should return 0, if it is passed INSIDE, and should return 1, otherwise.

Question 3

Write a function that is passed a pointer to a variable of type range. The function should set both fields of the referenced range type to 255.