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
11 changes: 11 additions & 0 deletions assignment6.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Olivier Gabison

1. It will print:
203 1 23

2. Structures allow you to group variables and mixed data types together in a single
unit. Enums is a data type where every possible value is defined as a symbolic constant.
You would use structures when making a bank account, and enums when defining the days of the week.

3. Passing an array directly to an array causes pass by value. While passing a structure containing an array
causes that object, including the array, to be copied into the function's parameter.
47 changes: 47 additions & 0 deletions banking.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//Olivier Gabison - Banking System

#include <stdio.h>

struct bank {
char name[100];
int number;
float balance;
};

struct bank deposit(struct bank bank, float money){
printf("Depositing $%f into your account...\n", money);
bank.balance += money;
printf("Your account now has $%f\n", bank.balance);
return bank;
}

struct bank withdraw(struct bank bank, float money){
printf("Withdrawing $%f from your account...\n", money);
bank.balance -= money;
printf("Your account now has $%f\n", bank.balance);
return bank;
}

int getBal(struct bank bank){
printf("%s has $%f\n", bank.name, bank.balance);
}
int main(){

struct bank bank1 = {"Account 1", 1, 100.0};
struct bank bank2 = {"Account 2", 2, 1000.0};

getBal(bank1);
bank1 = deposit(bank1, 100);
bank1 = withdraw(bank1, 50);
getBal(bank1);

getBal(bank2);
bank2 = deposit(bank2, 200);
bank2 = withdraw(bank2, 100);
getBal(bank2);




return 0;
}
89 changes: 89 additions & 0 deletions complex.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
//Olivier Gabison - Add/Subtract/Multiply/Divide with complex numbers

#include <stdio.h>

struct complex {
int real;
int imag;
};

struct complex add(struct complex complex1, struct complex complex2){
int c_real = complex1.real + complex2.real;
int c_imag = complex1.imag + complex2.imag;
struct complex complex3 = {c_real, c_imag};
return complex3;
}

struct complex subtract(struct complex complex1, struct complex complex2){
int c_real = complex1.real - complex2.real;
int c_imag = complex1.imag - complex2.imag;
struct complex complex3 = {c_real, c_imag};
return complex3;
}

struct complex multiply(struct complex complex1, struct complex complex2){ //(3 + 2i)(5 + 2i)
int c_real = (complex1.real * complex2.real);
int c_imag = (complex1.imag * complex2.real) + (complex1.real * complex2.imag) + (-(complex1.imag * complex2.imag));
struct complex complex3 = {c_real, c_imag};
return complex3;
}

struct complex divide(struct complex complex1, struct complex complex2){ //I don't know how to divide :(
int c_real = (complex1.real * complex2.real);
int c_imag = (complex1.imag * complex2.real) + (complex1.real * complex2.imag) + (-(complex1.imag * complex2.imag));
struct complex complex3 = {c_real, c_imag};
return complex3;
}

void display(struct complex complex){
printf("The sum is: %d + %di\n", complex.real, complex.imag);
}

int main(){

printf("Welcome to the complex number calculator.\n");
printf("Please pick a choice:\n");
printf("[1] Add\n");
printf("[2] Subtract\n");
printf("[3] Multiply\n");
printf("[4] Divide");
int choice;
int a_real;
int a_imag;
int b_real;
int b_imag;
int c_real;
int c_imag;
scanf("\n%d", &choice);
if(choice >= 0 && choice <= 4){
printf("Time to make your first complex number...\n");
printf("Enter your a (a + bi)");
scanf("\n%d", a_real);
printf("Enter your b (a + bi)");
scanf("\n%d", a_imag);

printf("\nTime to make your second complex number...\n");
printf("Enter your a (a + bi)");
scanf("\n%d", b_real);
printf("Enter your b (a + bi)");
scanf("\n%d", b_imag);

struct complex complex1 = {a_real, a_imag};
struct complex complex2 = {b_real, b_imag};
struct complex complex3;
if(choice == 1){ //ADDING
complex3 = add(complex1, complex2);
} else if (choice == 2){ //SUBTRACTING
complex3 = subtract(complex1, complex2);
} else if (choice == 3){ //MULTIPLY
complex3 = multiply(complex1, complex2);
} else if (choice == 4){
complex3 = divide(complex1, complex2);
}

display(complex3);
}


return 0;
}
38 changes: 38 additions & 0 deletions students.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//Olivier Gabison - Finds the average of student grades

#include <stdio.h>

struct student {
char name[100];
int age;
int scores[5];
};

void avg(struct student student){
float average = 0;

for(int i = 0; i < 5; i++){
average += student.scores[i];
}
average /= 5;

printf("%s's has an average grade of %f", student.name, average);
}

int main(){

struct student s1 = {"Alex", 10, {10, 20, 15, 13, 12}};
struct student s2 = {"Joe", 12, {15,20,30,45,23}};
struct student s3 = {"Bob", 16, {12,70,70,48,25}};
struct student s4 = {"Victor", 18, {65,90,80,65,63}};
struct student s5 = {"Davis", 12, {75,80,30,65,23}};

struct student student[] = {s1, s2, s3, s4, s5};

for(int i = 0; i < 5; i++){
avg(student[i]);
printf("\n");
}


}