Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Part2
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Matthew Danielson
7/6/16
Questions for Assignment 6

1) There will be a bunch of erros, as this code attempts to assign values within the struct definition, and then later attempts to assign values to said values - both of which are not legal actions.

2) Enumerations deal exclusively with constants, and are useful in a situation where words such as JAN or FEB make a code more readable than simply just an array of increasing integers. Strucutres, on the other hand, are able to store many data types -precursor of OOD - and are very functional in any code that needs data storage that isn't strictly of one type in one location.

3) When an array is passed directly to a function, it cannot be returned as its reference is being passed, and array is directly altered. However, when an array is passed within a structure, its values are passed instead and are altered locally, and are only changed if its structure is returned.
92 changes: 92 additions & 0 deletions banking.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/* Matthew Danielson
* 7/6/16
* banking.c
* two bank accounts, transacts between them
*/

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
typedef struct{
int number;
int balance;
char name[25];
} account;


account withdraw(account, int);
account deposit(account, int);
account create(int, int, char []);

int main(){
srand(time(NULL));
printf("Welcome to Banking! \n");
int whiletrue = 1;
int check;
char name[25];
int number;
int balance;
account accounts[10];
int count=0;
int reference;
int quantity;
char throwaway;
while(whiletrue){
printf("Enter 1 to make an account, 2 to deposit, 3 to withdraw, 4 to view, and 5 to quit: ");
scanf("%d", &check);
scanf("%c", &throwaway);
if(check == 1){
number = count;
printf("\nYour account number is %d",number+1);
printf("\nPlease enter your name:");

fgets(name, sizeof(name), stdin);
//
printf("\nPlease enter a balance: ");
scanf("%d", &balance);
scanf("%c", &throwaway);
accounts[count].number = number;
accounts[count].balance = balance;
strcpy(accounts[count].name, name);
count++;
}
if(check == 2 || check == 3){
printf("\nAccount number?");
scanf("%d", &reference);
scanf("%c", &throwaway);
printf("\nAmount?");
scanf("%d", &quantity);
scanf("%c", &throwaway);
reference--;
if(check == 2)
accounts[reference] = deposit(accounts[reference], quantity);
if(check == 3)
accounts[reference] = withdraw(accounts[reference], quantity);
}
if(check == 4){
printf("\nAccount number?");
scanf("%d", &reference);
reference--;
printf("\nName: %s", accounts[reference].name);
printf("\nAccount Number: %d", reference+1);
printf("\nBalance: %d\n", accounts[reference].balance);
}
if(check ==5){
printf("\nThank you for using Banking(TM)\n");
exit(0);
}
}

}

account deposit(account account1, int quantity){
account1.balance += quantity;
return account1;
}

account withdraw(account account1, int quantity){
account1.balance -= quantity;
return account1;
}

106 changes: 106 additions & 0 deletions complex.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/* Matthew Danielson
* 7/6/16
* complex.c
* Complex number calculator using structures with a user
*/

#include <stdio.h>
#include <stdlib.h>
typedef struct{
int coefficient;
int c;
} imag;

imag add(imag, imag);
imag sub(imag, imag);
imag mul(imag, imag);
imag divi(imag, imag);

int main(){
printf("Welcome to the Complex Number Calculator!");
int input;
char throwaway;
int coefficient;
int c;
imag expressions[3];
int count;
while(1){
count = 0;
printf("\nEnter 1 to add, 2 to subtract, 3 to multiply, 4 to divide, and 5 to exit");
scanf("%d", &input);
scanf("%c", &throwaway);
if(input != 5){
while(count <2){
printf("\nPlease the coefficient: ");
scanf("%d", &coefficient);
scanf("%c", &throwaway);
printf("\nPlease enter the extra term: ");
scanf("%d", &c);
scanf("%c", &throwaway);
expressions[count].coefficient = coefficient;
expressions[count].c = c;
count++;

}
}
if(input == 1){
expressions[2] = add(expressions[0], expressions[1]);
printf("\nResult: %di + %d", expressions[2].coefficient,expressions[2].c);

}
if(input == 2){
expressions[2] = sub(expressions[0], expressions[1]);
printf("\nResult: %di + %d", expressions[2].coefficient, expressions[2].c);

}
if(input == 3){
expressions[2] = mul(expressions[0], expressions[1]);
printf("\nResult: %di + %d", expressions[2].coefficient,expressions[2].c);

}
if(input == 4){
expressions[2] = add(expressions[0], expressions[1]);
printf("\nResult: %di + %d", expressions[2].coefficient, expressions[2].c);

}
if(input == 5){
printf("\nThank you for using the calculator\n");
exit(0);
}
}
}

imag add(imag expression1, imag expression2){
imag expression3;
expression3.coefficient = (expression1.coefficient + expression2.coefficient);
expression3.c = (expression1.c + expression2.c);

return expression3;
}

imag sub(imag expression1, imag expression2){
imag expression3;
expression3.coefficient = (expression1.coefficient - expression2.coefficient);
expression3.c =(expression1.c - expression2.c);
return expression3;
}

imag mul(imag expression1, imag expression2){
imag expression3;
expression3.c = ((expression1.c * expression2.c) -(expression1.coefficient * expression2.coefficient));
expression3.coefficient = ((expression1.coefficient * expression2.c ) + (expression2.coefficient * expression1.c));
return expression3;
}

imag divi(imag expression1, imag expression2){
imag expression3;
imag temp;
temp.coefficient = expression2.coefficient;
temp.c = -(expression2.c);
imag temp2 = mul(expression1, temp);
imag temp3 = mul(expression2, temp);
expression3.coefficient = (temp2.coefficient / temp3.coefficient);
expression3.c = (temp2.c / temp3.c);
return expression3;
}

35 changes: 35 additions & 0 deletions quadratic.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* Matthew Danielson
* 7/5/16
* quadratic.c
* solves the quadratic formula
*/

#include <stdio.h>
#include <math.h>

float quadratic(int, int, int);

int main(){
printf("Please enter a:");
int a;
scanf("%d", &a);
printf("\nPlease enter b:");
int b;
scanf("%d", &b);
printf("\nPlease enter c:");
int c;
scanf("%d", &c);
float value = quadratic(a, b, c);
printf("%f \n", value);


}


float quadratic(int a, int b, int c){
float y = pow(b, 2);
y -= (4*a*c);
float x = (-b + sqrt(y))/(2*a);
return x;
}