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
4 changes: 4 additions & 0 deletions assignment6.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Jack Rosen
1. The program will have an error because you cannot declare a struct insidethe main() class.
2. Structures can have different variable types to store while enumerations store integers but use the variable name. A structure would work for banks who need to hold a name, bank number, and balance in the same place. Enumerations work if you want to find out the months of the year because they all have the correct number set to them.
3. When you pass a structure with an array, the value of the array does not change in the structure, only in the thing you are passing to. When you pass an array, the value of the array changes in the function and wherever else it is.
41 changes: 41 additions & 0 deletions banking.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <stdio.h>
#include <string.h>
/*Jack Rosen. The purpose of this is to add and subtract balance from an account using structures and functions. */
typedef struct bankAccounts
{
float balance;
int number;
char name[1000];
} bank;
float deposit(float s)
{
float money = 50;
return s + money;
}
float widthdraw(float s)
{
float money = 25;
return s - money;
}

int main()
{
float pers1,pers2;
printf("How much should be in the first account?\n");
scanf("%f", &pers1);
printf("How much should be in the second account?\n");
scanf("%f", &pers2);
bank account1 = {pers1, 11245, "Account 1"}, account2 = {pers2, 51124, "Account 2"};
for (int i = 0; i < 2; i++)
{
account1.balance = deposit(account1.balance);
printf("The account, %s, with number %d now has %f dollars\n", account1.name, account1.number, account1.balance);
account1.balance = widthdraw(account1.balance);
printf("The account, %s, with number %d now has %f dollars\n", account1.name, account1.number, account1.balance);
account2.balance = deposit(account2.balance);
printf("The account, %s, with number %d now has %f dollars\n", account2.name, account2.number, account2.balance);
account2.balance = widthdraw(account2.balance);
printf("The account, %s, with number %d now has %f dollars \n", account2.name, account2.number, account2.balance);
}
return 0;
}
100 changes: 100 additions & 0 deletions complex.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#include <stdio.h>
/*Jack Rosen. The purpose of this program is to do computations with complex numbers using structures and functions. */
typedef struct complexNumber
{
float real;
float complexN;
}number;
float add1(float k, float f)
{
k += f;
return k;
}
float add2(float l, float s)
{
l += s;
return l;
}
float subtract1(float k, float f)
{
k -= f;
return k;
}
float subtract2(float l, float s)
{
l -= s;
return l;
}
float multiply1 (float k, float l, float f, float s)
{
k *= f;
l *= s;
k -= l;
return k;
}
float multiply2 (float k, float l, float f, float s)
{
k *= s;
f *= l;
k += f;
return k;
}
float divide1(float k, float l, float f, float s)
{
k *= f;
l *= s;
k += l;
return k;
}
float divide2(float k, float l, float f, float s)
{
k *= s;
f *= l;
f -= k;
return f;

}
int main()
{
float real1, complex1, real2, complex2;
printf("What do you want the real number to be?\n");
scanf("%f", &real1);
printf("What do you want the complex part to be?\n");
scanf("%f", &complex1);
printf("What do you want the real number to be?\n");
scanf("%f", &real2);
printf("What do you want the complex part to be?\n");
scanf("%f", &complex2);
number first = {real1, complex1}, second = {real2, complex2}, answer= {};
printf("What do you want to do to the numbers? +, -, *, /\n");
char decision;
scanf("%c", &decision);
if (decision == '\n')
{
decision = getchar();
}
if (decision == '+')
{
answer.real = add1(real1, real2);
answer.complexN = add2(complex1, complex2);
printf("%f + %fi\n", answer.real, answer.complexN);
}
else if (decision == '-')
{
answer.real = subtract1(real1, real2);
answer.complexN = subtract2(complex1, complex2);
printf("%f + %fi\n", answer.real, answer.complexN);
}
else if (decision == '*')
{
answer.real = multiply1(real1, complex1, real2, complex2);
answer.complexN = multiply2(real1, complex1, real2, complex2);
printf("%f + %fi\n", answer.real, answer.complexN);
}
else if (decision == '/')
{
answer.real = divide1(real1, complex1, real2, complex2)/((real2 * real2) + (complex2 * complex2));
answer.complexN = divide2 (real1, complex1, real2, complex2)/((real2 * real2) + (complex2 * complex2));
printf("%f + %fi\n", answer.real, answer.complexN);
}
}
39 changes: 39 additions & 0 deletions student.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include <stdio.h>
#include <string.h>
/*Jack Rosen. The purpose is to find the average test score of 5 people using structures and functions. */
typedef struct {
char name[100];
int age;
int scores[5];
} student;
int main()
{
int average;
student st[5];
student s = {"Jack", 15, {}}, r = {"Oscar", 17, {}}, d = {"Eli", 19, {}}, e = {"Emma", 12, {}}, g = {"Bob", 20, {}};
st[0] = s;
st[1] = r;
st[2] = d;
st[3] = e;
st[4] = g;
for (int i = 0; i <= 4; i++)
{
printf("What do you want %s's 5 test scores to be?\n", st[i].name);
for (int j = 0; j <= 4; j++)
{
scanf("%d", &st[i].scores[j]);
}
}
for (int i = 0; i <= 4; i++)
{
average = 0;
for (int j = 0; j <= 4; j++)
{
average += st[i].scores[j];
}
average /= 5;
printf("The average of %s's scores was %d%%\n", st[i].name, average);
}
return 0;

}