diff --git a/OSU Coursework/CS 161 - Intro to Programming I/Assignments/Assignment 1/code/perrenc_hw0_1.c b/OSU Coursework/CS 161 - Intro to Programming I/Assignments/Assignment 1/code/perrenc_hw0_1.c new file mode 100644 index 0000000..8d7e280 --- /dev/null +++ b/OSU Coursework/CS 161 - Intro to Programming I/Assignments/Assignment 1/code/perrenc_hw0_1.c @@ -0,0 +1,56 @@ +/* + * Original Author: Corwin A. Perren (perrenc) + * File: perrenc_hw0_1.c + * Created: Unknown by perrenc + * Last Modified: 2012 February 21,20:33 by perrenc + * + * Prints out integers and decimals with specific numbers of decimal points. + * + */ + +#include + +int main (int argc, char **argv) { + + /* + * Creates integers and float variables, then assigns a computed value to them + */ + int a = (2 * 3); + int b = (1 / 5); + int c = (1 / 2); + int d = (3 / 2); + int e = (1 / 3); + int f = (2 / 3); + double g = (1.0 / 5); + double h = (1.0 / 2); + double i = (3.0 / 2); + double j = (1.0 / 3); + double k = (2.0 / 3); + double l = (1 / 5.0); + double m = (1 / 2.0); + double n = (3 / 2.0); + double o = (1 / 3.0); + double p = (2 / 3.0); + + /* + * Prints the integers with no decimal points and then prints the float values + * with 6 and 20 decimal points + */ + printf("a = %i\n", a); + printf("b = %i\n", b); + printf("c = %i\n", c); + printf("d = %i\n", d); + printf("e = %i\n", e); + printf("f = %i\n", f); + printf("g = %.06f\n %.20f\n", g, g); + printf("h = %.06f\n %.20f\n", h, h); + printf("i = %.06f\n %.20f\n", i, i); + printf("j = %.06f\n %.20f\n", j, j); + printf("k = %.06f\n %.20f\n", k, k); + printf("l = %.06f\n %.20f\n", l, l); + printf("m = %.06f\n %.20f\n", m, m); + printf("n = %.06f\n %.20f\n", n, n); + printf("o = %.06f\n %.20f\n", o, o); + printf("p = %.06f\n %.20f\n", p, p); + +} diff --git a/OSU Coursework/CS 161 - Intro to Programming I/Assignments/Assignment 1/code/perrenc_hw0_2.c b/OSU Coursework/CS 161 - Intro to Programming I/Assignments/Assignment 1/code/perrenc_hw0_2.c new file mode 100644 index 0000000..9c7a4e1 --- /dev/null +++ b/OSU Coursework/CS 161 - Intro to Programming I/Assignments/Assignment 1/code/perrenc_hw0_2.c @@ -0,0 +1,35 @@ +/* + * Original Author: Corwin A. Perren (perrenc) + * File: perrenc_hw0_2.c + * Created: Unknown by perrenc + * Last Modified: 2012 February 21, 20:36 by perrenc + * + * Uses printf to print integers the same way through two different methods. + * + */ + +#include + +int main (int argc, char **argv) { + + /* + * Creates variables for holding integers between and including 1 to 4 assigns + * one of these values to each variable. + */ + int a = 1; + int b = 2; + int c = 3; + int d = 4; + + /* Prints the four integer values on one line using a single printf statement. */ + printf("%d, %d, %d, %d\n\n", a, b, c, d); + + /* + * Prints the four integer values on the same line using four different printf + * statements. + */ + printf("%d, ", a); + printf("%d, ", b); + printf("%d, ", c); + printf("%d\n", d); +} diff --git a/OSU Coursework/CS 161 - Intro to Programming I/Assignments/Assignment 1/code/perrenc_hw0_4.c b/OSU Coursework/CS 161 - Intro to Programming I/Assignments/Assignment 1/code/perrenc_hw0_4.c new file mode 100644 index 0000000..75d692c --- /dev/null +++ b/OSU Coursework/CS 161 - Intro to Programming I/Assignments/Assignment 1/code/perrenc_hw0_4.c @@ -0,0 +1,29 @@ +/* + * Original Author: Corwin A. Perren (perrenc) + * File: perrenc_hw0_4.c + * Created: Unknown by perrenc + * Last Modified: 2012 February 21, 20:41 by perrenc + * + * Prints out integers from 10 down by using a for loop and if statement. + * + */ + +#include + +int main (int argc, char **argv) { + + /* Creates a variable for manipulation and sets it to an inital value of 10. */ + int x = 10; + + /* + * Takes x and prints its value and a comma from 10 to 2, then when the if + * statement falsifies, it prints the final value with a new line and exits. + */ + for( x ; x >= 1 ; x -= 1) { + if (x != 1){ + printf("%d, ", x); + }else{ + printf("%d\n", x); + } + } +} diff --git a/OSU Coursework/CS 161 - Intro to Programming I/Assignments/Assignment 1/code/perrenc_hw0_5.c b/OSU Coursework/CS 161 - Intro to Programming I/Assignments/Assignment 1/code/perrenc_hw0_5.c new file mode 100644 index 0000000..2b4cb88 --- /dev/null +++ b/OSU Coursework/CS 161 - Intro to Programming I/Assignments/Assignment 1/code/perrenc_hw0_5.c @@ -0,0 +1,26 @@ +/* + * Original Author: Corwin A. Perren (perrenc) + * File: perrenc_hw0_5.c + * Created: Unknown by perrenc + * Last Modified: 2012 February 21, 20:49 by perrenc + * + * Total all integers from 1 to whatever value is necessary to make x in the loop equal + * to 1000. + * + */ + +#include + +int main(int argc, char **argv){ + + int x; // Variable used for incrementing + int total; // Variable used for holding the total amount + + /* Increments x, then adds current x to the total until x is equal to 1000. */ + for(x = 1 ; x <= 1000 ; x++){ + total += x; + } + + /* Prints the total after going through the loop. */ + printf("%d\n", total); +} diff --git a/OSU Coursework/CS 161 - Intro to Programming I/Assignments/Assignment 1/code/perrenc_hw0_6.c b/OSU Coursework/CS 161 - Intro to Programming I/Assignments/Assignment 1/code/perrenc_hw0_6.c new file mode 100644 index 0000000..b1960c3 --- /dev/null +++ b/OSU Coursework/CS 161 - Intro to Programming I/Assignments/Assignment 1/code/perrenc_hw0_6.c @@ -0,0 +1,42 @@ +/* + * Original Author: Corwin A. Perren (perrenc) + * File: perrenc_hw0_6.c + * Created: Unknown by perrenc + * Last Modified: 2012 February 21, 20:54 by perrenc + * + * Calulates and prints out the fibonacci sequence up to a value the user specifies. + * + */ + +#include + +int main (int argc, char **argv){ + + int x; // Used for loop limiting + int k; // Used for user input + int a = 0; // Beginning of the fibonacci sequences + int b = 1; // Another beginning value of the fibonacci sequence + int total; + + /* + * Asks users to what value of the fibonacci sequence they would like to + * calculate and then stores it in k + */ + printf("Enter to what iteration of the fibonacci sequence you want to calculate: "); + scanf("%d", &k); + + /* + * Prints an iteration of the fibonacci sequence, totals the two previous values + * to make the next iteration, then loops until the number of iterations reaches + * what the user inputted previously. + */ + for(x = 0 ; x < k ; x++){ + printf("%d ", a); + total = a + b; + a = b; + b = total; + } + + /* Prints a new line to make the output cleaner. */ + printf("\n"); +} diff --git a/OSU Coursework/CS 161 - Intro to Programming I/Assignments/Assignment 1/code/perrenc_hw0_7.c b/OSU Coursework/CS 161 - Intro to Programming I/Assignments/Assignment 1/code/perrenc_hw0_7.c new file mode 100644 index 0000000..4219a94 --- /dev/null +++ b/OSU Coursework/CS 161 - Intro to Programming I/Assignments/Assignment 1/code/perrenc_hw0_7.c @@ -0,0 +1,30 @@ +/* + * Original Author: Corwin A. Perren (perrenc) + * File: perrenc_hw0_7.c + * Created: Unknown by perrenc + * Last Modified: 2012 February 21, 20:54 by perrenc + * + * Prints the ascii character for the number a user enters. + * + */ + +#include + +int main(int argc, char **argv){ + + int x; // Variable used for user input + + /* Ask user for input, then store it on x. */ + printf("Please enter a number between 0 and 255: "); + scanf("%d", &x); + + /* Prints the appropriate ascii character for an entered value as long as it is + * within range, else it prints an error, or exits with a "-1" input. + */ + if ((x < 0 | x > 255) & (x != -1)){ + printf("You entered an improper value or it was out of range...\n"); + }else if ((x >= 0) & (x <= 255)){ + printf("%c\n", x); + } +} + diff --git a/OSU Coursework/CS 161 - Intro to Programming I/Assignments/Assignment 1/code/perrenc_hw0_9.c b/OSU Coursework/CS 161 - Intro to Programming I/Assignments/Assignment 1/code/perrenc_hw0_9.c new file mode 100644 index 0000000..580db07 --- /dev/null +++ b/OSU Coursework/CS 161 - Intro to Programming I/Assignments/Assignment 1/code/perrenc_hw0_9.c @@ -0,0 +1,31 @@ +/* + * Original Author: Corwin A. Perren (perrenc) + * File: perrenc_hw0_9.c + * Created: Unknown by perrenc + * Last Modified: 2012 February 21, 20:54 by perrenc + * + * Print the square and cube roots of values from 1 to 25. + * + */ + +#include +#include + +int main(int argc, char **argv){ + + int x; // Variable used for incrementing from 1 to 25 + double y; // Variable used for squares and cubes manipulation + + /* + * Increments x from 1 to 25 and prints the x value, its square root, and cube + * root in column format, then ends. + */ + for(x = 1 ; x <= 25 ; x++){ + y = x; + printf("%i ", x); + y = sqrt (x); // Takes the square root of x + printf("%f ", y); + y = pow(x, (1/3.0)); // Takes the cube root of x + printf("%f \n", y); + } +} diff --git a/OSU Coursework/CS 161 - Intro to Programming I/Assignments/Assignment 1/written/USER INFORMATION.txt b/OSU Coursework/CS 161 - Intro to Programming I/Assignments/Assignment 1/written/USER INFORMATION.txt new file mode 100644 index 0000000..e136d4b --- /dev/null +++ b/OSU Coursework/CS 161 - Intro to Programming I/Assignments/Assignment 1/written/USER INFORMATION.txt @@ -0,0 +1,3 @@ +Corwin Perren +ECE 151 Section 10 +931759527 \ No newline at end of file diff --git a/OSU Coursework/CS 161 - Intro to Programming I/Assignments/Assignment 1/written/perrenc_hw0.txt b/OSU Coursework/CS 161 - Intro to Programming I/Assignments/Assignment 1/written/perrenc_hw0.txt new file mode 100644 index 0000000..9c97cf4 --- /dev/null +++ b/OSU Coursework/CS 161 - Intro to Programming I/Assignments/Assignment 1/written/perrenc_hw0.txt @@ -0,0 +1,193 @@ +1 - What does a comment in C look like? Give some examples. + +/** This is what the majority of block comments in C look like. Once it is + * recognized as a comment, the block color will change for easier + * readability. + */ + +// This is an example of a single line comment. It's useful for commenting on +// the same line as actual code. + + +2 - How does one open a file in vi? Save a file? Quit? + + a. To open a file, you type "vi filename" at the linux command line. + To save a file, enter vi command mode and type ":w" + To quit, enter vi command mode and type ":q" or press shift-z-z + + +3 - (3.1) Write the octal, decimal, and hexadecimal equivalents of these numbers. + Answers in form "Original: octal, decimal, hexadecimal" + + a. 00110011 = 63, 51, 33 + b. 01101100 = 154, 108, 3C + c. 01110111 = 167, 119, 77 + d. 00111101 = 75, 61, 3D + e. 11111011 = -5, -5, -5 + f. 11111111 = -1, -1, -1 + g. 00100010001011010 = 42132, 17498, 445A + h. 10100010001011010 = -135646, -48038, -BBA6 + + +4 - (3.5) Find the errors in each of the following segments. + a. printf("%s\n", 'Happy Birthday'); + Fixed: printf("%s\n", "Happy Birthday"); + + b. printf("\%c\n", 'Hello'); + Fixed: printf("%s\n", "Hello"); + + c. printf("%c\n", "This is a string); + Fixed: printf("%s\n", "This is a string"); + + d. printf(""%s"", 'Good Bye'); + Fixed: printf("%s", "\"Good Bye\"\n"); + + e. char c = 'a'; + printf("%s\n", c); + Fixed: char c = 'a'; + printf("%c\n", c); + + f. printf('Enter your name: "); + Fixed: printf("Enter your name: "); + + g. printf( %f, 123.456); + Fixed: printf("%f", 123.456); + + h. printf("%s%s\n", 'O', 'K'); + Fixed: printf "%s%s\n, "O", "K"); + + i. char c; + scanf("%c", c); + Fixed: char c; + scanf("%c", &c); + + j. double d; + scanf("%f", &d); + printf("%f", d); + Fixed: double d; + scanf("%lf", &d); + printf("%lf", d); + + k. int d; + scanf("%f", &d); + printf("%f", d); + Fixed: int d; + scanf("%d", &d); + printf("%d", d); + + l. double x = 123.45678, y; + int d; + d = x; + y = d; + printf("%f\n", y); + Fixed: double x = 123.45678 + double d; + d = x; + y = d; + printf("%f\n", y); + + +5 - (3.6) How many digits are after the decimal point for floating point values +printed with printf? Does printf round or truncate values? + + a. There are six values after the decimal point by default. Yes, + printf will always truncate to this number unless otherwise specified, and + while doing so, it rounds the answer. + + +6 - (3.17) Signed and unisgned representation problems + a. Signed - 256 + Unsigned - 128 + b. Signed - 65536 + Unsigned - 32768 + c. Signed - 4294967296 + Unsigned - 2147483648 + d. Signed - 64 + Unsigned - 32 + e. Signed - 1024 + Unsigned - 512 + + +7 - (4.1) State whether the following are true or false? + + a. False. Operators in C are evaluated from right to left. The + compiler reads down the code, the evaluates coming back up in the opposite + direction. + + b. False. The || operator is an inclusive or, meaning that if either + or both of the operator statements are true, the expression will evaluate as + true. + + +8 - (4.12) - Write C Expressions + + a. (x + 4) / (y + 5) + b. 9 + (5*((x + 4) / (y + 5))) + c. (4 / 3) * 3.14 * r pow(r, 3) + d. x < y + e. (x >= y) & (y <= z) + f. (x >= y) & (x >= 0) + g. (x <= 1) | (x > 20) + h. (x > 1) & (x <= 20) + i. ( (x > 1) & (x <= 20) ) | ( (y <= 3) & (y >= 1) ) + + +9 - (5.3) Correct errors in each of the code blocks + + a. if(age >= 65); + printf("Age is greater than or equal to 65\n"); + else + printf("Age is less than 65\n") + + a fixed: if(age >= 65){ + printf("Age is greater than or equal to 65\n"); + }else{ + printf("Age is less than 65\n"); + } + + + b. if(i = 2) + printf("i is 2\n"); + else + printf("i is not equal to 2\n"); + + b fixed: if(i == 2){ + printf("i is 2\n"); + }else{ + printf("i is not equal to 2\n"); + } + + + c. for(x = 999; x >= 1; x +=2) + printf("%d\n", n); + + c fixed: for(int x = 999; x >= 1; x -=2){ + printf("%d\n", x); + } + + + d. counter = 2; + Do { + if(counter % 2 == 0) + printf("%d\n", counter); + counter += 2; + }While(counter < 100) + + d fixed: counter = 2; + while(counter < 100){ + if((counter % 2) == 0){ + printf("%d\n", counter); + counter += 2; + } + } + + + e. total = 1; + for(x = 100; x <= 150; x++); + total += x; + + e fixed: total = 0; + for(int x = 100; x <= 150; x++){ + total += x; + } + diff --git a/OSU Coursework/CS 161 - Intro to Programming I/Assignments/Assignment 1/written/perrenc_hw0_6_flowchart.pdf b/OSU Coursework/CS 161 - Intro to Programming I/Assignments/Assignment 1/written/perrenc_hw0_6_flowchart.pdf new file mode 100644 index 0000000..0bb1909 Binary files /dev/null and b/OSU Coursework/CS 161 - Intro to Programming I/Assignments/Assignment 1/written/perrenc_hw0_6_flowchart.pdf differ diff --git a/OSU Coursework/CS 161 - Intro to Programming I/Assignments/Assignment 1/written/perrenc_hw0_6_pseudocode.txt b/OSU Coursework/CS 161 - Intro to Programming I/Assignments/Assignment 1/written/perrenc_hw0_6_pseudocode.txt new file mode 100644 index 0000000..5f1f9a9 --- /dev/null +++ b/OSU Coursework/CS 161 - Intro to Programming I/Assignments/Assignment 1/written/perrenc_hw0_6_pseudocode.txt @@ -0,0 +1,23 @@ +/** Pseudocode for question 6, homework 1, in ece151 +* Made by Corwin Perren +*/ + +create integer x +create integer t +create integer sum +create integer a and set to 0 +create integer b and set to 1 + +print "Enter the step of the Fibonacci sequence you want to calculate:" +print a new line +set integer t from user input + +while + t is greater than x + print a + sum a and b + set a = b + set b = sum + increment x by 1 + +when false print new line \ No newline at end of file diff --git a/OSU Coursework/CS 161 - Intro to Programming I/Assignments/Assignment 1/written/perrenc_hw0_7_flowchart.pdf b/OSU Coursework/CS 161 - Intro to Programming I/Assignments/Assignment 1/written/perrenc_hw0_7_flowchart.pdf new file mode 100644 index 0000000..7a0323a Binary files /dev/null and b/OSU Coursework/CS 161 - Intro to Programming I/Assignments/Assignment 1/written/perrenc_hw0_7_flowchart.pdf differ diff --git a/OSU Coursework/CS 161 - Intro to Programming I/Assignments/Assignment 1/written/perrenc_hw0_7_pseudocode.txt b/OSU Coursework/CS 161 - Intro to Programming I/Assignments/Assignment 1/written/perrenc_hw0_7_pseudocode.txt new file mode 100644 index 0000000..40690a3 --- /dev/null +++ b/OSU Coursework/CS 161 - Intro to Programming I/Assignments/Assignment 1/written/perrenc_hw0_7_pseudocode.txt @@ -0,0 +1,21 @@ +/** Pseudocode for question 7, homework 1, in ece151 +* Made by Corwin Perren +*/ + +create integer x + +print "Enter a number between 0 and 255" +print a new line +receive an integer "x" from user + +if + 1: x is less than 0 and greater than 255 + and + 2: x is not -1 + print "The value you entered was improper or out or range" + print a new line +else if + 1: x is greater than or equal to 0 + and + 2: x is less than or equal to 255 + print corresponding ASCII character from value of x diff --git a/OSU Coursework/CS 161 - Intro to Programming I/Assignments/Assignment 2/perrenc_hw1.c b/OSU Coursework/CS 161 - Intro to Programming I/Assignments/Assignment 2/perrenc_hw1.c new file mode 100644 index 0000000..c5e2e0a --- /dev/null +++ b/OSU Coursework/CS 161 - Intro to Programming I/Assignments/Assignment 2/perrenc_hw1.c @@ -0,0 +1,459 @@ +/* + * Original Author: Corwin A. Perren (perrenc) + * File: perrenc_hw1.c + * Created: 2012 February 17, 14:47 by perrenc + * Last Modified: 2012 February 20, 17:07 by perrenc + * + * This program is the entirety of assigment 2 for ece151 + * and requires compiling with the -lm argument to include + * math linking. + */ + +/* Includes */ +#include +#include + +/* Defines */ + +// For prob 1 ( 10.7 ) +#define WEEK 5 +#define DAY 7 + +/* --------------------Begin Functions-------------------- */ + +/* ********Problem 1******** */ + +/* + * This program takes a month of web page hit values and averages them per week day for + * the month. + */ +void prob1(void){ + + system("clear"); //Clears the screen + + int dayloop; //For looping the day variable + int weekloop; //For looping the week variable + int mean[DAY] = {0, 0, 0, 0, 0, 0, 0}; //Array for storing mean values + + /* This is the array taken from the book. */ + int hits[WEEK][DAY] = {367, 654, 545, 556, 565, 526, 437, + 389, 689, 554, 526, 625, 537, 468, + 429, 644, 586, 626, 652, 546, 493, + 449, 689, 597, 679, 696, 568, 522, + 489, 729, 627, 729, 737, 598, 552}; + + /* Fills the mean array with sums of the weekday values for the month. */ + for (weekloop = 0 ; weekloop < WEEK ; weekloop++){ + for (dayloop = 0 ; dayloop < DAY ; dayloop++){ + mean[dayloop] += hits[weekloop][dayloop]; + } + } + + /* + * Averages the values in mean for the number of weekdays summed in the previous + * step. + */ + for (dayloop = 0 ; dayloop < DAY ; dayloop++){ + mean[dayloop] /= WEEK; + } + + /* Prints the mean values for each day of the week. */ + printf("The mean number of hits for Mondays of this month was %d\n", mean[0]); + printf("The mean number of hits for Tuesdays of this month was %d\n", mean[1]); + printf("The mean number of hits for Wednesdays of this month was %d\n", mean[2]); + printf("The mean number of hits for Thursdays of this month was %d\n", mean[3]); + printf("The mean number of hits for Fridays of this month was %d\n", mean[4]); + printf("The mean number of hits for Saturdays of this month was %d\n", mean[5]); + printf("The mean number of hits for Sundays of this month was %d\n", mean[6]); + + pause (); //Waits for user to press enter before returning to the menu +} + + +/* ********Problem 2******* */ + +/* Calculates a centroid value for an array of pixels with intensities. */ +void prob2(void){ + + system("clear"); //Clears the screen + + int loop; //Used for loop incrementing + double centroidx = 0; //Stores the centroid x value + double centroidy = 0; //Stores the centroid y value + double intensitytotal = 0; //Stores the intensity total + + /* Pixels locations and intensities from the book. */ + double pixel[][2] = {5.0, -4.0, 4.0, 3.0, -1.0, 6.0, -9.0, 5.0}; + double intensity[] = {.25, .57, .63, .1}; + + /* + * Loops through the pixel array and performs the summing for the centroid + * calculation and stores the values in centroidx and y. + */ + for (loop = 0 ; loop <= 3 ; loop++){ + centroidx += (pixel[loop][0]*intensity[loop]); + centroidy += (pixel[loop][1]*intensity[loop]); + } + + /* + * Loops through the intensity array and sums the four values and stores it in + * intensitytotal. + */ + for (loop = 0 ; loop <= 3 ; loop++){ + intensitytotal += intensity[loop]; + } + + /* + * Divides the centroidx and y sums by the intensitytotal to complete the last + * step of the centroid calculation. + */ + centroidx /= intensitytotal; + centroidy /= intensitytotal; + + /* Prints the centroid value. */ + printf("Centroid = %.2lf, %.2lf", centroidx, centroidy); + + pause (); //Waits for user input before returning to the menu. +} + +/* ********Problem 3******** */ + +/* + * Searches an array of binary values for a specific binary value and returns whether it + * finds it. + */ +void prob3(void){ + + system("clear"); //Clears the screen + + int loop; //Used for looping + int searchvalue = 0b01010001; //Value that is searched + int searchreturn; //Stores binary search return value + + /* Random binary data. */ + int data[8] = {0b00000001, 0b00010001, 0b10010101, 0b01101110, + 0b11011011, 0b11111110, 0b00111101, 0b10011101}; + + printf("---------- Data Array Values --------\n"); //Prints a header + + /* Prints the array. */ + for (loop = 0 ; loop < 8 ; loop++){ + printf("%d\n", data[loop]); + } + + /* Searches the array with the binary value specified above. */ + searchreturn = binarysearch (8, data, searchvalue); + + /* + * Prints a different message depending on whether the value searched was + * found or not. + */ + if (searchreturn != -1){ + printf("\nThis binary value equivalent to %d was found in ", searchvalue); + printf("element %d of the array.\n", searchreturn); + }else { + printf("\nThis binary value equivalent to %d could not ", searchvalue); + printf("be found in the array."); + } + + pause (); //Watis for the user to press enter before returning to the menu +} + +/* + * Function that compares an array of binary values against a search value and returns + * whether the search term was found. + */ +int binarysearch(int arraysize, int data[], int search){ + + int loop; //Used for looping + + /* + * Searches the array for a binary value and returns whether it was found or + * not. + */ + for (loop = 0 ; loop < arraysize ; loop++){ + if (search == data[loop]){ + return loop; + } + } + + return -1; //Returns if the search value is not found +} + +/* ********Problem 5******** */ + +/* Performs matrix multiplication on two arrays the size of which the user can specify */ +void prob5(void){ + + system("clear"); //Clears the screen + + int arraysize; //Used for storing the array size + int loop1; //Used for level one looping + int loop2; //Used for level two looping + int loop3; //Used for level three looping + + /* Allows the user to specify the size of the arrays to multiply. */ + printf("Please enter the number of columns and rows the arrays should have: "); + scanf("%d", &arraysize); + + system("clear"); //Clears the screen + + int array1[arraysize][arraysize]; //First array + int array2[arraysize][arraysize]; //Second array + int array3[arraysize][arraysize]; //Third array with matrix multiplication + + /* + * Fills arrays 1 and 2 with numbers based on where they are in the loops and fills + * array three with zeros so we don't get random values. + */ + for (loop1 = 0 ; loop1 < arraysize ; loop1++){ + for (loop2 = 0 ; loop2 < arraysize ; loop2++){ + array1[loop1][loop2] = (2*((loop1+1)*(loop2+1))); + array2[loop1][loop2] = (4*((loop1+1)*(loop2+2))); + array3[loop1][loop2] = 0; + } + } + + printf("This is array 1:\n"); //Prints a header for array 1 + + /* Prints out array 1 */ + for (loop1 = 0 ; loop1 < arraysize ; loop1++){ + for (loop2 = 0 ; loop2 < arraysize ; loop2++){ + printf("%d ", array1[loop1][loop2]); + } + printf("\n"); + } + + printf("\nThis is array 2:\n"); //Prints a header for array 2 + + /* Prints out array 2 */ + for (loop1 = 0 ; loop1 < arraysize ; loop1++){ + for (loop2 = 0 ; loop2 < arraysize ; loop2++){ + printf("%d ", array2[loop1][loop2]); + } + printf("\n"); + } + + /* + * Performs matrix multiplication on array 1 and array 2 and stores it on + * array 3. + */ + for (loop1 = 0 ; loop1 < arraysize ; loop1++){ + for (loop2 = 0 ; loop2 < arraysize ; loop2++){ + for (loop3 = 0 ; loop3 < arraysize ; loop3++){ + array3[loop1][loop2] += (array1[loop1][loop3] * + array2[loop3][loop2]); + } + } + } + + /* Prints a header for array 3 */ + printf("\nThis is array 3, which is the result of matrix multiplication on "); + printf("array 1 and 2:\n"); + + /* Prints out array 3 */ + for (loop1 = 0 ; loop1 < arraysize ; loop1++){ + for (loop2 = 0 ; loop2 < arraysize ; loop2++){ + printf("%d ", array3[loop1][loop2]); + } + printf("\n"); + } + + pause (); //Waits for the user to press enter before returning to the menu +} + +/* ********Problem 6******** */ + +/* + * Calculates primes up to a user entered value by marking composites and printing + * what's left. + */ +void prob6(void){ + + system("clear"); //Clears the screen + + int userin1; //Used for user input + int loop1; //Used for level one loops + int loop2; //Used for level two loops + int loop3; //Used for level three loops + int total = 0; //Used for totaling the number of primes + + /* + * Asks the user for a number to calculate prime number to, stores it, and + * clears the screen. + */ + printf("Enter the value you want primes calculated to: "); + scanf("%d", &userin1); + system("clear"); + + int sieve[(userin1-1)]; //Creates an array for holding sieve values in + + /* Fills the array with integers from 2 to the user entered value */ + for(loop1 = 2 ; loop1 <= userin1 ; loop1++){ + sieve[(loop1-2)] = loop1; + } + + /* Sets all composites in the array to zero. */ + for(loop1 = 0 ; loop1 < userin1; loop1++){ + for(loop2 = 2; loop2 < userin1; loop2++){ + for(loop3 = loop2; loop3 < userin1; loop3++){ + if ((loop2*loop3) == sieve[loop1]){ + sieve[loop1] = 0; + } + } + } + } + + /* + * Prints out all values in the array that aren't zero, which leaves you with + * only prime numbers. + */ + printf("Here are the prime numbers from 0 to the number you entered: \n\n"); + for(loop1 = 0 ; loop1 < (userin1-1) ; loop1++){ + if(sieve[loop1] != 0){ + printf("%d\n", sieve[loop1]); + total++; //Increments total when something is printed + } + } + + /* Prints the number of primes. */ + printf("\nThere were %d primes in this list. ", total); + + pause (); //Waits until the user presses enter, then returns to the menu +} + + +/* ********Problem 7******* */ + +/* + * This takes in a string, then copies each value to another string and adds a null + * character before returning the copied string. + */ +char str_copy(char *s2, const char *s1){ + + int loop; //Used for looping + + /* + * Copies each character in string1 to the same place in string2 until it + * encounters the null character. + */ + for (loop = 0 ; s1[loop] != '\0' ; loop++){ + s2[loop] = s1[loop]; + } + + s2[(loop++)] = '\0'; //Adds the null character back in + return *s2; //Returns the copied string +} + +/* Takes a user entered string and copies it to another string. */ +void prob7(void){ + char string1[100]; //Storage for string1 + char string2[100]; //Storage for string2 + int loop; //Used for looping + + system("clear"); //Clears the screen + + /* + * Asks the user to enter a string, clears the buffer, and stores the string on + * string1. + */ + printf("Please enter a string:\n"); + while(getchar() != '\n'){ + ; //VOID + } + fgets(string1, 100, stdin); + + /* + * Replaces the newline character fgets scans in with a null character to make + * the array into a string. + */ + for (loop = 0 ; loop < 100 ; loop++){ + if (string1[loop] == '\n'){ + string1[loop] = '\0'; + break; + } + } + + printf("\nThis is string 1:\n%s\n\n", string1); //Prints string1 header + + str_copy(string2, string1); //Copies str1 to str2 + + printf("This is string 2 after being copied:\n%s\n", string2); //Prints header + + /* + * This is a modified version of my pause function that accounts for the fact + * that a buffer flush already happened. Essentially, this removes the extra + * getchar so that you don't have to hit enter twice to return to the menu. + */ + printf("\n\nPress enter to return to the menu."); + while(getchar() != '\n'){ + ; //VOID + } +} + + +/* Generic Functions */ + +/* Pauses until the user presses enter, then clears the buffer in case they type + * somthing before they hit enter */ +int pause(void){ + printf("\n\nPress enter to return to the menu."); + getchar (); + while('\n' != getchar()){ + ; //VOID + } +} + +/* --------------------End Functions-------------------- */ + +int main(int argc, char **argv){ + + int menu; // Used for selecting a menu item + + beginning: ; // Used for goto statements in switch + + system("clear"); //Clears the screen + + /* Creates the list of possible selections for the user menu. */ + printf("Please select which homework problem you would like to run:\n"); + printf("1 -- Problem 1 ( 10.7 )\n"); + printf("2 -- Problem 2 ( 10.10 )\n"); + printf("3 -- Problem 3 ( 10.30 )\n"); + printf("4 -- Problem 5 ( Matrix Multiplication )\n"); + printf("5 -- Problem 6 ( Sieve of Eratosthenes )\n"); + printf("6 -- Problem 7 ( 11.6 )\n"); + printf("7 -- Exit Program\n\n"); + printf("Enter Selection: "); + scanf("%d", &menu); + + /* + * Runs a particular program based on the user's input. Goto's are used since + * switch is a much cleaner way to impliment the menu selection and I could not + * find an alternative way. + */ + switch(menu){ + case 1: + prob1 (); //Runs problem 1 + goto beginning; //Goes back to the menu after running + case 2: + prob2 (); //Runs problem 2 + goto beginning; //Goes back to the menu after running + case 3: + prob3 (); //Runs problem 3 + goto beginning; //Goes back to the menu after running + case 4: + prob5 (); //Runs problem 5 + goto beginning; //Goes back to the menu after running + case 5: + prob6 (); //Runs problem 6 + goto beginning; //Goes back to the menu after running + case 6: + prob7 (); //Runs problem 7 + goto beginning; //Goes back to the menu after running + case 7: + system("clear"); //Clears the screen + return 0; //Ends the program + + } + +} diff --git a/OSU Coursework/CS 161 - Intro to Programming I/Assignments/Assignment 2/perrenc_hw1.txt b/OSU Coursework/CS 161 - Intro to Programming I/Assignments/Assignment 2/perrenc_hw1.txt new file mode 100644 index 0000000..5015474 --- /dev/null +++ b/OSU Coursework/CS 161 - Intro to Programming I/Assignments/Assignment 2/perrenc_hw1.txt @@ -0,0 +1,254 @@ +Corwin Perren - 931759527 +Assignment 2 - ECE151 +Written Questions + + +Problem 1(10.2) + a. + Original code: + char str[5]; + scanf("%s", str); /* User types hello */ + + Fixed code: + char str[5]; + scanf("%s", &str); //user types hello + Explanation: + An ampersand is needed to store the value to memory, and the commenting + is inconsistent with the style guide. + + b. + Original: + int a[3]; + printf("%d %d %d\n", a[1], a[2], a[3]); + Fixed: + int a[3] = {1, 3, 5}; + printf("%d %d %d\n", a[0], a[1], a[2]); + Explanation: + The original creates an empty array with no values in it, which makes it + impossible to print its contents. The location in memory is dumped. Also, + the locations printf is pulling from are one block off. The first value + has location [0,0], not [1,1]. + + c. + Original: + double f[3] = {1.1, 10.01, 100.001, 1000.001}; + Fixed: + double f[4] = {1.1, 10.01, 100.001, 1000.001}; + Explanation: + The array is not large enough. + + d. + Original: + double d[2][10]; + d[1,9] = 2.345; + Fixed: + float d[2][10]; + d[1][9] = 2.345; + Explanation: + Used incorrect location mapping and the double was not big enough to + handle this decimal. + + + +Problem 2(10.4) + +Original: + int N; + int M=90; + + int funct4(int n) { + int i; + int m = n; + int a[n][n]; + int b[n][m]; + int c[printf("%d\n", n)][n]; + int d[n][N]; + int e[n][M]; + int f[n] = {1, 2, 3, 4}; + static int g[n]; + + for(i=0; i + +#define x 5 +#define y 10 + +int main (int argc, char **argv) { + + if ((x == 5) | (x == 6)) { + printf("Yup, it worked.\n"); + } + + if ((x == 6) | (y == 10)) { + printf("That worked too.\n"); + } + return 0; + +} diff --git a/OSU Coursework/CS 161 - Intro to Programming I/Assignments/Assignment 2/perrenc_hw1_flowcharts.pdf b/OSU Coursework/CS 161 - Intro to Programming I/Assignments/Assignment 2/perrenc_hw1_flowcharts.pdf new file mode 100644 index 0000000..dcb63ea Binary files /dev/null and b/OSU Coursework/CS 161 - Intro to Programming I/Assignments/Assignment 2/perrenc_hw1_flowcharts.pdf differ diff --git a/OSU Coursework/CS 161 - Intro to Programming I/Assignments/Assignment 2/perrenc_hw1_pseudocode.txt b/OSU Coursework/CS 161 - Intro to Programming I/Assignments/Assignment 2/perrenc_hw1_pseudocode.txt new file mode 100644 index 0000000..aa352c3 --- /dev/null +++ b/OSU Coursework/CS 161 - Intro to Programming I/Assignments/Assignment 2/perrenc_hw1_pseudocode.txt @@ -0,0 +1,160 @@ +Corwin Perren - 931759527 +Assignment 2 - ECE151 +Pseudocode + + +--------Problem 1 ( 10.7 )-------- + +Clear the screen. +Initialize the variables dayloop and weekloop. +Initialize the array "mean" and fill it with zeros. + +Initialize and fill the array "hits" with the array data from the book. + +Sum all integers in the same column and store them in the corresponding +column of "mean". + +Divide each column of "mean" by the number of values that were summed and +store that number back onto that value of mean. + +Print out the values of "mean" for each day of the week. + +Pause until the user presses enter, then return to the menu. + + +--------Problem 2 ( 10.10 )-------- + +Clear the screen + +Initialize loop, centroidx, centroidy, and intenstity total. + +Initialize the arrays "pixel" and "intensity" and fill them with the values +from the book. + +Multiply each row of pixel by their respective column in intensity and sum +these onto centroidx and y respectively. + +Add all the intensity values together and store it on intensitytotal. + +Divide centroidx and y by intensitytotal and store the values back on those +those repective variables. + +Print the values of centroidx and y. + +Pause until the user presses enter, then return to menu. + + +--------Problem 3 ( 10.30 )-------- + +***Main Function*** + +Clear the screen. + +Initialize loop, searchreturn, and searchvalue with a binary value you want to +search for. + +Initialize the array "data" and fill it with made up binary numbers. + +Print a header for a printout of the current array. + +Print out the array "data". + +Call binarysearch and store its return value on searchreturn. + +If reutrnvalue is not equal to negative one, print a statement saying the +search was successful and the binary value was found, otherwise print a +statement saying the binary search failed and the value could not be found. + +Pause until the user presses enter, then return to the menu. + +***Binary Search Function*** + +Initialize loop. + +Search for a match of the binary value in each element of the array. If a +result is found, return at which element it was found, else return negative +one. + + +--------Problem 5 ( Matrix Multiplication )-------- + +Clear the screen. + +Initialize arraysize, loop1, loop2, and loop3. + +Ask the user for the size of the arrays they would like to multiply and store +that value on arraysize. + +Initialize array1, array2, and array3 as square arrays with arraysize as their +row and column sizes. + +Fill array1 and array2 with numbers and array3 with zeros. + +Print out a header for array1, then print array1. + +Print out a header for array2, then print array2. + +Make each element of array3 equal to the result of performing matrix +multiplication on array1 and array2. + +Print a header for array3, then print out array3. + +Pause until the user presses enter, then return to the menu. + + +--------Problem 6 ( Sieve of Eratosthenes )-------- + +Clear the screen + +Initialize userin1, loop1, loop2, loop3, and total. + +Ask the user for a number to calculate primes up to from zero, and store it on +userin1. + +Initialize the array "sieve" with a size one less than userin1. + +Fill "sieve" with integers from two to userin1. + +Mark all composites for each integer from two to the user entered number by making +that value in the array equal to zero. + +Print a header for the prime numbers that are left, then print out value from +the array that are not equal to zero while incrementing total. + +Print out the number of prime numbers printed from the last step by printing +total. + +Pause until the user presses enter, then return to the menu. + + +--------Problem 7 ( 11.6)-------- + +***Main Function*** + +Initialize arrays string1 and string2 and int loop. + +Clear the screen. + +Prompt the user to enter a string and store it on string1 after clearing the +buffer. + +Loop through each element of string1 until a newline character is found. +Replace the newline character with a null character to turn the array into a +string. + +Print out a header for string1 and the string itself. + +Call str_cpy on string1. + +Print a header for string2, then print the string itself. + +Pause until the user presses enter, then return to the menu. + +***Str_Copy Function*** + +Initialize loop. + +Copy each element from the source string to the destination string, then add a +null character to the end to keep it a string. + +Return the copied string. diff --git a/OSU Coursework/CS 161 - Intro to Programming I/Final/desktop/gradebook.db b/OSU Coursework/CS 161 - Intro to Programming I/Final/desktop/gradebook.db new file mode 100644 index 0000000..b360c7c --- /dev/null +++ b/OSU Coursework/CS 161 - Intro to Programming I/Final/desktop/gradebook.db @@ -0,0 +1,4 @@ +Shelby Estrada 3 Test1 78.000000 Test2 87.650000 Test3 76.540000 +Nick Newell 3 Test1 98.670000 Test2 92.560000 Test3 34.560000 +Corwin Perren 3 Test1 78.320000 Test2 98.000000 Test3 89.000000 +Will Seble 3 Test1 86.560000 Test2 89.900000 Test3 92.250000 diff --git a/OSU Coursework/CS 161 - Intro to Programming I/Final/desktop/perrenc_hw2.c b/OSU Coursework/CS 161 - Intro to Programming I/Final/desktop/perrenc_hw2.c new file mode 100644 index 0000000..10c3488 --- /dev/null +++ b/OSU Coursework/CS 161 - Intro to Programming I/Final/desktop/perrenc_hw2.c @@ -0,0 +1,104 @@ +/* + * Original Authors: Corwin A. Perren (perrenc) and Will H. Seble (seblew) + * File: perrenc_hw2.c + * Created: 2012 March 16, 22:20 by perrenc and seblew + * Last Modified: 2012 March 16, 22:20 by perrenc and seblew + * + * This is the main dot c file for a gradebook. It gives the user a menu and calls + * necessary funtions. + * + */ + +/* Includes */ +#include +#include +#include "perrenc_hw2.h" + +int main(int argc, char **argv){ + + int menuloop = 1; //Used to loop the menu + struct student *head = NULL; //Creates head node struct + + while(menuloop != 0){ + int menuchoice; // Used for selecting a menu item + + system("clear"); //Clears the screen + + /* Prints a pretty menu */ + printf("----------Gradebook Menu----------\n\n"); + printf("Please note: Some functions will require pressing enter "); + printf("multiple times\nin order to return to this menu.\n\n"); + printf("------------Read Write------------\n"); + printf("1 -- Load Gradebook from File\n"); + printf("2 -- Write Current Gradebook to File\n\n"); + printf("-------View Grades Statistics-----\n"); + printf("3 -- View Entire Gradebook\n"); + printf("4 -- View the First Student's Information/Assignments\n"); + printf("5 -- View the Last Student's Information/Assignments\n"); + printf("6 -- View a Student's Information/Assignments by Name Search\n"); + printf("7 -- View the n'th Student's Information/Assignments\n"); + printf("8 -- View a specific Student's Statistics\n"); + printf("9 -- View a specific Assignment's Statistics\n\n"); + printf("------------Add Grades------------\n"); + printf("10-- Add Assignment/s & Grade/s to Student\n\n"); + printf("---------Add Remove Students------\n"); + printf("11-- Add a New Student\n"); + printf("12-- Remove a Student\n\n"); + printf("-----------Extra Functions--------\n"); + printf("13-- Display the Number of Students in the Class\n"); + printf("14-- Exit Program\n\n"); + printf("Enter Selection: "); + scanf("%d", &menuchoice); + + /*Allows the user to choose a function to run*/ + switch(menuchoice){ + case 1: + head = read_from_file(head); + class_print(head); + break; + case 2: + write_to_file(head); + break; + case 3: + class_print(head); + break; + case 4: + print_head(head); + break; + case 5: + tail_print(head); + break; + case 6: + name_search_print(head); + break; + case 7: + print_nth(head); + break; + case 8: + student_statistics(head); + break; + case 9: + assignment_statistics(head); + break; + case 10: + update_assignments(head); + break; + case 11: + head = add_student(head); + break; + case 12: + head = remove_student(head); + break; + case 13: + num_students(head); + break; + case 14: + menuloop = 0; //Ends the program + break; + } + } + + printf("\n"); //Prints a newline to make things nice + system("clear"); //Clears the screen + return 0; +} diff --git a/OSU Coursework/CS 161 - Intro to Programming I/Final/desktop/perrenc_hw2.h b/OSU Coursework/CS 161 - Intro to Programming I/Final/desktop/perrenc_hw2.h new file mode 100644 index 0000000..775adf3 --- /dev/null +++ b/OSU Coursework/CS 161 - Intro to Programming I/Final/desktop/perrenc_hw2.h @@ -0,0 +1,787 @@ +/* + * Original Author: Corwin A. Perren (perrenc) and Will H. Seble (seblew) + * Contain code by: D. Kevin McGrath (dmcgrath) + * File: perrenc_hw2.h + * Created: 2012 March 16, 20:26 by perrenc and seblew + * Last Modified: 2012 March 16, 20:26 by perrenc and seblew + * + * This file includes all of the functions necessary to make a gradebook. + * It is called from perrenc_hw2.c + * + */ + +/* Includes */ +#include +#include +#include +#include +#include + +#ifndef perrenc_hw2 +#define perrenc_hw2 + +/* Defines */ + +/* --------------------Begin dmcgrath Functions-------------------- */ +/*These were copied directly off of the 311 code page*/ + +struct assignment{ + char *name; /*!< \brief string to hold the name of the assignment */ + double value; /*!< \brief hold the given score of the assignment, normalized */ +}; + +struct student{ + + struct student *next; + /*! \brief self referential pointer to link to nodes behind */ + struct student *previous; + + /*! \brief string to hold the first name of the student */ + char *first_name; + /*! \brief string to hold the last name of the student */ + char *last_name; + + /*! \brief pointer to the dynamic assignments array */ + struct assignment *assignments; + /*! \brief keep a count of the number of assignments */ + long int num_assignments; +}; + +struct stats{ + double mean; + double median; + double stddev; +}; + +int compare(const void *s, const void *t){ + int comp = 1; + + double is = *(double *)s; + double it = *(double *)t; + + if (is < it){ + comp = -1; + }else if (is == it){ + comp = 0; + } + + return comp; +} + +double median(double *list, long int length){ + double med = 0.0; + + /* use the built in quicksort function to sort the list to extract the median */ + /* requires the use of a function pointer */ + qsort(list, length, sizeof(double), compare); + + if (length % 2 == 0){ + /* if the list is an even length, return average of middle 2 elements*/ + med = list[length/2 - 1] + list[length/2]; + med /= 2.0; + }else{ + /* otherwise return the middle element (correct due to 0 offset) */ + med = list[length/2]; + } + + return med; +} + +double mean(double *list, long int length){ + double total = 0.0; + long int i; + + for (i = 0; i < length; ++i){ + total += list[i]; + } + + return total / length; +} + +double stddev(double *list, long int length){ + double mu = mean(list, length); + double sigma_2 = 0.0; + double square = 2.0; + int i; + + /* sum the deviants (squares of the differences from the average) */ + for (i = 0; i < length; ++i){ + sigma_2 += pow(list[i] - mu, square); + } + + sigma_2 /= (length - 1); + + return sqrt(sigma_2); +} + +/* --------------------End dmcgrath Functions-------------------- */ + +/* --------------------Begin perrenc Functions-------------------- */ + +/*This function is used to let a user manually add a student*/ +struct student* temp_student_userin(void){ + int loop = 0; //Used for looping + + system("clear"); //Clears screen + + struct student *tmp; //Tmp stuct to hold student + + /*Allocate space*/ + tmp = (struct student*) malloc(sizeof(struct student)); + tmp->first_name = (char *) malloc(100*sizeof(char)); + tmp->last_name = (char *) malloc(100*sizeof(char)); + + /*Get name of student*/ + printf("Please enter user's first name...\n"); + scanf("%s", tmp->first_name); + printf("Please enter user's last name...\n"); + scanf("%s", tmp->last_name); + + system("clear"); //Clear Screen + + /*Print student name, ask for number of assignments*/ + printf("The name you entered was: %s %s\n\n", tmp->first_name, tmp->last_name); + printf("How many assignments would you like to add for this user: "); + scanf("%d", &tmp->num_assignments); + printf("\n\n"); + + /*Allocate space for assignments*/ + tmp->assignments = (struct assignment*) malloc(tmp->num_assignments * sizeof(struct assignment)); + + /*Add assignments with names and grades*/ + for(loop = 0 ; loop < tmp->num_assignments ; loop++){ + + tmp->assignments[loop].name = (char *) malloc(100 * sizeof(char)); + + printf("Please enter the assignment %d name with no spaces: ", loop+1); + scanf("%s", tmp->assignments[loop].name); + printf("\n"); + + printf("Please enter the assignment grade: "); + scanf("%lf", &tmp->assignments[loop].value);; + printf("\n"); + + printf("You added assignment %s with grade %.2lf\n", tmp->assignments[loop].name + , tmp->assignments[loop].value); + printf("\n\n"); + } + return tmp; //Return new student +} + +/*This function is called to manually add a new student*/ +struct student* add_student(struct student *head){ + + struct student *tmp; //tmp student struct + struct student *cursor = head; //cursor struct + + tmp = temp_student_userin (); //gets new student + + /*insert sorts the new student into the gradbook*/ + while(1){ + if(head == NULL){ + head = tmp; + print_student(head); + pause(); + return head; + }else if((strcmp(tmp->last_name, cursor->last_name) < 0) | + (strcmp(tmp->last_name, cursor->last_name) == 0)){ + + if(cursor->previous == NULL){ + tmp->previous = NULL; + tmp->next = cursor; + cursor->previous = tmp; + head = tmp; + return head; + }else if(cursor->previous != NULL){ + tmp->previous = cursor->previous; + tmp->next = cursor; + cursor->previous->next = tmp; + tmp->next->previous = tmp; + return head; + } + + }else if(strcmp(tmp->last_name, cursor->last_name) > 0){ + + if(cursor->next != NULL){ + cursor = cursor->next; + }else{ + tmp->previous = cursor; + tmp->next = NULL; + cursor->next = tmp; + return head; + } + } + } +} + +/*This function resets pointers on surround students when one is removed*/ +struct student* remove_reset_pointers(struct student *cursor, struct student *head){ + int loop; //For loops + + /*Resets pointers on surrounding students depeind on whether the one that was + * removed was at the head/tail/or middle + */ + if((cursor->next == NULL) & (cursor->previous == NULL)){ + head = NULL; + }else if(cursor->next == NULL){ + cursor->previous->next = NULL; + }else if(cursor->previous == NULL){ + head = cursor->next; + cursor->next->previous = NULL; + }else{ + cursor->previous->next = cursor->next; + cursor->next->previous = cursor->previous; + } + + /*Frees the deleted student assignments*/ + for(loop = 0 ; loop < cursor->num_assignments ; loop++){ + free(cursor->assignments[loop].name); + } + + /*Frees the student struct entries and struct itself*/ + free(cursor->first_name); + free(cursor->last_name); + free(cursor->assignments); + free(cursor); + + return head; //Returns the new head +} + +/*This function is used to remove a student from the gradebook*/ +struct student* remove_student(struct student *head){ + struct student *cursor = head; //cursor struct + char *firstname = (char *) malloc(100 * sizeof(char)); //For user input + char *lastname = (char *) malloc(100 * sizeof(char)); //For user imput + int loop; //For looping + + system("clear"); //Clear Screen + + /*Asks the user which student they want to delete*/ + printf("Please enter student's first name to delete: "); + scanf("%s", firstname); + printf("\n"); + printf("Please enter student's last name to delete: "); + scanf("%s", lastname); + printf("\n\n"); + + /*Finds the student in the gradebook by name seach*/ + while(1){ + if(strcmp(cursor->last_name, lastname) != 0 ){ + if(cursor->next != NULL){ + cursor = cursor->next; + }else{ + system("clear"); + printf("No user by that name was found\n"); + pause(); + return NULL; + } + }else if(strcmp(cursor->last_name, lastname) == 0){ + if(strcmp(cursor->first_name, firstname) != 0){ + cursor = cursor->next; + }else if(strcmp(cursor->first_name, firstname) == 0){ + head = remove_reset_pointers(cursor, head); + return head; + } + } + + } + + +} + +/*This function is used by the read_file function to sort and place students in the + * gradebook. + */ +struct student* file_insert(struct student *head, struct student *tmp){ + + struct student *cursor = head; //cursor struct + + /* + * Determines wherer in the gradebook the student needs to be places, and puts them + * there. + */ + while(1){ + if(head == NULL){ + head = tmp; + return head; + }else if((strcmp(tmp->last_name, cursor->last_name) < 0) | + (strcmp(tmp->last_name, cursor->last_name) == 0)){ + + if(cursor->previous == NULL){ + tmp->previous = NULL; + tmp->next = cursor; + cursor->previous = tmp; + head = tmp; + return head; + }else if(cursor->previous != NULL){ + tmp->previous = cursor->previous; + tmp->next = cursor; + cursor->previous->next = tmp; + tmp->next->previous = tmp; + return head; + } + + }else if(strcmp(tmp->last_name, cursor->last_name) > 0){ + + if(cursor->next != NULL){ + cursor = cursor->next; + }else{ + tmp->previous = cursor; + tmp->next = NULL; + cursor->next = tmp; + return head; + } + } + } +} + +/* + * This function opens a file and turns it's input into structs to be placed in the + * gradbook, then places them there + */ +struct student* read_from_file(struct student *head){ + + struct student *tmp; //Tmp struct + FILE *gradebook; //File input stream + int loop; //For loops + + gradebook = fopen("gradebook.db", "r"); //Points file to stream + + /* + * Creates structs for each student in the file until a null character is recieved + * and then puts the students in the gradbook + */ + while(!feof(gradebook)){ + tmp = (struct student*) malloc(sizeof(struct student)); //Make space for student + tmp->first_name = (char *) malloc(100*sizeof(char)); //Make space for student + tmp->last_name = (char *) malloc(100*sizeof(char)); //Make space for student + + /*Fills struct with student data and assignment data*/ + if(fscanf(gradebook, "%s\t%s\t%d", tmp->first_name, tmp->last_name, + &tmp->num_assignments) == 3){ + tmp->assignments = (struct assignment*) + malloc(tmp->num_assignments * sizeof(struct assignment)); + + for(loop = 0 ; loop < tmp->num_assignments ; loop++){ + + tmp->assignments[loop].name = (char *) + malloc(100 * sizeof(char)); + fscanf(gradebook, "%s", tmp->assignments[loop].name); + fscanf(gradebook, "%lf", &tmp->assignments[loop].value); + } + head = file_insert(head, tmp); + }else{ + free(tmp->first_name); + free(tmp->last_name); + free(tmp); + } + } + + fclose(gradebook); + return head; +} + +/*This function writes the current gradebook to a file to be opened later*/ +int write_to_file(struct student *head){ + + struct student *cursor = head; //cursor struct + int loop; //for loops + + FILE *gradebook; //file stream + gradebook = fopen("gradebook.db", "w"); //points file to stream + + /*Properly formatas and places students into the file*/ + while(cursor != NULL){ + + fprintf(gradebook, "%s\t%s\t%d\t", cursor->first_name, cursor->last_name, + cursor->num_assignments); + for(loop = 0 ; loop < cursor->num_assignments ; loop++){ + if(loop < (cursor->num_assignments - 1)){ + fprintf(gradebook, "%s\t%lf\t", + cursor->assignments[loop].name, + cursor->assignments[loop].value); + }else{ + fprintf(gradebook, "%s\t%lf\n", + cursor->assignments[loop].name, + cursor->assignments[loop].value); + } + } + cursor = cursor->next; + } + fclose(gradebook); +} + +/*This function searches for the student the user specifies, then prints out their data*/ +int name_search_print(struct student *head){ + + struct student *cursor = head; //cursor struct + char *firstname = (char *) malloc(100 * sizeof(char)); //space for name + char *lastname = (char *) malloc(100 * sizeof(char)); //space for name + int loop; + + system("clear"); //clears screen + + /*Asks the user the student they'd like to print*/ + printf("Please enter student's first name: "); + scanf("%s", firstname); + printf("\n"); + printf("Please enter student's last name: "); + scanf("%s", lastname); + printf("\n\n"); + + /*finds student and prints them*/ + while(1){ + if(strcmp(cursor->last_name, lastname) != 0 ){ + if(cursor->next != NULL){ + cursor = cursor->next; + }else{ + system("clear"); + printf("No user by that name was found\n"); + pause(); + return 1; + } + }else if(strcmp(cursor->last_name, lastname) == 0){ + if(strcmp(cursor->first_name, firstname) != 0){ + cursor = cursor->next; + }else if(strcmp(cursor->first_name, firstname) == 0){ + system("clear"); + + printf + ("The searched user \"%s %s\" has %d assignment/s:\n\n", + cursor->first_name, cursor->last_name, + cursor->num_assignments); + + printf("Assignment Number\tName\t\tGrade %\n\n"); + for(loop = 0 ; loop < cursor->num_assignments ; loop++){ + printf("\t%d\t\t%s\t\t%.2lf\n", loop+1, + cursor->assignments[loop].name, + cursor->assignments[loop].value); + } + printf("\n\n"); + pause(); + return 0; + } + } + } +} + +/*This function prints the nth student*/ +int print_nth(struct student *head){ + + struct student *cursor = head; //cursor struct + int nth; //for user input + int loop; //for looping + + system("clear"); //clears screen + + /*asks which number the user would like to print*/ + printf("Which number in the list would you like to print?\n"); + printf("Lower numbers are last names closer to a...\n\n"); + printf("Please enter a number: "); + scanf("%d", &nth); + + /*moves cursor to that location*/ + for(loop = 0 ; loop < (nth-1) ; loop++){ + cursor = cursor->next; + } + + /*prints out that student*/ + system("clear"); + printf("\"%s %s\" has %d assignment/s and is user #%d:\n\n", cursor->first_name, + cursor->last_name, cursor->num_assignments, nth); + + printf("Assignment Number\tName\t\tGrade %\n\n"); + for(loop = 0 ; loop < cursor->num_assignments ; loop++){ + printf("\t%d\t\t%s\t\t%.2lf\n", loop+1, cursor->assignments[loop].name, + cursor->assignments[loop].value); + } + printf("\n\n"); + pause(); + +} + +/*prints the last item in the gradebook*/ +int tail_print(struct student *head){ + int loop; //for looping + struct student *cursor = head; //cursor struct + + system("clear"); //clears the screen + + /*moves the cursor to the last position and prints it*/ + while(1){ + if(cursor->next != NULL){ + cursor = cursor->next; + }else{ + printf("The tail/last user \"%s %s\" has %d assignment/s:\n\n", + cursor->first_name, cursor->last_name, cursor->num_assignments); + printf("Assignment Number\tName\t\tGrade %\n\n"); + for(loop = 0 ; loop < cursor->num_assignments ; loop++){ + printf("\t%d\t\t%s\t\t%.2lf\n", loop+1, + cursor->assignments[loop].name, + cursor->assignments[loop].value); + } + printf("\n"); + pause(); + return 0; + } + } +} + +/*Prints the entire gradebook*/ +int class_print(struct student* head){ + struct student *cursor = head; //cursor struct + int loop; //looping + + system("clear"); //clears the screen + + /*prints a header and all students and assignments in the class*/ + printf("--------- Class Gradebook ----------\n\n"); + while(cursor != NULL){ + printf("%s, %s\t\t",cursor->last_name, cursor->first_name); + for(loop = 0 ; loop < cursor->num_assignments ; loop++){ + printf("%s\t%.2lf\t", cursor->assignments[loop].name, + cursor->assignments[loop].value); + } + printf("\n"); + cursor = cursor->next; + } + printf("\n"); + pause(); +} + +//prints out a students information after they've been entered manually*/ +int print_student(struct student *tmp){ + int loop; //for looping + + system("clear"); //clears the screen + + /*prints out all user's information and assignments*/ + printf("The user \"%s %s\" has %d assignment/s:\n\n", tmp->first_name, + tmp->last_name, tmp->num_assignments); + printf("Assignment Number\tName\t\tGrade %\n\n"); + for(loop = 0 ; loop < tmp->num_assignments ; loop++){ + printf("\t%d\t\t%s\t\t%.2lf\n", loop+1, tmp->assignments[loop].name, + tmp->assignments[loop].value); + } + printf("\n"); + pause(); +} + +/*prints the student at the beginning of the list*/ +int print_head(struct student *head){ + int loop; //for looping + + system("clear"); //clears the screen + +/*prints out that user's information and assignments*/ + printf("The head/first user \"%s %s\" has %d assignment/s:\n\n", head->first_name, + head->last_name, head->num_assignments); + printf("Assignment Number\tName\t\tGrade %\n\n"); + for(loop = 0 ; loop < head->num_assignments ; loop++){ + printf("\t%d\t\t%s\t\t%.2lf\n", loop+1, head->assignments[loop].name, + head->assignments[loop].value); + } + printf("\n"); + pause(); +} + +/*This function lets a user add an assignment to a user*/ +int update_assignments(struct student *head){ + struct student *cursor = head; //cursor struct + char *firstname = (char *) malloc(100 * sizeof(char)); //space for name + char *lastname = (char *) malloc(100 * sizeof(char)); //space for name + int loop = 0; //for looping + + + + system("clear"); //clears the screen + + /*asks the user for the student's name*/ + printf("Please enter student's first name: "); + scanf("%s", firstname); + printf("\n"); + printf("Please enter student's last name: "); + scanf("%s", lastname); + printf("\n\n"); + + /*finds the student and lets the user enter a new assignment and grade*/ + while(1){ + if(strcmp(cursor->last_name, lastname) != 0 ){ + if(cursor->next != NULL){ + cursor = cursor->next; + }else{ + system("clear"); + printf("No user by that name was found\n"); + pause(); + return 1; + } + }else if(strcmp(cursor->last_name, lastname) == 0){ + if(strcmp(cursor->first_name, firstname) != 0){ + cursor = cursor->next; + }else if(strcmp(cursor->first_name, firstname) == 0){ + + cursor->assignments[cursor->num_assignments].name = ( + char *) malloc(100 * sizeof(char)); + + printf("Please enter the assignment name with no spaces: "); + scanf("%s", cursor->assignments[cursor->num_assignments].name); + printf("\n"); + + printf("Please enter the assignment grade: "); + scanf("%lf", &cursor->assignments[cursor->num_assignments].value); + printf("\n"); + + printf("You added assignment %s with grade %.2lf\n", + cursor->assignments[loop].name, cursor->assignments[loop].value); + + printf("\n\n"); + + cursor->num_assignments = (1 + cursor->num_assignments); + return 0; + } + } + } +} + +/*determines and prints the numer of students in the gradebook*/ +int num_students(struct student *head){ + + struct student *cursor = head; //cursor struct + int numstudents = 0; //for storing num of students + + /*loops through until null and incriments*/ + while(cursor != NULL){ + cursor = cursor->next; + numstudents++; + } + + system("clear"); //clears the screen + + /*prints out the number of students*/ + printf("There are %d students in the class.\n\n", numstudents); + pause(); + return numstudents; +} + +/*this prints the statistics for a specific assignment for all users in teh class*/ +int assignment_statistics(struct student *head){ + + struct student *cursor = head; //cursor struct + char *assignmentname; //for user specification + int loop; //for looping + int length = 0; //num of values stored + int numassignments = 0; + + /*determines max num of assignments*/ + while(cursor != NULL){ + cursor = cursor->next; + numassignments++; + } + + double stats[numassignments]; //makes array for values + + system("clear"); //clears the screen + + assignmentname = (char *) malloc(100*sizeof(char)); + + /*asks for the assignment name*/ + printf("Please enter the name of the assignment you'd like statistics for: "); + scanf("%s", assignmentname); + + /*compiles data into array*/ + cursor = head; + while(cursor != NULL){ + for(loop = 0 ; loop < cursor->num_assignments ; loop++){ + if(strcmp(cursor->assignments[loop].name, assignmentname) == 0){ + stats[length] = cursor->assignments[loop].value; + length++; + } + } + cursor = cursor->next; + } + + if(length == 0){ + system("clear"); + printf("There was no assignment by that name..."); + system("sleep 6"); + } + + /*prints out statistics after sending data and length tho those functions*/ + system("clear"); + printf("The mean for assignment \"%s\" is \"%.2lf%\".\n", assignmentname, + mean(stats, length)); + printf("The median for assignement\"%s\" is \"%.2lf%\".\n", assignmentname, + median(stats, length)); + printf("The standard deviation for assignment \"%s\" is \"%.2lf%\".\n", + assignmentname, stddev(stats, length)); + + free(assignmentname); + pause(); +} + +/*prints out statistics for a specifc user on all assignments*/ +int student_statistics(struct student *head){ + struct student *cursor = head; //cursor struct + char *firstname = (char *) malloc(100 * sizeof(char)); //space for name + char *lastname = (char *) malloc(100 * sizeof(char)); //space for name + int loop; //for loops + int length = 0; //for # of data + double stats[50]; //for holding data + + system("clear"); //clears the scren + + /*asks for the student's name*/ + printf("Please enter student's first name: "); + scanf("%s", firstname); + printf("\n"); + printf("Please enter student's last name: "); + scanf("%s", lastname); + printf("\n\n"); + + /*finds the student, compiles data, and prints out statistics*/ + while(1){ + if(strcmp(cursor->last_name, lastname) != 0 ){ + if(cursor->next != NULL){ + cursor = cursor->next; + }else{ + system("clear"); + printf("No user by that name was found\n"); + pause(); + return 1; + } + }else if(strcmp(cursor->last_name, lastname) == 0){ + if(strcmp(cursor->first_name, firstname) != 0){ + cursor = cursor->next; + }else if(strcmp(cursor->first_name, firstname) == 0){ + for(loop = 0 ; loop < cursor->num_assignments ; loop++){ + stats[length] = cursor->assignments[loop].value; + length++; + } + system("clear"); + printf("The mean for student \"%s %s\" is \"%.2lf%\".\n", + firstname, lastname, mean(stats, length)); + printf("The median for student \"%s %s\" is \"%.2lf%\".\n" + , firstname, lastname, median(stats, length)); + printf("The standard deviation for student \"%s %s\" is " + , firstname, lastname); + printf("\"%.2lf%\".\n", stddev(stats, length)); + pause(); + return 0; + } + } + } +} + /* Generic Functions */ + +/*pauses until user hits enter*/ +int pause(void){ + printf("Press enter to return to the menu."); + getchar(); + while('\n' != getchar()){ + ; //VOID + } +} + +/* --------------------End perrenc Functions-------------------- */ + +#endif diff --git a/OSU Coursework/CS 161 - Intro to Programming I/Final/Makefile b/OSU Coursework/CS 161 - Intro to Programming I/Final/wunderboard/Makefile similarity index 100% rename from OSU Coursework/CS 161 - Intro to Programming I/Final/Makefile rename to OSU Coursework/CS 161 - Intro to Programming I/Final/wunderboard/Makefile diff --git a/OSU Coursework/CS 161 - Intro to Programming I/Final/adc.c b/OSU Coursework/CS 161 - Intro to Programming I/Final/wunderboard/adc.c similarity index 100% rename from OSU Coursework/CS 161 - Intro to Programming I/Final/adc.c rename to OSU Coursework/CS 161 - Intro to Programming I/Final/wunderboard/adc.c diff --git a/OSU Coursework/CS 161 - Intro to Programming I/Final/adc.h b/OSU Coursework/CS 161 - Intro to Programming I/Final/wunderboard/adc.h similarity index 100% rename from OSU Coursework/CS 161 - Intro to Programming I/Final/adc.h rename to OSU Coursework/CS 161 - Intro to Programming I/Final/wunderboard/adc.h diff --git a/OSU Coursework/CS 161 - Intro to Programming I/Final/main.c b/OSU Coursework/CS 161 - Intro to Programming I/Final/wunderboard/main.c similarity index 100% rename from OSU Coursework/CS 161 - Intro to Programming I/Final/main.c rename to OSU Coursework/CS 161 - Intro to Programming I/Final/wunderboard/main.c diff --git a/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 1/Lab1 b/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 1/Lab1 new file mode 100644 index 0000000..94e6ae5 Binary files /dev/null and b/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 1/Lab1 differ diff --git a/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 1/a.out b/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 1/a.out new file mode 100644 index 0000000..9b8d0f5 Binary files /dev/null and b/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 1/a.out differ diff --git a/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 1/a3.out b/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 1/a3.out new file mode 100644 index 0000000..94e6ae5 Binary files /dev/null and b/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 1/a3.out differ diff --git a/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 1/main.c b/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 1/main.c new file mode 100644 index 0000000..9ca878c --- /dev/null +++ b/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 1/main.c @@ -0,0 +1,9 @@ +#include + +int main (void) { + + printf("User:perrenc\nName:Corwin\nFavorite Color:Dark Neon Green\n"); + + return 0; + +} diff --git a/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 1/test b/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 1/test new file mode 100644 index 0000000..94e6ae5 Binary files /dev/null and b/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 1/test differ diff --git a/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 2/Lab2 b/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 2/Lab2 new file mode 100644 index 0000000..438d94d Binary files /dev/null and b/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 2/Lab2 differ diff --git a/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 2/lab2.c b/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 2/lab2.c new file mode 100644 index 0000000..b5dd311 --- /dev/null +++ b/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 2/lab2.c @@ -0,0 +1,85 @@ +/** +Change Machine Source File for Lab2 in CS 151 +Made by Corwin Perren + +Takes a money amount as an input and tells you the appropriate number of each bill and +coin less than or equal to $20 increments to make up total amount. +*/ + +#include /** Include the stdio.h file to allow for printf() to be used*/ + +/** @brief Main Function + @param void This function does not accept any input variables + @return This function would return an error code to the OS if needed. +*/ +int main (int argc, char **argv) { + +/** Original money amount and all bill/coin variables. x is used for manipulation of +the original amount. +*/ + double i = 00.00; /* initial input variable */ + int twenties = 0; /* $20 variable */ + int tens = 0; /* $10 variable */ + int fives = 0; /* $5 variable */ + int ones = 0; /* $1 variable */ + int quarters = 0; /* $.25 variable */ + int dimes = 0; /* $.1 variable */ + int nickels = 0; /* $.05 variable */ + int pennies = 0; /* $.01 variable */ + int x = 0; /* used for the running total as the code progresses */ + + system("clear"); /** Clears the screen */ + + /** Prompts the user for a numerical input, stores it, multiplies it by 100, then + stores that value as an integer on x. + */ + printf("Please enter the amount of money to make change for: "); + scanf("%lf",&i); + i = i*100 ; + x = (int)i; + + /** Takes the money amount, determines the number of each bill or coin, and subtracts + that number of bills from the total amount to calculate the next amount. + */ + twenties = x/2000; + x = x-twenties*2000; + tens = x/1000; + x = x-tens*1000; + fives = x/500; + x = x-fives*500; + ones = x/100; + x = x-ones*100; + quarters = x/25; + x = x-quarters*25; + dimes = x/10; + x = x-dimes*10; + nickels = x/5; + x = x-nickels*5; + pennies = x/1; + + system("clear"); /** Clears the screen */ + + /** Print the original input amount, then the number of bills/coins needed only + if that number is not zero. + */ + printf("%.2lf - Original Amount\n\n", (i/100)); + if (twenties != 0){ + printf("%i - Twenties\n",twenties); + }if (tens != 0){ + printf("%i - Tens\n",tens); + }if (fives != 0){ + printf("%i - Fives\n",fives); + }if (ones != 0){ + printf("%i - Ones\n",ones); + }if (quarters != 0){ + printf("%i - Quarters\n",quarters); + }if (dimes != 0){ + printf("%i - Dimes\n",dimes); + }if (nickels != 0){ + printf("%i - Nickels\n",nickels); + }if (pennies != 0){ + printf("%i - Pennies\n",pennies); + } + + return (0); +} diff --git a/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 3/Lab3 b/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 3/Lab3 new file mode 100644 index 0000000..0818a06 Binary files /dev/null and b/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 3/Lab3 differ diff --git a/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 3/Lab3_extended b/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 3/Lab3_extended new file mode 100644 index 0000000..ed8f33b Binary files /dev/null and b/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 3/Lab3_extended differ diff --git a/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 3/lab3.c b/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 3/lab3.c new file mode 100644 index 0000000..97c3df2 --- /dev/null +++ b/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 3/lab3.c @@ -0,0 +1,50 @@ +/** ECE 151 Lab 3 Source File + * Modified by Corwin Perren + */ + +#include /** included to allow for printf() to be used*/ +#include /** included to allow time() to be used*/ +#include /** include to allow rand() and srand() to be used*/ +/** @brief main Function +@param void This function does not accept any input variables +@return This function would return an error code to the OS if needed. +*/ +int main(int argc, char **argv) { + + srand(time(NULL)); /* seed the number generator */ + int x = rand(); /* variable to hold our random integer */ + int i = 0; /* varaible used for user input */ + int guesses = 0; /* used to track number of user guesses */ + +/* keeps randomizing x until it reaches a value under 50 */ + while (x > 50) { + x = rand(); + } + +/* clears the terminal and asks the user for an input */ + system ("clear"); + printf("What is your guess for the random number under 50?\n", x); + + +/* loops through asking the user for guesses until five guesses have been made */ + while (guesses < 5){ + + scanf ("%d", &i); /* takes in user input */ + if (i < x) { +/* prints if the user's value is less than x */ + system("clear"); + printf("Your guess is too low.\n"); + }else if (i == x) { +/* prints if the user's value is x, then breaks */ + system("clear"); + printf("You guessed right!\n"); + break; + }else if (i > x) { +/* prints if the user's value is larger than x */ + system("clear"); + printf("Your guess is too high.\n"); + } + + guesses = ++guesses; /* incriments the number of guesses the user has made */ +} +} diff --git a/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 3/lab3_extended.c b/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 3/lab3_extended.c new file mode 100644 index 0000000..a0bcf6e --- /dev/null +++ b/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 3/lab3_extended.c @@ -0,0 +1,73 @@ +/* + * Original Author: Corwin A. Perren (perrenc) + * File: lab3_extended.c + * Created: 2012 January 26, 13:42 by perrenc + * Last Modified: 2012 February 2, 01:31 by perrenc + * + * This program tries to guess a number the user has though of. + * It has five tries before erroring out. + */ + +#include /** included to allow for printf() to be used*/ +#include /** included to allow time() to be used*/ +#include /** include to allow rand() and srand() to be used*/ +/** @brief main Function +@param void This function does not accept any input variables +@return This function would return an error code to the OS if needed. +*/ +int main (int argc, char **argv) { + + srand(time(NULL)); /* seed the number generator */ + int x = 0; /* variable to hold our random integer */ + int i = 0; /* variable used for user input */ + int guesses = 0; /* used to track number of user guesses */ + int max = 51; /* used as a ceiling for guesses */ + int min = 0; /* used as a floor for guesses */ + +/* Keeps randomizing x until it reaches a value under 50 */ + x = rand()%51; /* assigns a value to x less than or equal to 50 that is random */ + system("clear"); /* clears the screen */ + +/* Loops through asking the user for guesses until five guesses have been made */ + while (guesses < 5){ + +/* Increments the number of guesses, asks the user about how close the computer is to + * guessing the number, then takes the users response, narrows its guess range by + * changing upper or lower limits, then randomly guesses a new value withing that range. + * After guessing right, it prints success, otherwise after five tries it prints that it + * lost. + */ + guesses = ++guesses; + printf("Is your number %d? Enter 1 for too low, 2 for correct, or 3 for too high: ", x); + scanf("%i", &i); + if(i == 1){ + min = ++x; /* adjusts guess floor */ + if(max == min){ /* is about to guess the right value + and avoids dividing by zero */ + x = min; + continue; + } + x = rand()%(max-min) + min; /* used to make a guess within a range */ + }else if (i == 2){ + printf("Yay! I guessed right!\n"); + break; + }else if (i == 3){ + max = --x; /* adjusts guess ceiling */ + if(max == min){ /* same as previous one */ + x = min; + continue; + } + x = rand()%(max-min) + min; /* used to make a guess within a + range */ + }else if (x != (3 | 2 | 1)){ /* prints an error if uncorrect values are + entered */ + printf("You have entered an incorrect value, please try again.\n"); + guesses -= 1; + } + } + if (i != 2){ /* prints that the computer lost */ + printf("Awww, I lost.\n"); + } + +} + diff --git a/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 4/division b/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 4/division new file mode 100644 index 0000000..a9f04cb Binary files /dev/null and b/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 4/division differ diff --git a/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 4/division.c b/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 4/division.c new file mode 100644 index 0000000..99f2a05 --- /dev/null +++ b/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 4/division.c @@ -0,0 +1,53 @@ +/* + * Original Author: Corwin A. Perren (perrenc) + * File: division.c + * Created: 2012 February 8, 16:58 by perrenc + * Last Modified: 2012 February 8, 23:15 by perrenc + * + * Has the user enter two integers, swaps them if the second one entered is larger than + * the first one, then divides the first by the second, first mod second, and the first + * by the second as doubles. It then prints out these values along with the equation. + */ + +#include + +int main(int argc, char **argv) { + + int userint1; //User input 1 + int userint2; //User input 2 + int swap; //Used for swapping input 1 and 2 if 2 is larger than 1 + double double1; //Used for making a double of userint1 + double double2; //Used for making a double of userint2 + +//Clears the screen, and asks the user to enter the two integers + system("clear"); + printf("Please enter an integer: "); + scanf("%d", &userint1); + printf("Please enter a second integer: "); + scanf("%d", &userint2); + +//Swaps userint1 and userint2 if userint2 is larger than userint1 + if(userint2 > userint1){ + swap = userint1; + userint1 = userint2; + userint2 = swap; + } + +//Prints and error and ends the program if you try and divide by zero + if(userint2 == 0){ + printf("\nYou cannot divide by zero, program ending...\n\n"); + return(1); + } + +//Prints userint1/userint2 and userint1 mod userint2 + printf("\n%d / %d = %d\n", userint1, userint2, (userint1 / userint2)); + printf("%d %% %d = %d\n", userint1, userint2, (userint1 % userint2)); + +//Converts userint1 and 2 to doubles + double1 = userint1; + double2 = userint2; + +//Prints double1/double2 + printf("%lf / %lf = %lf\n\n", double1, double2, (double1 / double2)); + +} diff --git a/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 4/lab4_1 b/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 4/lab4_1 new file mode 100644 index 0000000..ddbaf1f Binary files /dev/null and b/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 4/lab4_1 differ diff --git a/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 4/lab4_1.c b/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 4/lab4_1.c new file mode 100644 index 0000000..68f4392 --- /dev/null +++ b/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 4/lab4_1.c @@ -0,0 +1,58 @@ +/* + * Original Author: Corwin A. Perren (perrenc) + * File: lab4_1.c + * Created: 2012 February 6, 15:10 by perrenc + * Last Modified: 2012 February 8, 23:00 by perrenc + * + * Asks the user for five floating point values, and prints them + * if all are entered correctly, else it ends the program. + */ + +#include + +int main(int argc, char **argv) { + + double f1 = -1.0; //First user float value + double f2 = -1.0; //Second user float value + double f3 = -1.0; //Third user float value + double f4 = -1.0; //Fourth user float value + double f5 = -1.0; //Fifth user float value + +// Clears the screen, then explains what needs to be entered, and what will be printed. + system("clear"); + printf("I am going to ask you to enter 5 different positive floating point numbers.\n"); + printf("I will end the program as soon as you enter a negative value or a repeat number.\n"); + printf("I will congratulate you and print out the 5 numbers if you successfully complete the task.\n\n"); + +/* Has the user input five values, and quits the program if an entered number is negative + * or if two numbers entered in a row are the same. If the values are entered correctly, + * it prints out the five values the user entered. + */ + printf("Please enter your first number. "); + scanf("%lf", &f1); + if(f1 < 0){ + return(0); + } + printf("Please enter your second number. "); + scanf("%lf", &f2); + if((f2 == f1) | (f2 < 0)){ + return(0); + } + printf("Please enter your third number. "); + scanf("%lf", &f3); + if((f3 == f2) | (f3 < 0)){ + return(0); + } + printf("Please enter your fourth number. "); + scanf("%lf", &f4); + if((f4 == f3) | (f4 < 0)){ + return(0); + } + printf("Please enter your fifth number. "); + scanf("%lf", &f5); + if((f5 == f4) | (f5 < 0)){ + return(0); + } + printf("\nYour numbers were: %lf, %lf, %lf, %lf, %lf\n\n", f1, f2, f3, f4, f5); + +} diff --git a/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 4/lab4_2 b/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 4/lab4_2 new file mode 100644 index 0000000..c9e0660 Binary files /dev/null and b/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 4/lab4_2 differ diff --git a/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 4/lab4_2.c b/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 4/lab4_2.c new file mode 100644 index 0000000..5812117 --- /dev/null +++ b/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 4/lab4_2.c @@ -0,0 +1,43 @@ +/* + * Original Author: Corwin A. Perren (perrenc) + * File: lab4_2.c + * Created: 2012 February 8, 16:58 by perrenc + * Last Modified: 2012 February 8, 23:09 by perrenc + * + * Asks the users for a number between 1 and 20 and prints up to that number from one + * and down to one from that number. + * It errors if the value is not within this range. + */ + +#include + +int main(int argc, char **argv) { + + int userinput; //Variable for user input + int loop; //Used for looping + +// Clears the screen and asks the user to input an integere between one and twenty + system("clear"); + printf("Please enter an integer between 1 and 20: "); + scanf("%d", &userinput); + +// Quits the program if an incorrect value has been entered + if((1 > userinput) | (userinput > 20)){ + printf("You have entered an incorrect value, closing program...\n"); + return(-1); + } + +//Prints up from one to the user entered value + for(loop = 1 ; (loop <= userinput) ; ++loop){ + printf("%d ", loop); + } +//Prints newline + printf("\n"); + +//Prints down to one from the user entered number + for(loop = userinput ; ((loop <= userinput) & (loop != 0)) ; loop--){ + printf("%d ", loop); + } +//Prints a newline + printf("\n"); +} diff --git a/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 4/lab4_4 b/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 4/lab4_4 new file mode 100644 index 0000000..7356df3 Binary files /dev/null and b/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 4/lab4_4 differ diff --git a/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 4/lab4_4.c b/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 4/lab4_4.c new file mode 100644 index 0000000..75ebf25 --- /dev/null +++ b/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 4/lab4_4.c @@ -0,0 +1,58 @@ +/* Original Author: Corwin Perren (perrenc) + * File: lab4_4.c + * Created: 2012 February 08, 21:05 by perrenc + * Last modified: 2012 February 08, 23:23 by perrenc + * + * Purposefully used for making and correcting errors + */ + +#include + +int main(int argc, char **argv) { + + /*creates the user input and incrementing variables*/ + int i; + int loop; + + system("clear"); + printf("Enter an integer between 1 and 20:\n"); + scanf("%d", &i); + + /*errors and exits if i is greater than 20 or less than one*/ + if((1 > i) | (i > 20)){ + printf("You have entered an incorrect value.\n"); + return(-1); + } + /*prints ascending characters from one up to the user entered value*/ + for (loop = 1; (loop <= i); ++loop){ + printf("%d ", loop); + } + + printf("\n"); + + /*prints descending characters from the user entered value down to 1*/ + for(loop = i; ((loop <= i) & (loop != 0)); loop--){ + printf("%d ", loop); + } + printf("\n"); +} + +/*error listings + * Removed semicolon at line 23: "expected ; before return" + * Commented out variable i on line 14: "i undeclared (first use in this function. + Each undeclared identifier is reported only once for each function it appears in." + * Removed braces from the following if function: "expected } before else" + +int extra() { + if(x < 3) { + printf("x is less than 3.\n"); + printf("you fart loudly."); + else + printf("x is not less than 3.\n"); + printf("et cetera\n"); +} +} + * Removed parentheses from line 27: "expected ( before loop + expected ; before { token" + * Passed wrong type to line 28: It compiled, but output was empty. + */ diff --git a/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 5/flush b/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 5/flush new file mode 100644 index 0000000..58ea830 Binary files /dev/null and b/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 5/flush differ diff --git a/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 5/flush.c b/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 5/flush.c new file mode 100644 index 0000000..0056442 --- /dev/null +++ b/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 5/flush.c @@ -0,0 +1,47 @@ +/* + * Original Author: Corwin A. Perren (perrenc) + * File: flush.c + * Created: 2012 February 16, 03:11 by perrenc + * Last Modified: 2012 February 16, 03:11 by perrenc + * + * Has the user input some text, prints out the first character entered along with its + * ascii code and then reruns until it receives a "%" character. + * + */ + +#include + +/* ------Begin Functions------ */ + +/*Has the user input text, uses getchar to store the first character, then loops through + * getchar until the buffer is clear when it receives a "\n". */ +char getchar_and_flush(){ + char foo; //Used for temp user input storage + int loop; //Used for looping to clear the buffer + + printf("Please enter some text. Press enter to finish. To quit, type a \"%\" symbol. "); + foo = getchar (); + loop = foo; + while(loop != '\n'){ + loop = getchar (); + } + return foo; +} + + +/* ------End Functions------ */ + +/* Initalizes foo, clears the screen, then calls getchar_and_flush until the return + * character is "%" */ +int main(int argc, char **argv){ + + char foo; //Used to check the return value of getchar_and_flush for looping + + system("clear"); + + while(foo != '%'){ + foo = getchar_and_flush(); + printf("\nThe first character was %c or %d in ASCII.\n\n", foo, foo); + } + return 0; +} diff --git a/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 5/lab5 b/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 5/lab5 new file mode 100644 index 0000000..5cef5e9 Binary files /dev/null and b/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 5/lab5 differ diff --git a/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 5/lab5.c b/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 5/lab5.c new file mode 100644 index 0000000..791e44c --- /dev/null +++ b/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 5/lab5.c @@ -0,0 +1,125 @@ +/* + * Original Author: Corwin A. Perren (perrenc) + * File: lab5.c + * Created: 2012 February 16, 00:22 by perrenc + * Last Modified: 2012 February 16, 00:22 by perrenc + * + * This program asks the user for two values, counts up to it from zero, down to zero + * from it, and bewteen the two values. It then asks whether the user would like to + * run the program again. + */ + +#include + +/* ------Begin Functions------ */ + +/* Begin user input functions */ + +/* Asks the user for a positive integer and returns it */ +int userinput1(void){ + int a; // For temp user input storage + system("clear"); + printf("Please enter your first positive integer: "); + scanf("%d", &a); + return a; +} + +/* Asks the user for another positive integer and returns it */ +int userinput2(void){ + int a; // For temp user input storage + printf("Please enter your second positive integer: "); + scanf("%d", &a); + return a; +} + +/* End user input functions */ + +/* Begin Math Functions */ + +/* Receives the first integer from the user and counts up from 0 to it with integers */ +int count_up(int userin1){ + int loop; //Used for loop incrementing + for(loop = 0 ; loop <= userin1 ; loop++){ + printf("%d ", loop); + } + printf("\n"); +} + +/* Counts down to zero by integers from the first integer entered by the user */ +int count_down(int userin1){ + int loop; //Used for loop incrementing + for(loop = userin1 ; loop >= 0 ; loop--){ + printf("%d ", loop); + } + printf("\n"); +} + +/* Counts from the smaller number up to the larger one based on those entered by + * the user */ +int count_between_up(int userin1, int userin2){ + int loop; //Used for loop incrementing + for(loop = userin1 ; loop <= userin2 ; loop++){ + printf("%d ", loop); + } + printf("\n"); +} + +/* Counts down from the larger number to the smaller one from those entered by the user */ +int count_between_down(int userin1, int userin2){ + int loop; //Used for loop incrementing + for(loop = userin1 ; loop >= userin2 ; loop--){ + printf("%d ", loop); + } + printf("\n"); +} + +/* End Math Functions */ + +/* Begin Generic Functions */ + +/* Assigns the user inputs to variables, counts up, then down, then counts up or down + * between the two entered number depending on which of the two is larger */ +void task1(void){ + + int userin1 = userinput1 (); + int userin2 = userinput2 (); + + count_up (userin1); + count_down (userin1); + + if (userin1 < userin2){ + count_between_up (userin1, userin2); + }else if (userin1 > userin2){ + count_between_down (userin1, userin2); + } +} + +/* Used for quitting or rerunning the program per user request */ +int quittask1(void){ + + int endtask1; + + printf("\nWould you like to run again? Type 0 for no or 1 for yes: "); + scanf("%d", &endtask1); + + return endtask1; +} + +/* ------End Functions------ */ + +/* Runs task 1 from above and determines whether the program should exit or rerun based + * on the return value from quittask1. To rerun, a goto is used since I could not get + * loops to work. */ +int main(int argc, char **argv){ + + begintask1: ; + task1 (); + int endtask1 = quittask1 (); + if(endtask1 == 0){ + //Break + }else if(endtask1 == 1){ + goto begintask1; + } + + return 0; +} diff --git a/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 6/Section6.pdf b/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 6/Section6.pdf new file mode 100644 index 0000000..305186f Binary files /dev/null and b/OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 6/Section6.pdf differ