[Previous Homework] [Next Homework]

hw13 - Structures & Typedef

Using the boxStruct.c code as a guide, create a program that calculates the volume of a can in cubic inches:

  • Use struct and typedef to create a new structure data type named cylinder
    • The structure should contain members for the diameter and height of a cylinder

  • Create a function name calculate_volume() that does the following:
    • Takes in one parameter of type cylinder
    • Calculates the volume of the cylinder using the data structure that was passed in
    • Returns the volume of the cylinder

  • In main()
    • Declare a variable of type cylinder
    • Assigns values to the members of the cylinder structure. The values may be hard coded.
    • Calls the calculate_volume() function
    • Prints out the values in the cylinder structure and the volume that was calculated.

From Linux on the GL machine:
  • Write a C program (see below) and save it in a file called cylinder.c in your ./cmsc104/hw13 directory

  • Compile the program:
    gcc -o cylinder cylinder.c

  • Run the program to make sure it works:
    ./cylinder

  • Use the SUBMIT utility turn in the homework.
    submit cs104_grasso hw13 cylinder.c cylinder


Make sure that you follow all the coding standards