Homework 6   
Due Date
Monday, May 5
Assignment

  1. [10 points] Do 7.9 from the textbook.

  2. [10 points] Do 7.10 from the textbook.

  3. [15 points]

    Write a function called circumference that calculates the circumference of a circle. You must pass the radius parameter by value, and a circumference parameter by reference. Do not use a return statement.

    a. Write the function prototype.

    b. Write a sample main() function.

    c. Write the actual function.

  4. [15 points]

    Determine the output of the following program:

    #include <stdio.h>
    
    void super_swap (int *, int *, int *);
    
    main () {
    	int a = 1;
       	int b = 2;
    int c = 3;
       	printf ("%d %d %d\n", a,b,c);
       	super_swap (&a, &b, &c);
       	printf ("%d %d %d", a,b,c);
       	getchar();
    }
    
    void super_swap (int *num1, int *num2, int *num3) {
    int temp1 = *num1;
    *num1 = *num2;
    *num2 = *num3;
    *num3 = temp1;
    }
    

  5. [25 points]

    This question asks you to create an array for tracking credit card purchases.

    A. Create a structure, called creditcard that contains three members: credit_card_number (integer data type), authorization_number (integer data type) and amount_to_charge (float data type):

    B. Create an array called records, which contains 50 creditcard structures.

    C. Using three lines of code, initialize the data for records[25] to: credit_card_number = 4111111, authorization_number=56132 and amount_to_charge = 19.95.

    D. Create a pointer to creditcard and call it cardPtr. Initialize cardPtr to point to the zeroeth element of the records array.

    E. Using cardPtr defined above, initialize the data for records[0] to: credit_card_number=999121, authorization_number = 89532 and amount_to_charge = 99.95.

    F. Using cardPtr, print out all data contained in records[25].

  6. [10 points] Given the following array:
    int numbers[5] = {2,4,6,8,10};
    

    A. Write a pointer to integer, called numPointer and initialize it to point to the zeroeth element of the numbers array.

    B. Assuming that numbers[0] is located at address 1,000 and that integers are 4 byte long, what is the value of numPointer?

    C. What is the value of numPointer+2?

    D. What is the value of *(numPointer+2)?

  7. [15 points] From the Text, Exercise 7.17