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
7 changes: 7 additions & 0 deletions assignment6.txt
Original file line number Diff line number Diff line change
@@ -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.
189 changes: 189 additions & 0 deletions banking.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
/*Sean Kee*/
/*Banking using structures v1.0.12*/
#include <stdio.h>
#include <string.h>
int a = 0; /*Global Account Counter, states the next available account number for creation*/

typedef struct bankAccount{
int number;
char name[100];
float balance;
} account;

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");
printf(" _-*V*-_ \n");
printf("^--^I*o^o*I^--^\n");
printf("T KEE BANKING T\n");
printf("I_@**_***_**@_I\n\n\n\n");
}

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");
printf("Name: %s\n", acc.name);
printf("Account Number: %1d\n", acc.number);
printf("Current Balance: $%.02f\n", acc.balance);
printf("\n\nPress Enter to Return.");
getchar();
}

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#: ");
getchar();
fgets(acc.name, sizeof(acc.name), stdin);
acc.number = a;
acc.balance = 0;
accountStatus(acc);
return acc;
}

account withdraw(account acc) { /*Function for withdrawing money*/
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) { /*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();
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#: ");
getchar();
scanf("%c", &status);
getchar();
if (status == 'y' || status == 'Y') {
accountStatus(acc);
return acc;
}
else
return acc;
}
}

account deposit(account acc) { /*Deposit money function*/
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);
getchar();
if (status == 'y' || status == 'Y') {
accountStatus(acc);
return acc;
}
else
return acc;
}

void mainMenu(account acc[]) { /*Menu System*/
int menu = 1; /*1:MAIN, 2:CREATE, 3:MANAGE*/
int option;
int account = -1; /*Keeps track of the current user*/
do {
title();
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*/
menu = 2;
break;
case 2: /*Manage*/
menu = 3;
break;
case 3: /*Exit*/
menu = 0;
break;
default: menu = 1;
}
break;
case 2: /*Create a new account*/
acc[a] = accountCreate(acc[a]);
a++;
menu = 1;
break;
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 { /*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*/
acc[account] = withdraw(acc[account]);
break;
case 2: /*Deposit*/
acc[account] = deposit(acc[account]);
break;
case 3: /*Status Check*/
title();
printf("Your current balance is: $%.02f", acc[account].balance);
printf("\nPress Enter to Return.");
getchar();
break;
case 4: /*Logs the user out and resets the current account in use*/
menu = 1;
account = -1;
break;
}
break;
}
default:
account = -1;

}

} while (menu > 0);
}

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*/
scanf("%d", &n);
account acc[n];

mainMenu(acc);
}

int main()
{
initialize();

return 0;
}
78 changes: 78 additions & 0 deletions complex.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*Sean Kee*/
/*Complex Numbers*/
#include <stdio.h>
#include <string.h>

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;
}
64 changes: 64 additions & 0 deletions student.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*Sean Kee*/
/*Student Structure*/
#include <stdio.h>
#include <string.h>

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;
}