10.10.2005

a dollar to get her integers

Current Mood: rested
Current Music: "Trashed and Scattered" by Avenged Sevenfold

I'm seriously on the brink of a real update, I just wanted to share this. It's my homework for CS 158, my first course in C programming. It's a very simple program that asks for the sides of a triangle (in inches) and calculates the hypotenuse (in centimeters), but I'm damn proud of it.


**********************************************
Homework: 10/10
**********************************************
Comments:
- Complete header
- Correct code
- Correct output
- Good job
**********************************************
Announcements:

DO NOT RESPOND TO THIS EMAIL! I can not change your grade!
All grade appeals must be made in writing and presented in
person to either Bill Crum or Bill White during their office hours.

Before turning in your homework please make sure
that you program complies with the course coding standards:

http://www.cs.purdue.edu/homes/wcrum/cs158/fall05/standards.htm

Failure to to follow these standards will result in escalating
point deductions from your labs, homeworks, and projects.


**********************************************

**********************************************
*
*
* rgarwood
*
*
**********************************************
* CS 158 - hw5
* Output file for rgarwood
* Div/Sec div09sec01
* Project: hw5
* Printed on Fri Sep 30 10:26:13 EST 2005
**********************************************
* Compile time errors (if any appear below
**********************************************
**********************************************
* File listing
**********************************************
/************************************************************
*
* Programmers and Purdue Email Adresses:
* 1. Ryan Garwood rgarwood@purdue.edu
* 2.
* 3.
*
* Homework # 05
*
* Academic Integrity Statement:
*
* We have not used source code obtained from
* any other unauthorized source, either modified
* or unmodified. Neither have we provided access
* to our code to another. The project we are submitting
* is our own original work.
*
* Lab Division and Section: 09/01
*
* Program Description: Given user input sides of a triangle, this
* function calculates the hypotenuse in centimeters.
*
*************************************************************/


#include
#include

#define METRIC_CONVERSION 2.540

void getSide(float*, float*);
void toCm(float*, float*, float*);
float calcHypo(float, float);
void displayResults(float);

int main()
{
float sideA; //THE FIRST USER INPUT FOR SIDE A OF THE TRIANGLE
float sideB; //THE SECOND USER INPUT FOR SIDE B OF THE TRIANGLE
float hypotenuse; //THE HYPOTENUSE OF THE TRIANGLE

getSide(&sideA, &sideB);

hypotenuse = calcHypo(sideA, sideB);

toCm(&sideA, &sideB, &hypotenuse);

displayResults(hypotenuse);

return(0);
}

/*****************************************************************
*
* Function Information
*
* Name of Function: getSide
*
* Programmer's Name: Ryan Garwood
*
* Function Return Type: void
*
* Parameters (list and comment one per line):
* sideA // The first side of the triangle to be stored
* sideB // The second side of the triangle to be stored
*
* Function Description: This function accepts user input for
* a side of the triangle and stores the value using pass by address
*
*****************************************************************/

void getSide(float *sideA, float *sideB)
{

printf("Enter the length of a side (inches): ");
scanf("%f", sideA);

printf("Enter the lenght of a side (inches): ");
scanf("%f", sideB);

return;
}

/****************************************************************
*
* Function Information
*
* Name of Function: toCm
*
* Programmer's Name: Ryan Garwood
*
* Function Return Type: void
*
* Parameters (list and comment one per line):
* sideA //Value of side A to be converted to metric and stored in main
* sideB //Value of side B to be converted to metric and stored in main
* hypotenuse //Value of the hypotenuse to be converted, stored in main
*
* Function Description: This program converts the triangle values to
* metric and stores them in main with pass by address.
*
****************************************************************/

void toCm(float *sideA, float *sideB, float *hypotenuse)
{
*sideA = *sideA * METRIC_CONVERSION;
*sideB = *sideB * METRIC_CONVERSION;
*hypotenuse = *hypotenuse * METRIC_CONVERSION;

return;
}

/***************************************************************
*
* Function Information
*
* Name of Function: calcHypo
*
* Programmer's Name: Ryan Garwood
*
* Function Return Type: float
*
* Parameters (list and comment one per line):
* leg1 //THE FIRST LEG OF THE TRIANGLE
* leg2 //THE SECOND LEG OF THE TRIANGLE
*
* Function Description: Basic math fucntion squares and adds both
* legs of the triangle, then takes the square root, to calculate
* the hypotenuse
*
****************************************************************/

float calcHypo(float leg1, float leg2)
{
float Hypo; //THE HYPOTENUSE TO BE CALCULATED

Hypo = (pow(leg1, 2)) + (pow(leg2, 2));
Hypo = sqrt(Hypo);
return(Hypo);
}

/****************************************************************
*
* Function Information
*
* Name of Function: displayResults
*
* Programmer's Name: Ryan Garwood
*
* Function Return Type: float
*
* Parameters (list and comment one per line):
* x //THE VARIABLE HOLDING THE HYPOTENUSE TO BE PRINTED
*
* Function Description: This function displays the calculated
* hypotenuse
*
****************************************************************/

void displayResults(float x)
{
printf("The length of the hypotenuse is: %f\n", x);

return;
}
**********************************************
* .h file follows
**********************************************
**********************************************
* Output
**********************************************
*
Enter the length of a side (inches): Enter the lenght of a side (inches): The
length of the hypotenuse is: 1.414211
*
**********************************************
*
Enter the length of a side (inches): Enter the lenght of a side (inches): The
length of the hypotenuse is: 12.700000
*
**********************************************
*
Enter the length of a side (inches): Enter the lenght of a side (inches): The
length of the hypotenuse is: 22.625143
*
**********************************************
**********************************************

2 comments:

  1. You realize you have two Bills? Kind of like how in Office Space Peter had two Bobs. I'm not implying anything, I'm just saying.

    Also, you should have totally gone for Shastity's integers

    ReplyDelete
  2. I mean, there are two Darren Stevens, right? Dick York and Dick Sargeant. Yeah, right, as if we wouldn't notice. Oh hold on: Dick York, Dick Sergeant, Sergeant York... Wow, that's weird.

    ReplyDelete