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

89
lab3/menucalc.c Normal file
View file

@ -0,0 +1,89 @@
// Owen Dorweiler
// Fundamentals of Computing
// Lab 3, Text Menu Calculator
// Program to help 3rd graders verify math skills; does user selected operations on two integers
#include <stdio.h>
#include <math.h>
int menu();
void decide(int, double, double);
void add(double, double);
void subtract(double, double);
void multiply(double, double);
void divide(double, double);
int main() {
int select;
double num1, num2;
// Run function to display menu and get selection
select = menu();
// Run loop while selection is not 5
while (select != 5) {
// Get user input
printf("Enter number 1: ");
scanf("%lf", &num1);
printf("Enter number 2: ");
scanf("%lf", &num2);
// Run decision function, which calls other functions
decide(select, num1, num2);
// Display menu again and get selection
select = menu();
}
return 0;
}
int menu() {
int select;
// Display menu
printf("What would you like to do?");
printf("\n1 - Addition");
printf("\n2 - Subtraction");
printf("\n3 - Multiplication");
printf("\n4 - Division");
printf("\n5 - Quit");
// Get selection
printf("\n\nEnter selection: ");
scanf("%d", &select);
return select;
}
void decide(int select, double num1, double num2) {
// Call functions based on selection, checking for errors
if (select == 1)
add(num1, num2);
else if (select == 2)
subtract(num1, num2);
else if (select == 3)
multiply(num1, num2);
else if (select == 4) {
if (num2 != 0)
divide(num1, num2);
else printf("\nError: divide by zero.\n\n");
}
else printf("\nError: invalid menu selection.\n\n");
}
void add(double x, double y) {
printf("\n(%g) + (%g) = %g\n\n", x, y, x+y);
}
void subtract(double x, double y) {
printf("\n(%g) - (%g) = %g\n\n", x, y, x-y);
}
void multiply(double x, double y) {
printf("\n(%g) * (%g) = %g\n\n", x, y, x*y);
}
void divide(double x, double y) {
printf("\n(%g) / (%g) = %g\n\n", x, y, x/y);
}

73
lab3/polar.c Normal file
View file

@ -0,0 +1,73 @@
// Owen Dorweiler
// Fundamentals of Computing
// Lab 3, Quadrants and Polar Coordinates
// Finds quadrant and polar coordinates for an x, y coordinate
#include <stdio.h>
#include <math.h>
int get_quadrant(double, double);
double get_radius(double, double);
double get_angle(double, double);
void show_info(int, double, double);
int main () {
int quadrant;
double radius, angle;
double x, y;
// Get user input
printf("Input x coordinate: ");
scanf("%lf", &x);
printf("Input y coordinate: ");
scanf("%lf", &y);
// Use funtions to get values for quadrant, radius, and angle
quadrant = get_quadrant(x, y);
radius = get_radius(x, y);
angle = get_angle(x, y);
show_info(quadrant, radius, angle);
return 0;
}
int get_quadrant(double x, double y) {
int quadrant;
// Find quadrant
if (x > 0) {
if (y > 0)
quadrant = 1;
else quadrant = 4;
}
else {
if (y > 0)
quadrant = 2;
else quadrant = 3;
}
return quadrant;
}
double get_radius(double x, double y) {
double radius;
// Find radius
radius = sqrt((x*x) + (y*y));
return radius;
}
double get_angle(double x, double y) {
double angle;
// Find angle
angle = atan2(y, x) * (180/M_PI);
return angle;
}
void show_info(int quadrant, double radius, double angle) {
printf("The point is in quadrant %d with radius %lf and angle %.2lf degrees.\n", quadrant, radius, angle);
}

65
lab3/quadratics.c Normal file
View file

@ -0,0 +1,65 @@
// Owen Dorweiler
// Fundamentals of Computing
// Lab 3, Multiple Quadratics
// Calculates zeros using the quadratic formula given a, b, c inputs, using a function to find the discriminant and going in a loop
#include <stdio.h>
#include <math.h>
double findDisc(double, double, double);
int main() {
// Initialize variables
double a, b, c;
double disc;
double zero1, zero2;
// Print title and get a input
printf("Quadratic Roots Calculator");
printf("\nEnter A (0 to quit): ");
scanf("%lf", &a);
while (a != 0) {
//Get b and c inputs
printf("Enter B: ");
scanf("%lf", &b);
printf("Enter C: ");
scanf("%lf", &c);
// Calculate discriminant
disc = findDisc(a, b, c);
if (disc > 0) {
// Calculate zeros
zero1 = (-b + sqrt(disc)) / (2*a);
zero2 = (-b - sqrt(disc)) / (2*a);
// Print result
printf("The first zero is %.4lf\n", zero1);
printf("The second zero is: %.4lf\n", zero2);
}
else if (disc == 0) {
// Calculate zero
zero1 = -b / (2*a);
// Print result
printf("The zero is %.4lf\n", zero1);
}
// If roots are imaginary, print message
else printf("The roots are imaginary.\n");
// Get a input
printf("\nEnter A (0 to quit): ");
scanf("%lf", &a);
}
return 0;
}
double findDisc(double a, double b, double c) {
double disc;
disc = (b*b) - (4*a*c);
return disc;
}

10
lab3/report.txt Normal file
View file

@ -0,0 +1,10 @@
Owen Dorweiler
Fundementals of Computing
Lab 3, Lab Report
From a user perspective, the program first prints a menu, asks for a selection, then asks for two numbers, and performs the selected calculation, displaying it to the user and displaying errors if applicable. It then repeats this process until the user selects option 5 (quit).
Internally, the program first initializes the selection and num1 and num2 variables, then runs the menu() program to display the menu and get the first user input. It then stops if the selection is 5, or keeps going if it is not 5. It gets user inputs for the first and second number, then passes the selection along with these numbers to the decide() function. This function sends the numbers to the correct operation function (add, subtract, multiply, divide) based on the selection, also displaying errors if there are any. The operation functions perform the selected operation on the numbers and display the output. The program then returns to main(), where the menu() function is called again, returning to the start of the loop.
The program was verified by a series of tests with both integers and decimal numbers for each operation, including inputs that yield errors. The program functioned correctly.