CSC 101 Programming Assignment 2: Shape Containment
DUE: On or before 11:59:59PM, April 18, 2011 (Monday)

Overview

For this assignment, you are writing a simple C program that computes if a shape fits inside another shape. Writing the program requires that you understand the following concepts:

• if-else statements
• floating-point input
• functions

Program Specification

You will write a program that prompts a user to define a sphere and a box. The program will check to make sure the inputs are reasonable (non-zero and positive) and, if any are not it will report an error and terminate. If all inputs are reasonable, the program will then determine which shape, if any, fits into the other and report the results. The user interface must match the provided sample runs exactly to be considered correct.  You will have to develop your own test cases.     A box can be contained by a sphere if the box completely fits inside the sphere without touching the sphere surface.  A sphere can be contained by a box if the sphere does not touch any edges of the box.  In order to determine if a sphere contains a box, you must calculate the longest diagonal of the box when determining whether or not it will fit inside the sphere.  You can assume the shapes share the same center point. 
●	NOTE: it is possible to specify a sphere and a box where neither is able to fully contain the other. 

Sample Run 1: 
$ ./a.out
Welcome to the Shape Fit tool!

Enter the dimensions of a box
Length: 1.2
Width : 1.3
Height: 1.5

Enter the radius of a sphere
Radius: 2.1

The sphere can contain the box!
$ 
  Sample Run 2: 
$ ./a.out
Welcome to the Shape Fit tool!

Enter the dimensions of a box
Length: 3.4 
Width : 4.2
Height: 2.3

Enter the radius of a sphere
Radius: 1.1

The box can contain the sphere!
$ 

 Sample Run 3: 
$ ./a.out
Welcome to the Shape Fit tool!

Enter the dimensions of a box
Length: 12.2
Width : 3.3
Height: 2.6

Enter the radius of a sphere
Radius: 5.4

Neither shape can contain the other!
$ 

 Sample Run 4: 
$ ./a.out
Welcome to the Shape Fit tool!

Enter the dimensions of a box
Length: -1.2

Invalid dimension: exiting
$ 

Program Structure

You should implement and use the following functions in your program:

●	can_sphere_contain_box
●	can_box_contain_sphere

The parameters and return values of these functions are up to you.  You may implement additional functions if you like.

Program Development and Testing

A sample binary is provided in:

●	/home/jseng/www/Spring11/program2/shapefit

The binary will be the benchmark program you can use to see what the correct answers are and what the output looks like.  It is often called an "oracle" to testers.

Other Requirements

Compile using the command on vogon (or use your make file and the '-o' switch to name it appropriately, as we have been doing):

●	gcc -ansi -pedantic -Wall -Werror -lm shapefit.c

Collaboration

NO collaboration is allowed on this assignment. Everyone must do their own individual work.

Program Handin Procedure

For this programming assignment, you will use the UNIX handin command on vogon. You run handin from the vogon command line as follows:

      handin  instructor  101_prog2 shapefit.c

where instructor is the UNIX ID of your 101 instructor this quarter:

Instructor	Username	
Clark Turner	csturner	
David Janzen	djanzen	
Gene Fisher	gfisher	
John Seng	jseng	

Run the handin command from the vogon directory where your copy of shapefit.c is stored.

You can resubmit your file as many times as you like, up to the submission deadline. Each new submission completely replaces the previously submitted file(s). If you follow an incremental development strategy, you can submit as many partially-working versions as you like, as each step is completed.

Survey
Track the amount of time that you spend working on this project.  After you hand in your project, complete the survey at the following link: http://www.surveymonkey.com/s/DBTXJHH where you will report your time spent.  Your answers on this survey will not affect your grade.