125 lines
3.3 KiB
C
125 lines
3.3 KiB
C
// 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 = 32;
|
|
const int DATA_NAME_WIDTH = 16;
|
|
const int VALUE_WIDTH = 16;
|
|
|
|
const char TOP_LINE[] = "===================================";
|
|
const char THICK_LINE_DIVIDER[] = "|=================================|";
|
|
const char THIN_LINE_DIVIDER[] = "|---------------------------------|";
|
|
|
|
|
|
// prototypes
|
|
void printTopLine();
|
|
void printThickDividerLine();
|
|
void printThinDividerLine();
|
|
|
|
|
|
// main program
|
|
int main()
|
|
{
|
|
// make title, circle area calculator
|
|
// display header using "="
|
|
// print ENDLINE
|
|
// functions: printString, printEndline(s), printCharacters
|
|
printEndline();
|
|
printString("Circle Area Calculator");
|
|
printEndline();
|
|
printCharacters(22, '=');
|
|
printEndlines(2);
|
|
printString("Enter required information");
|
|
printEndline();
|
|
|
|
// initialize variables
|
|
int radiusCircle;
|
|
double areaCircle;
|
|
|
|
// gather user input
|
|
// functions: promptForInteger
|
|
radiusCircle = promptForInteger("Enter the radius of the circle: ");
|
|
|
|
// conduct computations
|
|
// functions: pow
|
|
areaCircle = CONSTANT_PI * pow(radiusCircle, 2);
|
|
|
|
// display results
|
|
// make TABLE
|
|
// functions: printDoubleJustified, printStringJustified, printCharacter,
|
|
// printEndline(s), printThickDividerLine, printThinDividerLine
|
|
printEndlines(3);
|
|
// Top line for data results table
|
|
printThickDividerLine();
|
|
printEndline();
|
|
// Shows the data results table header
|
|
printCharacter(PIPE);
|
|
printCharacter(SPACE);
|
|
printStringJustified("Data Results", TABLE_WIDTH - 1, "CENTER");
|
|
printCharacter(SPACE);
|
|
printCharacter(PIPE);
|
|
printEndline();
|
|
printThinDividerLine();
|
|
printEndline();
|
|
// Shows the first line of the table, the radius of the Circle
|
|
printCharacter(PIPE);
|
|
printCharacter(SPACE);
|
|
printStringJustified("Radius", DATA_NAME_WIDTH - 2, "LEFT");
|
|
printCharacter(SPACE);
|
|
printCharacter(PIPE);
|
|
printCharacter(SPACE);
|
|
printDoubleJustified(radiusCircle, PRECISION, VALUE_WIDTH - 2, "RIGHT");
|
|
printCharacter(SPACE);
|
|
printCharacter(PIPE);
|
|
printEndline();
|
|
printThinDividerLine();
|
|
printEndline();
|
|
// Prints Area Results
|
|
printCharacter(PIPE);
|
|
printCharacter(SPACE);
|
|
printStringJustified("Area", DATA_NAME_WIDTH - 2, "LEFT");
|
|
printCharacter(SPACE);
|
|
printCharacter(PIPE);
|
|
printCharacter(SPACE);
|
|
printDoubleJustified(areaCircle, PRECISION, VALUE_WIDTH - 2, "RIGHT");
|
|
printCharacter(SPACE);
|
|
printCharacter(PIPE);
|
|
printEndline();
|
|
printThinDividerLine();
|
|
printEndlines(2);
|
|
|
|
// END program
|
|
printString("End Program");
|
|
printEndline();
|
|
return 0;
|
|
}
|
|
|
|
// supporting functions
|
|
|
|
void printThickDividerLine()
|
|
{
|
|
// display thik line divider
|
|
// functions: printString
|
|
printString(THICK_LINE_DIVIDER);
|
|
}
|
|
|
|
void printThinDividerLine()
|
|
{
|
|
// display thin line divider
|
|
// functions: printString
|
|
printString(THIN_LINE_DIVIDER);
|
|
}
|
|
|
|
void printTopLine()
|
|
{
|
|
// display top line
|
|
// functions: printString
|
|
printString(TOP_LINE);
|
|
}
|