diff --git a/assignment6.txt b/assignment6.txt new file mode 100644 index 0000000..e938951 --- /dev/null +++ b/assignment6.txt @@ -0,0 +1,14 @@ + Emma Ladouceur + + + 1. This code will print + + 203 1 23 + + because the specific emp1 overrides the initial values set for the employee struct. + + + 2. enumerations are simply words used for numbers. So for an enumeration of months those words really just stand for numbers 0-11, but a struct can have many values. Each thing doesn't stand for a number and you can get the value of the stuct to print or return not just it's numbered position. + + + 3. I'm not really sure but I think that to pass an array into a function you might have to go through a loop to print each value, or you need to look for a specific space in that array, but for a structure it depends of if you're looking for all of the values of the structure or just the array in which case you can loop through for just that piece of the structure. diff --git a/bank b/bank new file mode 100755 index 0000000..35db8d2 Binary files /dev/null and b/bank differ diff --git a/banking.c b/banking.c new file mode 100644 index 0000000..ee5d6f5 --- /dev/null +++ b/banking.c @@ -0,0 +1,61 @@ +//Emma Ladouceur +//Assignment 6 banking.c +//This compiles, but I'm still having some trouble with the values I put in for the balance... can't figure that out. + +#include + +typedef struct bank { + + int accNum; + char name[100]; + float balance; + +} bank; + + +float withdraw(bank b, float a){ + + float newbalance; + b.balance= b.balance-a; + printf("Your new balance is %f", b.balance); +} + +float deposit(float a, bank b){ + + float newbalance; + b.balance= b.balance + a; + printf("Your new balance is %f", b.balance); + + +} + +int main(){ + char name; + printf("What is your name"); + scanf("%s", &name); + printf("Would you like to deposit(type 1) or withdraw (type 2)\n"); + bank bank1 = {1, name, 600.0}; + bank bank2 = {2, name, 500.0}; + + int response; + scanf("%d", &response); + if(response == 1){ + float depo; + + printf("How much are you depositing"); + scanf("%f", &depo); + deposit(depo, bank1); + + } + + if(response ==2){ + float with; + + printf("How much are you withdraw"); + scanf("%f",&with); + withdraw(bank1,with); + + } + + printf("%f",bank1.balance); +} diff --git a/complex b/complex new file mode 100755 index 0000000..03abbd4 Binary files /dev/null and b/complex differ diff --git a/complex.c b/complex.c new file mode 100644 index 0000000..ab03896 --- /dev/null +++ b/complex.c @@ -0,0 +1,74 @@ +//Emma Ladouceur + +//Hmmmm, this seems like the best way to do it, but i didn't use stuct. I'm not sure even how you would, but maybe that's better for the mult and div which I couldn't get to work. + +#include +int add(int a, int b, int c, int d){ + int sum1, sum2; + + + sum1 = a+c; + sum2 = b+d; + + printf("The sum is %d + %di\n", sum1, sum2); + + +} +int sub(int a, int b, int c, int d){ + int sum1, sum2; + + sum1=a-c; + sum2 =b-d; + + printf("The difference is %d + %di\n", sum1, sum2); + +} + +int mult(int a, int b, int c, int d){ + +} + +int div(int a, int b, int c, int d){ + +} + +int main(){ + + int choice; + int a, b,c,d; + + printf("What operation with complex numbers would you like to perform? \n 1 for addition\n 2 for subtraction \n 3 for multiplication \n 4 for division.\n"); + + scanf("%d", &choice); + + if(choice ==1){ + printf("Enter a number a and b where b is bi\n"); + + scanf("%d",&a); + scanf("%d",&b); + + printf("Enter a number c and d where d is di\n"); + scanf("%d",&c); + scanf("%d",&d); + add(a,b,c,d); + } + + if(choice ==2){ + printf("Enter a number a and b where b is bi\n"); + scanf(" %d",&a); + scanf(" %d",&b); + + printf("Enter a number c and d where d is di\n"); + scanf(" %d",&c); + scanf(" %d",&d); + sub(a,b,c,d); +} + +// if(choice == 3) + +// if(choice == 4) + + + + +} diff --git a/students b/students new file mode 100755 index 0000000..8e2be89 Binary files /dev/null and b/students differ diff --git a/students.c b/students.c new file mode 100644 index 0000000..194a7d9 --- /dev/null +++ b/students.c @@ -0,0 +1,66 @@ +#include + +typedef struct student { + + char name[100]; + int age; + int scores[5]; + int average; + int sum,i; + +} student; + + + + +int main(){ + + + + student s1= {"Emma", 17, {60,99,100,40,30}}; + + + student s2= {"Katherine", 16, {88,99,47,89,100}}; + student s3={"Aly", 17, {100, 99, 90, 54, 70}}; + + //int grades[] = {10, 10, 12, 29, 10}; + student s4={"George", 4, {100,99,99,89,88}}; + student s5={"Dean", 1, {33,78,55,66,33}}; + + + student s[] = {s1,s2,s3,s4,s5}; + int i, j; + int sum=0; + for(i=0;i<5;i++){ + sum = 0; + for(j=0; j<5;j++){ + sum = sum + s[i].scores[j]; + + } + s[i].average = sum/5; + + } + + + + //Student 1 + printf("Name: %s\n", s[0].name); + printf("GPA: %d\n", s[0].average); + printf("Age: %d\n", s[0].age); + //Student 2 + printf("Name: %s\n", s[1].name); + printf("Age: %d\n", s[1].age); + printf("GPA: %d\n", s[1].average); + //Student 3 + printf("Name: %s\n", s[2].name); + printf("GPA: %d\n", s[2].average); + printf("Age: %d\n", s[2].age); + //Student 4 + printf("Name: %s\n", s[3].name); + printf("GPA: %d\n", s[3].average); + printf("Age: %d\n", s[3].age); + //Student 5 + printf("Name: %s\n", s[4].name); + printf("GPA: %d\n", s[4].average); + printf("Age: %d\n", s[4].age); +}