|
| 1 | +/* Calculate Roof Lengths and Angles*/ |
| 2 | + |
| 3 | +/* Joe O'Regan */ |
| 4 | +/* 15-11-2015 */ |
| 5 | + |
| 6 | +#include<stdio.h> |
| 7 | +#include<math.h> |
| 8 | + |
| 9 | +#define PI 3.14159265 |
| 10 | +#define CTD (PI/180) // CTD - Convert To Degrees |
| 11 | + |
| 12 | +// function prototypes |
| 13 | +float roofHeight1(); // pow, sqrt |
| 14 | +float roofSlope(float x,float y); // atan |
| 15 | +float chimney(); // cos |
| 16 | +float chimHeight(float x, float y); // sin |
| 17 | +float roofHeight2(); // tan |
| 18 | + |
| 19 | +// Global Variables |
| 20 | +float roofWidth=0; // total width of building |
| 21 | +float angle=0; // angle of roof |
| 22 | +float roofHeight=0; // height of roof |
| 23 | +float convert = PI / 180; |
| 24 | + |
| 25 | +int main() |
| 26 | +{ |
| 27 | + int selection=0; // menu option |
| 28 | + |
| 29 | + // Option Menu |
| 30 | + do |
| 31 | + { |
| 32 | + printf("*************************************************"); |
| 33 | + printf("\n*\tRoof Lengths & Angles (Meters)\t\t*\n"); |
| 34 | + printf("*************************************************\n\n"); |
| 35 | + printf("1. Calculate Height Of Roof From Slope Length & Total Width\n"); |
| 36 | + printf("2. Calculate Chimney Exit Hole Slope Location\n"); |
| 37 | + printf("3. Calculate Height Of Roof From Angle & Total Width\n"); |
| 38 | + printf("4. Exit\n"); |
| 39 | + printf("\nEnter Selection: "); |
| 40 | + scanf("%d",&selection); |
| 41 | + |
| 42 | + switch(selection) |
| 43 | + { |
| 44 | + case 1: printf("Option 1:\n\n"); |
| 45 | + printf("Get Height Of Roof From Slope Length & Total Width\n\n"); |
| 46 | + roofHeight1(); |
| 47 | + break; |
| 48 | + |
| 49 | + case 2: printf("Option 2:\n\n"); |
| 50 | + printf("Calculate Chimney Exit Hole Through Slope Of Roof \nGiven Dimensions Through Ceiling\n\n"); |
| 51 | + chimney(); |
| 52 | + break; |
| 53 | + |
| 54 | + case 3: printf("Option 3:\n\n"); |
| 55 | + printf("Calculate Height Of Roof Given Angle & Total Width\n\n"); |
| 56 | + roofHeight2(); |
| 57 | + break; |
| 58 | + } |
| 59 | + }while(selection != 4); |
| 60 | + |
| 61 | + getch (); |
| 62 | + return (0); |
| 63 | +} |
| 64 | +/**************************************************************************************************** |
| 65 | +* Function 1. Get Height (Sqrt & Pow) * |
| 66 | +****************************************************************************************************/ |
| 67 | + |
| 68 | + float roofHeight1() // Calculate: Height of roof, from slope length, and total width of roof |
| 69 | + { |
| 70 | + float slope,halfWidth; |
| 71 | + |
| 72 | + printf("Enter Slope Length Of Roof (Meters): "); |
| 73 | + scanf("%f", &slope); // Input: Length of Sloped Side of Roof |
| 74 | + printf("Enter Total Width Of Roof (Meters): "); |
| 75 | + scanf("%f", &roofWidth); // Input: Total Width of Roof |
| 76 | + |
| 77 | + halfWidth=roofWidth/2; // Divide total roof width by 2 (make right angle) |
| 78 | + roofHeight=sqrt(pow(slope,2) - pow(halfWidth,2)); // Formula: opposite equals square root of (hypotenuse squared, minus adjacent squared) |
| 79 | + // Roof height = square root of (slope squared - half total width squared) |
| 80 | + printf("\nGiven The Slope Length: %.2fm And Width: %.2fm Of A Roof\n",slope,roofWidth); |
| 81 | + printf("1. Roof Height Is %.2fm \n", roofHeight); // Output: Height of roof (roofHeight) |
| 82 | + printf("2. Roof Center Is %.2fm\n", halfWidth); // Output: Center of roof (halfWidth) |
| 83 | + printf("3. "); // Output: Angle of roof (angle) |
| 84 | + |
| 85 | + roofSlope(halfWidth,roofHeight); |
| 86 | +} |
| 87 | + |
| 88 | +/**************************************************************************************************** |
| 89 | +* Funtion 2. Get Angle (Atan) * |
| 90 | +****************************************************************************************************/ |
| 91 | + |
| 92 | +float roofSlope(float adjacent,float opposite) // Adjacent = half of roof width, Opposite = roof height |
| 93 | +{ |
| 94 | + angle = atan (opposite / adjacent) * 180 / PI; // angle = inverse tan of (opposite divided by adjacent) - converted from radians to degrees |
| 95 | + printf ("Slope Angle Is %.2f Degrees\n", angle ); // Output: Angle of roof (angle) |
| 96 | +} |
| 97 | + |
| 98 | +/**************************************************************************************************** |
| 99 | +* Function 3. Chimney (Cos) * |
| 100 | +****************************************************************************************************/ |
| 101 | + |
| 102 | +float chimney() // Calculate: Points chimney will exit sloped part of roof, from ceiling measurements |
| 103 | +{ |
| 104 | + float nearSlopeExit, farSlopeExit, distanceAngleToChimney, chimneyWidth; |
| 105 | + |
| 106 | + printf("Enter Distance From Angle to Chimney Edge at Ceiling Height: "); |
| 107 | + scanf("%f",&distanceAngleToChimney); // Input: distance at ceiling height from angle of roof to near chimney edge |
| 108 | + printf("Enter Chimney Width: "); |
| 109 | + scanf("%f",&chimneyWidth); // Input: The width of the chimney |
| 110 | + printf("Enter Angle Of Roof: "); |
| 111 | + scanf("%f",&angle); // Input: The angle of the roof |
| 112 | + |
| 113 | + printf("\n1. Distance From Angle To:"); |
| 114 | + |
| 115 | + nearSlopeExit = distanceAngleToChimney / (cos(angle * CTD)); // Calculate: Distance to near edge of chimney, from angle, on sloped edge |
| 116 | + printf("\n\tA. Near Edge Of Chimney On Slope: %.2fm",nearSlopeExit); // Output: near point where chimney makes contact with slope of roof (distance from ceiling) |
| 117 | + |
| 118 | + farSlopeExit = (distanceAngleToChimney + chimneyWidth) / cos(angle * CTD); // Calculate: Distance to far edge of chimney, from angle, on sloped edge (add chimney width) |
| 119 | + printf("\n\tB. Far Edge Of Chimney On Slope: %.2fm\n",farSlopeExit); // Output: far point where chimney makes contact with slope of roof (distance from ceiling) |
| 120 | + |
| 121 | + printf("2. Height Of Chimney: \n\tA. Nearest To Angle: "); |
| 122 | + chimHeight(angle,nearSlopeExit); // Output: Near (to angle) height of chimney, from ceiling to slope part of roof |
| 123 | + printf("\tB. Furthest From Angle: "); |
| 124 | + chimHeight(angle,farSlopeExit); // Output: Far (from angle) height of chimney, from ceiling to slope part of roof |
| 125 | +} |
| 126 | + |
| 127 | +/**************************************************************************************************** |
| 128 | +* Function 4. Chimney Heights (Sin) * |
| 129 | +****************************************************************************************************/ |
| 130 | + |
| 131 | +float chimHeight(float angle, float hypotenuse) // Hypotenuse = sloped part of roof |
| 132 | +{ // Calculate: Height of chimney from ceiling to sloped part of roof |
| 133 | + float opposite = hypotenuse * sin(angle * CTD); // Opposite = side of triangle opposite to sin angle (or height for chimney from ceiling to slope) |
| 134 | + printf("%.2f\n",opposite); // Ouput: chimney height, from ceiling to slope |
| 135 | +} |
| 136 | + |
| 137 | +/**************************************************************************************************** |
| 138 | +* Function 5. Roof Height (Tan) * |
| 139 | +****************************************************************************************************/ |
| 140 | + |
| 141 | +float roofHeight2() // Calculate: Height of roof, from roof angle, and width of roof |
| 142 | +{ |
| 143 | + printf("Enter Angle Of Roof: "); |
| 144 | + scanf("%f",&angle); // Input: Roof angle |
| 145 | + printf("Enter Roof Total Width: "); |
| 146 | + scanf("%f",&roofWidth); // Input: Total width of roof |
| 147 | + |
| 148 | + roofHeight = (roofWidth/2) * tan (angle * CTD ); // Calculate: Height is equal to half total width, multiplied by, tan of angle |
| 149 | + printf("1. Height Of Roof Is: %.2f meters\n\n",roofHeight); // Output: Height of roof |
| 150 | +} |
| 151 | + |
0 commit comments