diff --git a/Homework2/dhms b/Homework2/dhms new file mode 100755 index 0000000..e0c7164 Binary files /dev/null and b/Homework2/dhms differ diff --git a/Homework2/dhms.c b/Homework2/dhms.c new file mode 100644 index 0000000..c7e6ab0 --- /dev/null +++ b/Homework2/dhms.c @@ -0,0 +1,40 @@ +// header files +#include +#include +#include +#include + +// local constants +#define SECONDS_IN_DAY 86400 +#define SECONDS_IN_HOUR 3600 +#define SECONDS_IN_MINUTE 60 + +#define TIME_CONSTANT_SECONDS 8675309 + +/* +Name: Day/Hour/Minute/Second Calculator +Process: Given a number of seconds, + figure out how many days, hours, minutes and seconds fits. +Function input/parameters: NONE +Function output/parameters: NONE +Function output/returned: NONE +Device input/---: NONE +Device output/---: NONE +Dependencies: included by standard libraries +*/ +int main() +{ + // define local variables + int totalDays, totalHours, totalMinutes, totalSeconds; + // do calculations + // need to modulo then divide by last time unit for each part. + totalSeconds = TIME_CONSTANT_SECONDS % SECONDS_IN_MINUTE; + totalMinutes = (TIME_CONSTANT_SECONDS % SECONDS_IN_HOUR) / SECONDS_IN_MINUTE; + totalHours = (TIME_CONSTANT_SECONDS % SECONDS_IN_DAY) / SECONDS_IN_HOUR; + totalDays = (TIME_CONSTANT_SECONDS % (SECONDS_IN_DAY * 30)) / SECONDS_IN_DAY; + // display results + printf("In %d seconds, there are: %d days, %d hours, %d minutes, %d seconds\n", + TIME_CONSTANT_SECONDS, totalDays, totalHours, totalMinutes, totalSeconds); + // return success + return 0; +} \ No newline at end of file diff --git a/Homework2/ohm b/Homework2/ohm new file mode 100755 index 0000000..5cc3301 Binary files /dev/null and b/Homework2/ohm differ diff --git a/Homework2/ohm.c b/Homework2/ohm.c new file mode 100644 index 0000000..293990b --- /dev/null +++ b/Homework2/ohm.c @@ -0,0 +1,32 @@ +// header files +#include +#include +#include +#include +// local constants +#define AMPS_IN_SYSTEM 15 +#define VOLTS_IN_SYSTEM 120 + +/* +Name: Ohm's Law +Process: Given amps and volts, + calculate how much resistance in Ohms is present in this system. +Function input/parameters: NONE +Function output/parameters: NONE +Function output/returned: NONE +Device input/---: NONE +Device output/---: NONE +Dependencies: included by standard libraries +*/ +int main() +{ + // define local variables + int calculatedOhms; + // do calculations + calculatedOhms = VOLTS_IN_SYSTEM / AMPS_IN_SYSTEM; + // display results + printf("%d amps of current at %d volts requires %d ohms of resistance.\n", + AMPS_IN_SYSTEM, VOLTS_IN_SYSTEM, calculatedOhms); + // return success + return 0; +} \ No newline at end of file diff --git a/Homework2/quadratic b/Homework2/quadratic new file mode 100755 index 0000000..15ede19 Binary files /dev/null and b/Homework2/quadratic differ diff --git a/Homework2/quadratic.c b/Homework2/quadratic.c new file mode 100644 index 0000000..3e59a81 --- /dev/null +++ b/Homework2/quadratic.c @@ -0,0 +1,36 @@ +// header files +#include +#include +#include +#include + +// local constants +#define QUADRATIC_A 2 +#define QUADRATIC_B -4 +#define QUADRATIC_C -3 + +/* +Name: Quadratic Formula Root Finder +Process: +Function input/parameters: NONE +Function output/parameters: NONE +Function output/returned: NONE +Device input/---: NONE +Device output/---: NONE +Dependencies: included by standard libraries +*/ +int main() +{ + // define local variables + double positiveRoot, negativeRoot; + // do calculations + positiveRoot = (-QUADRATIC_B + sqrt((QUADRATIC_B * QUADRATIC_B) - + (4 * QUADRATIC_A * QUADRATIC_C))) / (2*QUADRATIC_A); + negativeRoot = (-QUADRATIC_B - sqrt((QUADRATIC_B * QUADRATIC_B) - + (4 * QUADRATIC_A * QUADRATIC_C))) / (2*QUADRATIC_A); + // display results + printf("The roots of the quadratic %dx^2 + %dx + %d are: %f & %f.\n", + QUADRATIC_A, QUADRATIC_B, QUADRATIC_C, positiveRoot, negativeRoot); + // return success + return 0; +} \ No newline at end of file diff --git a/Homework2/seconds b/Homework2/seconds new file mode 100755 index 0000000..5f86992 Binary files /dev/null and b/Homework2/seconds differ diff --git a/Homework2/seconds.c b/Homework2/seconds.c new file mode 100644 index 0000000..d1b7dcb --- /dev/null +++ b/Homework2/seconds.c @@ -0,0 +1,47 @@ +// header files +#include +#include +#include +#include + +// local constants +#define SECONDS_IN_YEAR 31449600 +#define SECONDS_IN_WEEK 604800 +#define SECONDS_IN_DAY 86400 +#define SECONDS_IN_HOUR 3600 +#define SECONDS_IN_MINUTE 60 + +#define TIME_CONSTANT_YEARS 3 +#define TIME_CONSTANT_WEEKS 6 +#define TIME_CONSTANT_DAYS 5 +#define TIME_CONSTANT_HOURS 2 +#define TIME_CONSTANT_MINUTES 5 + +/* +Name: Seconds in TIME_CONSTANT +Process: Calculates the amount of time in seconds that an amount of + years/weeks/days/hours/minutes in total seconds. +Function input/parameters: NONE +Function output/parameters: NONE +Function output/returned: NONE +Device input/---: NONE +Device output/---: NONE +Dependencies: included by standard libraries +*/ +int main() +{ + // define local variables + int totalTime; + // do calculations + totalTime = (TIME_CONSTANT_YEARS * SECONDS_IN_YEAR) + + (TIME_CONSTANT_WEEKS * SECONDS_IN_WEEK) + + (TIME_CONSTANT_DAYS * SECONDS_IN_DAY) + + (TIME_CONSTANT_HOURS * SECONDS_IN_HOUR) + + (TIME_CONSTANT_MINUTES * SECONDS_IN_MINUTE); + // display results + printf("The total number of seconds in %d years, %d weeks, %d days, %d hours, and %d minutes is: %d seconds\n", + TIME_CONSTANT_YEARS, TIME_CONSTANT_WEEKS, TIME_CONSTANT_DAYS, + TIME_CONSTANT_HOURS, TIME_CONSTANT_MINUTES, totalTime); + // return success + return 0; +} \ No newline at end of file diff --git a/Homework2/volume b/Homework2/volume new file mode 100755 index 0000000..0f82a55 Binary files /dev/null and b/Homework2/volume differ diff --git a/Homework2/volume.c b/Homework2/volume.c new file mode 100644 index 0000000..9243cca --- /dev/null +++ b/Homework2/volume.c @@ -0,0 +1,36 @@ +// header files +#include +#include +#include +#include + +// local constants +#define EDGE_LENGTH_MULTIPLIER 5 +// this volume is in centimeters +#define TOP_FRACTION 5*(3 + sqrt(5)) +#define BOTTOM_FRACTION 12 + +/* +Name: Volume of Icosahedron +Process: Given an edge of an Icosahedron, calculate the volume of the shape. + Uses a formula found on Google to calculate this. +Function input/parameters: NONE +Function output/parameters: NONE +Function output/returned: NONE +Device input/---: NONE +Device output/---: NONE +Dependencies: included by standard libraries +*/ +int main() +{ + // define local variables + double icosahedronVol; + // do calculations + icosahedronVol = (TOP_FRACTION / BOTTOM_FRACTION) * + (EDGE_LENGTH_MULTIPLIER * EDGE_LENGTH_MULTIPLIER * EDGE_LENGTH_MULTIPLIER); + // display results + printf("An Icosahedron with edge length %d cm has volume %f cm.\n", + EDGE_LENGTH_MULTIPLIER, icosahedronVol); + // return success + return 0; +} \ No newline at end of file