Added Lab 4 Files
++ Lab 4 Stuff ++ Copy of Console_IO_UTILS ++ Copy of Standard Constants
This commit is contained in:
parent
5e7fb8d089
commit
7900abc317
4 changed files with 1162 additions and 0 deletions
235
Lab04/Lab_4_prog_provided.c
Normal file
235
Lab04/Lab_4_prog_provided.c
Normal file
|
|
@ -0,0 +1,235 @@
|
|||
// header files
|
||||
#include "Console_IO_Utility.h"
|
||||
#include <math.h> // for trig functions
|
||||
|
||||
// global constants
|
||||
const int DEGREES_IN_TRIANGLE = 180;
|
||||
const double ANGEL_C_DEG = 90;
|
||||
const double CONSTANT_PI = 3.141592654;
|
||||
|
||||
|
||||
const int TWO_ENDLINES = 2;
|
||||
const int TABLE_WIDTH = 35;
|
||||
const int DATA_NAME_WIDTH = 16;
|
||||
const int UNIT_WIDTH = 7;
|
||||
const int VALUE_WIDTH = 8;
|
||||
|
||||
const char TOP_LINE[] = "===================================";
|
||||
const char THICK_LINE_DIVIDER[] = "|=================================|";
|
||||
const char THIN_LINE_DIVIDER[] = "|---------------------------------|";
|
||||
const char PIPE_SPACE[] = "| ";
|
||||
const char SPACE_PIPE[] = " |";
|
||||
|
||||
// prototypes
|
||||
// none
|
||||
|
||||
// main program
|
||||
int main()
|
||||
{
|
||||
// initialize function/variables
|
||||
|
||||
// initialize variables
|
||||
double sideA, sideB, sideC;
|
||||
double sqSideA, sqSideB, sqSideC;
|
||||
double cosAngleA, angleA_Rad, angleA_Deg;
|
||||
double angleB_Deg;
|
||||
|
||||
// show title
|
||||
// function: printString, printEndline(s)
|
||||
printEndline();
|
||||
printString( "Right Triangle Angle Calculator" );
|
||||
printEndline();
|
||||
printString( "=========================" );
|
||||
printEndlines( TWO_ENDLINES );
|
||||
|
||||
// get input
|
||||
|
||||
// show expression, provide instructions
|
||||
// function: printString, printEndline(s)
|
||||
printString( "For any given triangle," );
|
||||
printEndline();
|
||||
printString( "Enter the side lengths below:" );
|
||||
printEndlines( TWO_ENDLINES );
|
||||
|
||||
// get first coefficient
|
||||
// function: promptForDouble
|
||||
sideA = promptForDouble( "Enter side A: " );
|
||||
|
||||
// get second coefficient
|
||||
// function: promptForDouble
|
||||
sideB = promptForDouble( "Enter side B: " );
|
||||
|
||||
// process data
|
||||
// calculate sideA^2
|
||||
// function: pow
|
||||
sqSideA = pow(sideA, 2);
|
||||
|
||||
// calculate sideB^2
|
||||
// function: pow
|
||||
sqSideB = pow(sideB, 2);
|
||||
|
||||
// calculate sideC^2
|
||||
sqSideC = sqSideA + sqSideB;
|
||||
|
||||
// calculate sideC
|
||||
// function: sqrt
|
||||
sideC = sqrt(sqSideC);
|
||||
|
||||
// find angles
|
||||
// find angle A
|
||||
cosAngleA = sideB/sideC;
|
||||
|
||||
// find angle in radians
|
||||
// function: acos
|
||||
angleA_Rad = acos(cosAngleA);
|
||||
|
||||
// find angle A in degrees
|
||||
angleA_Deg = angleA_Rad*(DEGREES_IN_TRIANGLE/CONSTANT_PI);
|
||||
|
||||
// find angle B in degrees
|
||||
angleB_Deg = ANGEL_C_DEG - angleA_Deg;
|
||||
|
||||
|
||||
// display results
|
||||
|
||||
// print top line
|
||||
// function: printString, printEndline
|
||||
printEndline();
|
||||
printString( TOP_LINE );
|
||||
printEndline();
|
||||
|
||||
// print title line
|
||||
// function: printCharacter, printStringJustified, printEndline
|
||||
printCharacter( PIPE );
|
||||
printStringJustified( "RIGHT TRIANGLE ANGLE CALCULATIONS",
|
||||
TABLE_WIDTH - 2, "CENTER" );
|
||||
printCharacter( PIPE );
|
||||
printEndline();
|
||||
|
||||
// print thick divider line
|
||||
// function: printString, printEndline
|
||||
printString( THICK_LINE_DIVIDER );
|
||||
printEndline();
|
||||
|
||||
// print sub title line
|
||||
// function: printStringJustified, printString, printCharacter
|
||||
printString( PIPE_SPACE );
|
||||
printStringJustified( "Data Name", DATA_NAME_WIDTH - 1, "LEFT" );
|
||||
printCharacter( PIPE );
|
||||
printStringJustified( "Units", UNIT_WIDTH, "CENTER" );
|
||||
printString( PIPE_SPACE );
|
||||
printStringJustified( "Values", VALUE_WIDTH - 2, "CENTER" );
|
||||
printString( SPACE_PIPE );
|
||||
printEndline();
|
||||
|
||||
// print thin divider line
|
||||
// function: printString, printEndline
|
||||
printString( THIN_LINE_DIVIDER );
|
||||
printEndline();
|
||||
|
||||
// print Side A line
|
||||
printString( PIPE_SPACE );
|
||||
printStringJustified( "Side A", DATA_NAME_WIDTH - 1, "LEFT" );
|
||||
printCharacter( PIPE );
|
||||
printStringJustified( "m", UNIT_WIDTH, "CENTER" );
|
||||
printCharacter( PIPE );
|
||||
printDoubleJustified( sideA, PRECISION, VALUE_WIDTH - 1, "RIGHT" );
|
||||
printString( SPACE_PIPE );
|
||||
printEndline();
|
||||
|
||||
// print thin divider line
|
||||
// function: printString, printEndline
|
||||
printString( THIN_LINE_DIVIDER );
|
||||
printEndline();
|
||||
|
||||
// print Side B line
|
||||
printString( PIPE_SPACE );
|
||||
printStringJustified( "Side B", DATA_NAME_WIDTH - 1, "LEFT" );
|
||||
printCharacter( PIPE );
|
||||
printStringJustified( "m", UNIT_WIDTH, "CENTER" );
|
||||
printCharacter( PIPE );
|
||||
printDoubleJustified( sideB, PRECISION, VALUE_WIDTH - 1, "RIGHT" );
|
||||
printString( SPACE_PIPE );
|
||||
printEndline();
|
||||
|
||||
// print thin divider line
|
||||
// function: printString, printEndline
|
||||
printString( THIN_LINE_DIVIDER );
|
||||
printEndline();
|
||||
|
||||
// print Side C line
|
||||
printString( PIPE_SPACE );
|
||||
printStringJustified( "Side C", DATA_NAME_WIDTH - 1, "LEFT" );
|
||||
printCharacter( PIPE );
|
||||
printStringJustified( "m", UNIT_WIDTH, "CENTER" );
|
||||
printCharacter( PIPE );
|
||||
printDoubleJustified( sideC, PRECISION, VALUE_WIDTH - 1, "RIGHT" );
|
||||
printString( SPACE_PIPE );
|
||||
printEndline();
|
||||
|
||||
// print thick divider line
|
||||
// function: printString, printEndline
|
||||
printString( THICK_LINE_DIVIDER );
|
||||
printEndline();
|
||||
|
||||
// print Angle a line
|
||||
printString( PIPE_SPACE );
|
||||
printStringJustified( "Angle a", DATA_NAME_WIDTH - 1, "LEFT" );
|
||||
printCharacter( PIPE );
|
||||
printStringJustified( "deg", UNIT_WIDTH, "CENTER" );
|
||||
printCharacter( PIPE );
|
||||
printDoubleJustified( angleA_Deg, PRECISION, VALUE_WIDTH - 1, "RIGHT" );
|
||||
printString( SPACE_PIPE );
|
||||
printEndline();
|
||||
|
||||
// print thin divider line
|
||||
// function: printString, printEndline
|
||||
printString( THIN_LINE_DIVIDER );
|
||||
printEndline();
|
||||
|
||||
// print Angle b line
|
||||
printString( PIPE_SPACE );
|
||||
printStringJustified( "Angle b", DATA_NAME_WIDTH - 1, "LEFT" );
|
||||
printCharacter( PIPE );
|
||||
printStringJustified( "deg", UNIT_WIDTH, "CENTER" );
|
||||
printCharacter( PIPE );
|
||||
printDoubleJustified( angleB_Deg, PRECISION, VALUE_WIDTH - 1, "RIGHT" );
|
||||
printString( SPACE_PIPE );
|
||||
printEndline();
|
||||
|
||||
// print thin divider line
|
||||
// function: printString, printEndline
|
||||
printString( THIN_LINE_DIVIDER );
|
||||
printEndline();
|
||||
|
||||
// print Angle c line
|
||||
printString( PIPE_SPACE );
|
||||
printStringJustified( "Angle c", DATA_NAME_WIDTH - 1, "LEFT" );
|
||||
printCharacter( PIPE );
|
||||
printStringJustified( "deg", UNIT_WIDTH, "CENTER" );
|
||||
printCharacter( PIPE );
|
||||
printDoubleJustified( ANGEL_C_DEG, PRECISION,
|
||||
VALUE_WIDTH - 1, "RIGHT" );
|
||||
printString( SPACE_PIPE );
|
||||
printEndline();
|
||||
|
||||
// print thick divider line
|
||||
// function: printString, printEndline
|
||||
printString( THICK_LINE_DIVIDER );
|
||||
printEndline();
|
||||
|
||||
// end program
|
||||
|
||||
// show end program
|
||||
// function: printString, printEndline
|
||||
printEndline();
|
||||
printString( "End Program" );
|
||||
printEndline();
|
||||
|
||||
// return program success
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// supporting functions
|
||||
// none
|
||||
Loading…
Add table
Add a link
Reference in a new issue