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 @@
Aly Milich

1. Structures need to be declared before the main so you will get an error if you try to declare struct inside the main.

2. Structures are used to store different variable types under one common structure. You could use these to store different data about a student which could include their gender (char), name (string), and age (int). Enumerations assign variable names to stored integers which could be useful in storing the months for example because then the name of the month and its corresponding number would match up.

3. Passing an array directly versus passing a structure containing an array is the difference between passing by value and calling by value. In the former, the array is only changed inside the function whereas in the latter, the values of the array are changed until the program terminates.
64 changes: 64 additions & 0 deletions banking.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/* banking code
@author Aly Milich
*/

#include <stdio.h>

typedef struct bank{

int accNum;
char name[100];
float balance;

} bank;


float withdraw(float a){

float newBal;
newBal = 1000-a;
printf("Your new balance is: %f", newBal);
}

float deposit(float a, bank b){

float nuevoBal;
b.balance = b.balance + a;

printf("Your new balance is: %f", b.balance);
}



int main(){
char name[100];
printf("What is your name?\n");
fgets("%s", &name);

printf("Do you want to deposit(press 1) or withdraw(press 2)\n");
bank bank1 = {1, name, 1000};
bank bank2 = {2, name, 800};
printf("#: %d, Name: %s, Balance: %f\n",bank1.accNum,bank1.name,bank1.balance);
int input;
scanf("%d", &input);

if(input == 1){
float depo;

printf("How much are you depositing?");
scanf("%f", &depo);

deposit(depo, bank1);
}

else if(input ==2){
float withd;

printf("How much are you withdrawing?");
scanf("%f", &withd);

withdraw(withd);

}

}
56 changes: 56 additions & 0 deletions structex.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include <stdio.h>
#include <string.h>

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

int main(){
student s1= {"Emma", 17, {45, 35, 60, 70, 90}};
student s2 = {"Katie", 19, {45, 35, 60, 70, 90}};
student s3 = {"Victoria", 16, {65, 75, 85, 92, 82}};
student s4 = {"Vicky", 12, {55, 25, 60, 70, 90}};
student s5 = {"Deluca", 90, {70, 80, 90, 100, 90}};

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

int i, sum=0, j;

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;

}

//print students

printf("Name: %s\n", s[0].name);
printf("Age: %d\n", s[0]. age);
printf("Average: %d\n", s[0].average);
printf("\n");
printf("Name: %s\n", s[1].name);
printf("Age: %d\n", s[1].age);
printf("Average: %d\n", s[1].average);
printf("\n");
printf("Name: %s\n", s[2].name);
printf("Age: %d\n", s[2]. age);
printf("Average: %d\n", s[2].average);
printf("\n");
printf("Name: %s\n", s[3].name);
printf("Age: %d\n", s[3].age);
printf("Average: %d\n", s[3].average);
printf("\n");
printf("Name: %s\n", s[4].name);
printf("Age: %d\n", s[4].name);
printf("Average: %d\n", s[4].average);

return 0;

}