Added all previous files

This commit is contained in:
Owen Dorweiler 2025-12-14 17:24:49 -05:00
commit f04fb2189a
59 changed files with 64921 additions and 0 deletions

49
lab2/graph.c Normal file
View file

@ -0,0 +1,49 @@
// Author: Owen Dorweiler
// Class: Fundementals of Computing
// Assignment: Lab 2, Part 3
// Description: Computes and prints graph of equation using x and y
#include <stdio.h>
#include <math.h>
int main() {
// Initialize variables
double minX, minY, maxX, maxY;
double startX = 0.0, endX = 10.0, step = 0.2;
// Print plot title
printf("\nPlot for y = 12+(5*sin(2*x))+(6*cos(3*x)) for x from %.1f to %.1f", startX, endX);
printf("\nX\tY");
// Define starting max and min
double y;
y = 12+(5*sin(2*startX))+(6*cos(3*startX));
minY = y;
maxY = y;
minX = startX;
maxX = startX;
// Calculate y, check if max or min
for (double x = startX; x <= endX; x = x + step) {
y = 12+(5*sin(2*x))+(6*cos(3*x));
if (minY > y) {
minY = y;
minX = x;
}
if (maxY < y) {
maxY = y;
maxX = x;
}
// Print line of plot
printf("\n%.2f\t%.2f\t", x, y);
int roundY = (int)floor(y);
for (int a = 1; a <= roundY; a++)
printf("#");
}
// Print max and min
printf("\nThe maximum of %.2f was at %.2f", maxY, maxX);
printf("\nThe minimum of %.2f was at %.2f\n", minY, minX);
}

58
lab2/mortgage.c Normal file
View file

@ -0,0 +1,58 @@
// Author: Owen Dorweiler
// Class: Fundementals of Computing
// Assignment: Lab 2, Part 2
// Description: Calculates time it takes to pay off a mortgage given the principal, interest rate, and monthly payment
#include <stdio.h>
#include <math.h>
int main() {
// Initialize user defined variables
double principal, payment, rate;
// Get inputs from user
printf("Enter principal (initial amount): ");
scanf("%lf", &principal);
printf("Enter yearly interest rate (%): ");
scanf("%lf", &rate);
printf("Enter monthly payment: ");
scanf("%lf", &payment);
// Initialize variables
double balance = principal, interest, totalPaid = 0, monthRate = rate/12;
int totalMonths = 0;
// Check to if payment is less than interest; if so, display error
if (payment < balance * monthRate / 100)
printf("You cannot pay off your mortgage because your monthly payment is less than your initial monthly interest.\n");
else {
// Print header
printf("\nMonth\tPayment\t\tInterest\tBalance");
// Calculate and display table
for (int month = 1; balance > 0; month++) {
// Calculate interest
interest = balance * monthRate / 100;
// Check if balance is 0, and calculate balance
if (payment > balance) {
payment = balance;
balance = 0;
}
else balance = balance + interest - payment;
// Sum totals
totalPaid += payment;
totalMonths++;
printf("\n%d\t$%.2f\t\t$%.2f\t\t$%.2f", month, payment, interest, balance);
}
// Calculate and print total stats
int years = totalMonths / 12;
int months = totalMonths % 12;
printf("\n\nYou paid a total of $%.2f over %d years and %d months.\n\n", totalPaid, years, months);
}
}

19
lab2/report.txt Normal file
View file

@ -0,0 +1,19 @@
Author: Owen Dorweiler
Class: Fundementals of Computing
Assignment: Lab 2, Lab Report
The third program (graph.c) works as follows:
From a user perspective, the user simply runs the program and it graphs the equation.
Internally, the program starts by defining three important variables: startX, endX, and step. These variables correspond to the starting x value, the ending x value, and the step size. These are not values the user inputs, but the programmer can change them and it will change the behavior of the program. I did this so validation would be easier and the program would be more flexible.
The program prints the plot title and sets the maximum and minimum values to the values at startX. It then goes steps from startX to endX with the given step size, calculating y, checking to see if it is a new maximum or minimum, and plotting it as a bar graph.
If the new y value is a max or min, it overwrites the previous max or min value.
The program displays two decimal places, but rounds y to the nearest whole number for plotting.
At the end of the program, it displays the maximum and minimum and the x value for each.
I validated the output by comparing it to a graph generated by a graphing calculator, and manually checked the maximum and minumum points.

32
lab2/table.c Normal file
View file

@ -0,0 +1,32 @@
// Author: Owen Dorweiler
// Class: Fundementals of Computing
// Assignment: Lab 2, Part 1
// Description: Gets two numerical inputs and outputs a multiplication table
#include <stdio.h>
int main() {
// Declare variables
int num1, num2;
// Get inputs
printf("Input first number: ");
scanf("%d", &num1);
printf("Input second number: ");
scanf("%d", &num2);
// Print table header
printf("*");
for (int a = 1; a <= num1; a++) {
printf("\t%d", a);
}
// Print table
for (int b = 1; b <= num2; b++) {
printf("\n%d |", b);
for (int c = 1; c <= num1; c++) {
printf("\t%d", b * c);
}
}
printf("\n");
}