From cea3858d2b63ec47611c15b38a81c9f7ace51118 Mon Sep 17 00:00:00 2001 From: Skee Date: Wed, 6 Jul 2016 15:24:27 -0400 Subject: [PATCH 1/8] Classwork --- student.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 student.c diff --git a/student.c b/student.c new file mode 100644 index 0000000..8630428 --- /dev/null +++ b/student.c @@ -0,0 +1,64 @@ +/*Sean Kee*/ +/*Student Structure*/ +#include +#include + +typedef struct { + char name[100]; + int age; + int score[5]; + float avg; + char status[5]; +} student; + +student average(student st) { + float avg = 0; + for (int j = 0; j < 5; j++) { + avg += st.score[j]; + } + avg /= 5; + st.avg = avg; + + return st; +} +student status(student st) { + if (st.avg >= 65) + strcpy(st.status, "PASS"); + else + strcpy(st.status, "FAIL"); + + return st; +} + +int main() { + int grade; + int i; + int j; + student st[5]; + printf("STUDENT AVERAGE DATA STRUCTURE\n"); + printf("******************************\n\n"); + for (i = 0; i < 5; i++) { + printf("Student %d Name #: ", i + 1); + fgets(st[i].name, sizeof(st[i].name), stdin); + st[i].name[strlen(st[i].name)-1] = '\0'; + printf("%s's Age #: ", st[i].name); + scanf("%d", &st[i].age); + getchar(); + printf("\n"); + } + for (i = 0; i < 5; i++) { + printf("\n"); + for (j = 0; j < 5; j++) { + printf("Input score %d for %s #: ", j + 1, st[i].name); + scanf("%d", &st[i].score[j]); + } + st[i] = average(st[i]); + st[i] = status(st[i]); + } + printf("\n NAME AGE AVERAGE STATUS\n\n\n"); + for (i = 0; i < 5; i++) { + printf("%10s %6d %11.02f %8s\n\n", st[i].name, st[i].age, st[i].avg, st[i].status); + } + + return 0; +} From 3ea88f9e28eda6694232daa8a0e8f1d9ea1541d0 Mon Sep 17 00:00:00 2001 From: Skee Date: Thu, 7 Jul 2016 01:28:55 -0400 Subject: [PATCH 2/8] banking.c, not quite working properly --- banking.c | 172 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 172 insertions(+) create mode 100644 banking.c diff --git a/banking.c b/banking.c new file mode 100644 index 0000000..4fff705 --- /dev/null +++ b/banking.c @@ -0,0 +1,172 @@ +/*Sean Kee*/ +/*Banking using structures*/ +#include +#include +int a = 0; //Global Account Counter + +typedef struct bankAccount{ + int number; + char name[100]; + float balance; +} account; + +void title() { + printf("\n^-------------^\n"); + printf("T KEE BANKING T\n"); + printf("I_@**_***_**@_I\n\n\n\n"); +} + +void accountStatus(account acc) { + char y; + title(); + printf("ACCOUNT STATUS\n"); + printf("**************\n\n"); + printf("Name: %s\n", acc.name); + printf("Account Number: %1d\n", acc.number); + printf("Current Balance: $%.02f\n", acc.balance); + printf("\n\nPress y to Return."); + scanf("%c", &y); +} + +account accountCreate(account acc) { + printf("ACCOUNT CREATION\n"); + printf("****************\n\n"); + printf("What is your name?\n#: "); + fgets(acc.name, sizeof(acc.name), stdin); + acc.number = a; + acc.balance = 0; + accountStatus(acc); + return acc; +} + +account withdraw(account acc) { + float amount; + char retry; + char status; + title(); + printf("WITHDRAW FUNDS\n"); + printf("**************\n\n"); + printf("Your current balance is: $%.02f\n\n", acc.balance); + printf("How much would you like to withdraw?\n#: "); + scanf("%f", &amount); + if (amount > acc.balance) { + printf("\nSorry, you do not have enough funds to withdraw $%0.2f\n", amount); + printf("\nRetry? [y/n]\n#: "); + scanf("%c", &retry); + if (retry == 'y' || retry == 'Y') + withdraw(acc); + else + return acc; + } + else { + acc.balance -= amount; + printf("You have successfully withdrawn $%.02f from your account.\n\n", amount); + printf("Would you like to check your new status? [y/n]\n#: "); + scanf("%c", &status); + if (status == 'y' || status == 'Y') { + accountStatus(acc); + return acc; + } + else + return acc; + } +} + +account deposit(account acc) { + float amount; + char status; + title(); + printf("DEPOSIT FUNDS\n"); + printf("*************\n\n"); + printf("Your current balance is: $%.02f\n\n", acc.balance); + printf("How much would you like to deposit?\n#: "); + scanf("%f", &amount); + acc.balance += amount; + printf("You have successfully deposited $%.02f to your account.\n\n", amount); + printf("Would you like to check your new status? [y/n]\n#: "); + getchar(); + scanf("%c", &status); + if (status == 'y' || status == 'Y') { + accountStatus(acc); + return acc; + } + else + return acc; +} + +void mainMenu(account acc[]) { + int menu = 1; //1:MAIN, 2:CREATE, 3:MANAGE + int option; + int account = -1; + do { + title(); + switch(menu){ + case 1: + printf("How may I help you today?\n\n1: Create A New Account\n2: Manage An Existing Account\n3: Exit\n\n#: "); + scanf("%d", &option); + switch(option) { + case 1: //Create + menu = 2; + break; + case 2: //Manage + menu = 3; + break; + case 3: //Exit + menu = 0; + break; + default: menu = 1; + } + break; + case 2: + accountCreate(acc[a]); + a++; + menu = 1; + break; + case 3: + if (account == -1) { + printf("Please enter your account number\n#: "); + scanf("%d", &account); + break; + } + else { + printf("What action would you like to perform?\n\n1: Witdraw\n2: Deposit\n3: Check Balance\n4: Return\n#: "); + scanf("%d", &option); + + switch(option) { + case 1: //Withdraw + withdraw(acc[account]); + break; + case 2: //Deposit + deposit(acc[account]); + break; + case 3: //Status Check + printf("Your current balance is: $%.02f", acc[account].balance); + break; + case 4: + menu = 1; + account = -1; + break; + } + break; + } + + } + + } while (menu > 0); +} + +void initialize() { + int n; + printf("Input number of total accounts #: "); + scanf("%d", &n); + account acc[n]; + + mainMenu(acc); +} + +int main() +{ + initialize(); + + return 0; +} From 8dab27ed95cdf665cf30a7fe49b4e7890e86106d Mon Sep 17 00:00:00 2001 From: Skee Date: Thu, 7 Jul 2016 02:11:38 -0400 Subject: [PATCH 3/8] Fixed, Now working properly --- banking.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/banking.c b/banking.c index 4fff705..b87a544 100644 --- a/banking.c +++ b/banking.c @@ -11,27 +11,28 @@ typedef struct bankAccount{ } account; void title() { + printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); printf("\n^-------------^\n"); printf("T KEE BANKING T\n"); printf("I_@**_***_**@_I\n\n\n\n"); } void accountStatus(account acc) { - char y; title(); printf("ACCOUNT STATUS\n"); printf("**************\n\n"); printf("Name: %s\n", acc.name); printf("Account Number: %1d\n", acc.number); printf("Current Balance: $%.02f\n", acc.balance); - printf("\n\nPress y to Return."); - scanf("%c", &y); + printf("\n\nPress Enter to Return."); + getchar(); } account accountCreate(account acc) { printf("ACCOUNT CREATION\n"); printf("****************\n\n"); printf("What is your name?\n#: "); + getchar(); fgets(acc.name, sizeof(acc.name), stdin); acc.number = a; acc.balance = 0; @@ -52,6 +53,7 @@ account withdraw(account acc) { if (amount > acc.balance) { printf("\nSorry, you do not have enough funds to withdraw $%0.2f\n", amount); printf("\nRetry? [y/n]\n#: "); + getchar(); scanf("%c", &retry); if (retry == 'y' || retry == 'Y') withdraw(acc); @@ -62,7 +64,9 @@ account withdraw(account acc) { acc.balance -= amount; printf("You have successfully withdrawn $%.02f from your account.\n\n", amount); printf("Would you like to check your new status? [y/n]\n#: "); + getchar(); scanf("%c", &status); + getchar(); if (status == 'y' || status == 'Y') { accountStatus(acc); return acc; @@ -86,6 +90,7 @@ account deposit(account acc) { printf("Would you like to check your new status? [y/n]\n#: "); getchar(); scanf("%c", &status); + getchar(); if (status == 'y' || status == 'Y') { accountStatus(acc); return acc; @@ -118,7 +123,7 @@ void mainMenu(account acc[]) { } break; case 2: - accountCreate(acc[a]); + acc[a] = accountCreate(acc[a]); a++; menu = 1; break; @@ -129,18 +134,21 @@ void mainMenu(account acc[]) { break; } else { + printf("Hello %s", acc[account].name); printf("What action would you like to perform?\n\n1: Witdraw\n2: Deposit\n3: Check Balance\n4: Return\n#: "); scanf("%d", &option); - + getchar(); switch(option) { case 1: //Withdraw - withdraw(acc[account]); + acc[account] = withdraw(acc[account]); break; case 2: //Deposit - deposit(acc[account]); + acc[account] = deposit(acc[account]); break; case 3: //Status Check printf("Your current balance is: $%.02f", acc[account].balance); + printf("\nPress Enter to Return."); + getchar(); break; case 4: menu = 1; From a1a267ab847a75d0d602c5325394df630d922456 Mon Sep 17 00:00:00 2001 From: Skee Date: Thu, 7 Jul 2016 02:21:35 -0400 Subject: [PATCH 4/8] assignment6.txt --- assignment6.txt | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 assignment6.txt diff --git a/assignment6.txt b/assignment6.txt new file mode 100644 index 0000000..3881720 --- /dev/null +++ b/assignment6.txt @@ -0,0 +1,7 @@ +Sean Kee + +1. First, the code wouldn't even compile because you did not include the necessary header files. However, if you did, it would print 203, 1, 23. + +2. Compared to enums, structers allow for easy storage and access of multiple variables/data types. Enums is sort of like an inverted array, and can only store one data type. Enums are useful if you want to be able to refer to an "array" by words, rather than numbers. Structures are useful when you want to have sort of a set "format" for a certain thing. + +3. The difference between passing an array directly into a function means it isn't being copied. That means whatever changes are made to the array in the function affects the original array. However, structures get passed as values, which means if an array is inside the structure, it gets copied over. Whatever happens to the structured array in the function doesnt affect the original array unless it is returned back through the structure. From 7e9c1db3c0eb11b6c827570ef1868db138054ecd Mon Sep 17 00:00:00 2001 From: MrSkee Date: Thu, 7 Jul 2016 02:22:23 -0400 Subject: [PATCH 5/8] Added Version --- banking.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/banking.c b/banking.c index b87a544..bbd43e7 100644 --- a/banking.c +++ b/banking.c @@ -1,5 +1,5 @@ /*Sean Kee*/ -/*Banking using structures*/ +/*Banking using structures v1.0.12*/ #include #include int a = 0; //Global Account Counter From bed7b74ee2b3f2fcba33f12d8f31b38e73186d06 Mon Sep 17 00:00:00 2001 From: Skee Date: Thu, 7 Jul 2016 09:29:03 -0400 Subject: [PATCH 6/8] banking updated --- banking.c | 56 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/banking.c b/banking.c index b87a544..a42bfcc 100644 --- a/banking.c +++ b/banking.c @@ -1,8 +1,8 @@ /*Sean Kee*/ -/*Banking using structures*/ +/*Banking using structures v1.0.12*/ #include #include -int a = 0; //Global Account Counter +int a = 0; /*Global Account Counter, states the next available account number for creation*/ typedef struct bankAccount{ int number; @@ -10,14 +10,14 @@ typedef struct bankAccount{ float balance; } account; -void title() { +void title() { /*Prints Header*/ printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); printf("\n^-------------^\n"); printf("T KEE BANKING T\n"); printf("I_@**_***_**@_I\n\n\n\n"); } -void accountStatus(account acc) { +void accountStatus(account acc) { /*When this is called, it prints out the status of the current account*/ title(); printf("ACCOUNT STATUS\n"); printf("**************\n\n"); @@ -28,7 +28,7 @@ void accountStatus(account acc) { getchar(); } -account accountCreate(account acc) { +account accountCreate(account acc) { /*Creates a account in accordance with the next available account number*/ printf("ACCOUNT CREATION\n"); printf("****************\n\n"); printf("What is your name?\n#: "); @@ -40,7 +40,7 @@ account accountCreate(account acc) { return acc; } -account withdraw(account acc) { +account withdraw(account acc) { /*Function for withdrawing money*/ float amount; char retry; char status; @@ -50,7 +50,7 @@ account withdraw(account acc) { printf("Your current balance is: $%.02f\n\n", acc.balance); printf("How much would you like to withdraw?\n#: "); scanf("%f", &amount); - if (amount > acc.balance) { + if (amount > acc.balance) { /*Checks if requested withdrawal amount is greater than what is in the account*/ printf("\nSorry, you do not have enough funds to withdraw $%0.2f\n", amount); printf("\nRetry? [y/n]\n#: "); getchar(); @@ -76,7 +76,7 @@ account withdraw(account acc) { } } -account deposit(account acc) { +account deposit(account acc) { /*Deposit money function*/ float amount; char status; title(); @@ -99,58 +99,60 @@ account deposit(account acc) { return acc; } -void mainMenu(account acc[]) { - int menu = 1; //1:MAIN, 2:CREATE, 3:MANAGE +void mainMenu(account acc[]) { /*Menu System*/ + int menu = 1; /*1:MAIN, 2:CREATE, 3:MANAGE*/ int option; - int account = -1; + int account = -1; /*Keeps track of the current user*/ do { title(); - switch(menu){ - case 1: + switch(menu){ /*System for displaying the correct menu*/ + case 1: /*Main Menu*/ printf("How may I help you today?\n\n1: Create A New Account\n2: Manage An Existing Account\n3: Exit\n\n#: "); scanf("%d", &option); switch(option) { - case 1: //Create + case 1: /*Create*/ menu = 2; break; - case 2: //Manage + case 2: /*Manage*/ menu = 3; break; - case 3: //Exit + case 3: /*Exit*/ menu = 0; break; default: menu = 1; } break; - case 2: + case 2: /*Create a new account*/ acc[a] = accountCreate(acc[a]); a++; menu = 1; break; - case 3: - if (account == -1) { + case 3: /*Manage an existing account*/ + if (account == -1) { /*Asks the user to input their account number*/ printf("Please enter your account number\n#: "); scanf("%d", &account); break; } - else { - printf("Hello %s", acc[account].name); + else { /*For if the user has already logged in*/ + printf("Hello %s\n", acc[account].name); + printf("Account Number %d\n\n", acc[account].number); printf("What action would you like to perform?\n\n1: Witdraw\n2: Deposit\n3: Check Balance\n4: Return\n#: "); scanf("%d", &option); getchar(); switch(option) { - case 1: //Withdraw + case 1: /*Withdraw*/ acc[account] = withdraw(acc[account]); break; - case 2: //Deposit + case 2: /*Deposit*/ acc[account] = deposit(acc[account]); break; - case 3: //Status Check + case 3: /*Status Check*/ + title(); printf("Your current balance is: $%.02f", acc[account].balance); printf("\nPress Enter to Return."); getchar(); break; - case 4: + case 4: /*Logs the user out and resets the current account in use*/ menu = 1; account = -1; break; @@ -165,7 +167,9 @@ void mainMenu(account acc[]) { void initialize() { int n; - printf("Input number of total accounts #: "); + printf("\nADMINISTRATION\n"); + printf("**************\n"); + printf("Input number of total accounts #: "); /*Prompts the user before the bank function starts to input the allowed amount bank acounts*/ scanf("%d", &n); account acc[n]; From aec98a94b7f4aff415879a53d21ec4ea0d761433 Mon Sep 17 00:00:00 2001 From: Skee Date: Thu, 7 Jul 2016 23:10:34 -0400 Subject: [PATCH 7/8] forgot to add this yesterday :/ --- complex.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 complex.c diff --git a/complex.c b/complex.c new file mode 100644 index 0000000..79c3fbc --- /dev/null +++ b/complex.c @@ -0,0 +1,78 @@ +/*Sean Kee*/ +/*Complex Numbers*/ +#include +#include + +typedef struct { + float real; + float i; +} calc; + +calc add(calc x, calc y) { + calc calc; + calc.real = x.real + y.real; + calc.i = x.i + y.i; + return calc; +} + +calc sub (calc x, calc y) { + calc calc; + calc.real = x.real - y.real; + calc.i = x.i - y.i; + + return calc; +} + +calc mult (calc x, calc y) { + calc calc; + calc.real = x.real * y.real; + calc.i = x.i * y.i; + + return calc; +} + +calc div (calc x, calc y) { + calc calc; + calc.real = x.real / y.real; + calc.i = x.i / y.i; +} +void printResult(calc result) { + printf("Results: \n"); + printf("%.02f\n", result.real); + printf("%.02fi\n", result.i); +} +int main() { + calc x; + calc y; + calc result; + char op; + printf("What would you like to do?\n1:+ 2:- 3:* 4:/\n#: "); + scanf("%c", &op); + printf("Input real value 1\n#: "); + scanf("%f", &x.real); + printf("Input imaginary value 1\n#: "); + scanf("%f", &x.i); + printf("Input real value 2\n#: "); + scanf("%f", &y.real); + printf("Input imaginary value 2\n#: "); + scanf("%f", &y.i); + switch(op) { + case 1: + result = add(x, y); + break; + case 2: + result = sub(x, y); + break; + case 3: + result = mult(x, y); + break; + case 4: + result = div(x, y); + break; + default: + printf("Invalid, restart program.\n"); + } + printResult(result); + + return 0; +} From d61eb05c94dc2f37f122ff86e8543b468d669ece Mon Sep 17 00:00:00 2001 From: Skee Date: Thu, 7 Jul 2016 23:14:27 -0400 Subject: [PATCH 8/8] Changes --- banking.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/banking.c b/banking.c index a42bfcc..b3b2cfc 100644 --- a/banking.c +++ b/banking.c @@ -12,7 +12,9 @@ typedef struct bankAccount{ void title() { /*Prints Header*/ printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); - printf("\n^-------------^\n"); + printf(" _ \n"); + printf(" _-*V*-_ \n"); + printf("^--^I*o^o*I^--^\n"); printf("T KEE BANKING T\n"); printf("I_@**_***_**@_I\n\n\n\n"); } @@ -159,6 +161,8 @@ void mainMenu(account acc[]) { /*Menu System*/ } break; } + default: + account = -1; } @@ -167,6 +171,7 @@ void mainMenu(account acc[]) { /*Menu System*/ void initialize() { int n; + title(); printf("\nADMINISTRATION\n"); printf("**************\n"); printf("Input number of total accounts #: "); /*Prompts the user before the bank function starts to input the allowed amount bank acounts*/