++ Homework 2 Files
This commit is contained in:
parent
90652a17ce
commit
6269fbc4ce
10 changed files with 191 additions and 0 deletions
BIN
Homework2/dhms
Executable file
BIN
Homework2/dhms
Executable file
Binary file not shown.
40
Homework2/dhms.c
Normal file
40
Homework2/dhms.c
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
// header files
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
// 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;
|
||||
}
|
||||
BIN
Homework2/ohm
Executable file
BIN
Homework2/ohm
Executable file
Binary file not shown.
32
Homework2/ohm.c
Normal file
32
Homework2/ohm.c
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
// header files
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
// 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;
|
||||
}
|
||||
BIN
Homework2/quadratic
Executable file
BIN
Homework2/quadratic
Executable file
Binary file not shown.
36
Homework2/quadratic.c
Normal file
36
Homework2/quadratic.c
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
// header files
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
// 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;
|
||||
}
|
||||
BIN
Homework2/seconds
Executable file
BIN
Homework2/seconds
Executable file
Binary file not shown.
47
Homework2/seconds.c
Normal file
47
Homework2/seconds.c
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
// header files
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
// 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;
|
||||
}
|
||||
BIN
Homework2/volume
Executable file
BIN
Homework2/volume
Executable file
Binary file not shown.
36
Homework2/volume.c
Normal file
36
Homework2/volume.c
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
// header files
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
// 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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue