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
5 changes: 5 additions & 0 deletions assignment6.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Rumeet Goradia
1. This program will likely not even compile.The structure definion declares a type, not a variable that can be initialized. The values given for the ID, sex, and age in the employee structure definition are not recognized by the compiler because the compiler is only notified of their respective variables' presence. Therefore, no memory is allocated to the structure, so it cannot hold any values before being called.
2. Structures allow the programmer to group variables of mixed data types together into a single unit, whereas all variables in enumerations are integers. Although both hold multiple variables, enumerations provide only constants, but the elements of structures can be changed. Enumerations are helpful when the programmer has multiple units of information but doesn't want to remember these units by numbers. Structures are hlpful when the programmer has an entity that can be split up into numerous properties.
3. Passing an array directly to a function will pass the array by reference, meaning that after the function is completed, the elements of the array will still be modified. Passing a structure contaiing an array will pass the array by value, so the elements of the array are resetn every time the function runs.

95 changes: 95 additions & 0 deletions banking.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*Rumeet Goradia - Banking*/
#include <stdio.h>
#include <string.h>
typedef struct{
int accNum;
float bal;
char name[100];
} bank;

float withdraw(float balance, float withdrawal)
{
balance -= withdrawal;
return balance;
}

float deposit(float balance, float depositted)
{
balance+= depositted;
return balance;
}

int main()
{
bank acc1, acc2;
printf("What are the account numbers for your two bank accounts?\n");
scanf("%d", &acc1.accNum);
scanf("%d", &acc2.accNum);
printf("What is the balance in account %d?\n", acc1.accNum);
scanf("%f", &acc1.bal);
printf("what is the balance in account %d?\n", acc2.accNum);
scanf("%f", &acc2.bal);
getchar();
printf("What is the name for account %d?\n", acc1.accNum);
char name1[100], name2[100];
fgets(name1, sizeof(name1), stdin);
strcpy(acc1.name,name1);
printf("what is the name for account %d?\n", acc2.accNum);
fgets(name2, sizeof(name2), stdin);
strcpy(acc2.name,name2);
printf("\nAccount 1:\n");
printf("Name: %s", acc1.name);
printf("Number: %d\n", acc1.accNum);
printf("Balance: $%.2f\n\n", acc1.bal);
printf("Account 2:\n");
printf("Name: %s", acc2.name);
printf("Number %d\n", acc2.accNum);
printf("Balance: $%.2f\n\n", acc2.bal);
float dep1, dep2;
printf("How much money do you want to deposit into account %d?\n", acc1.accNum);
scanf("%f", &dep1);
float depositted1=deposit(acc1.bal, dep1);
printf("\nAccount 1:\n");
printf("Name: %s", acc1.name);
printf("Number: %d\n", acc1.accNum);
printf("Deposited: $%.2f\n", dep1);
printf("Balance: $%.2f\n\n", depositted1);
printf("How much money do you want to deposit into account %d?\n", acc2.accNum);
scanf("%f", &dep2);
float depositted2=deposit(acc2.bal, dep2);
printf("\nAccount 2:\n");
printf("Name: %s", acc2.name);
printf("Number: %d\n", acc2.accNum);
printf("Deposited: $%.2f\n", dep2);
printf("Balance: $%.2f\n\n", depositted2);
float with1, with2;
printf("How much money do you want to withdraw from account %d?\n", acc1.accNum);
scanf("%f", &with1);
float withdrawn1=withdraw(depositted1, with1);
printf("\nAccount 1:\n");
printf("Name: %s", acc1.name);
printf("Number: %d\n", acc1.accNum);
printf("Withdrawn: $%.2f\n", with1);
printf("Balance: $%.2f\n\n", withdrawn1);
printf("How much money do you want to withdraw from account %d?\n", acc2.accNum);
scanf("%f", &with2);
float withdrawn2=withdraw(depositted2, with2);
printf("\nAccount 2:\n");
printf("Name: %s", acc2.name);
printf("Number: %d\n", acc2.accNum);
printf("Withdrawn): $%.2f\n", with2);
printf("Balance: $%.2f\n\n", withdrawn2);
printf("\nFinal account details:\n");
printf("Account 1:\n");
printf("Name: %s", acc1.name);
printf("Number: %d\n", acc1.accNum);
printf("Balance: $%.2f\n\n", withdrawn1);
printf("Account 2:\n");
printf("Name: %s", acc2.name);
printf("Number: %d\n", acc2.accNum);
printf("Balance: $%.2f\n\n", withdrawn2);
return 0;
}



104 changes: 104 additions & 0 deletions complex.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*Rumeet Goradia - Complex Numbers*/
#include<stdio.h>
#include<string.h>
typedef struct {
float real;
float imag;
} comp;

comp add (comp x, comp y)
{
comp temp;
temp.real=x.real+y.real;
temp.imag=x.imag+y.imag;

return(temp);
}

comp sub (comp x, comp y)
{
comp temp;
temp.real=x.real-y.real;
temp.imag=x.imag-y.imag;

return(temp);
}

comp mul (comp x, comp y)
{
comp temp;
temp.real=(x.real*y.real)-(x.imag*y.imag);
temp.imag=(x.real*y.imag)+(x.imag*y.real);

return temp;

}

comp div (comp x, comp y)
{
comp num, den;
y.imag=-y.imag;
num.real=(x.real*y.real)-(x.imag*y.imag);
num.imag=(x.real*y.imag)+(x.imag*y.real);
den.real=(y.real*y.real)+(y.imag*y.imag);
comp quo;
quo.real=num.real/den.real;
quo.imag=num.imag/den.real;

return quo;
}

void printer (comp x)
{
printf("%f", x.real);
printf("%+f", x.imag);
printf("i\n");
return;
}

int main()
{
comp x, y;
printf("Please input the real and imaginary portions of the first complex number.\n");
scanf("%f", &x.real);
scanf("%f", &x.imag);
printf("Please input the real and imaginary portions of the second complex number.\n");
scanf("%f", &y.real);
scanf("%f", &y.imag);
comp ans;
getchar();
char op;
char prntop[100];
printf("Please choose one of the following operations:\n+ ADDITION\n- SUBTRACTION\n* MULTIPLICATION\n/ DIVISION\n");
scanf("%c", &op);
switch (op)
{
case '+':
ans=add(x,y);
strcpy(prntop, "Sum: ");
break;
case '-':
ans=sub(x,y);
strcpy(prntop, "Difference: ");
break;
case '*':
ans=mul(x,y);
strcpy(prntop, "Product: ");
break;
case '/':
ans=div(x,y);
strcpy(prntop, "Quotient: ");
break;
default:
printf("That was not an option.\n");
}
printf("First complex number: ");
printer(x);
printf("Second complex number: ");
printer(y);
printf("%s", prntop);
printer(ans);
return 0;
}


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

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

} stud;

float average (int score[5])
{
int sum=score[0]+score[1]+score[2]+score[3]+score[4];
float average = sum/5;
return average;
}

int main()
{
stud st[5];
strcpy(st[0].name,"Nicki");
strcpy(st[1].name,"Paul");
strcpy(st[2].name,"Sydney");
strcpy(st[3].name,"Sean");
strcpy(st[4].name,"Anjali");
st[0].age=14;
st[1].age=19;
st[2].age=16;
st[3].age=11;
st[4].age=3;
int st1sco[5]={100,92,36,74,58};
int st2sco[5]={60,32,78,98,22};
int st3sco[5]={76,29,40,81,69};
int st4sco[5]={84,10,29,48,79};
int st5sco[5]={92,84,71,67,13};
int g;
for (g=0;g<5;g++){
st[0].scores[g]=st1sco[g];
st[1].scores[g]=st2sco[g];
st[2].scores[g]=st3sco[g];
st[3].scores[g]=st4sco[g];
st[4].scores[g]=st5sco[g];
}
int h,i,j;
float avg[5];
for (h=0;h<5;h++){
avg[h]=average(st[h].scores);
}
for (i=0;i<5;i++){
printf("Name: %s\n",st[i].name);
printf("Age: %2d\n",st[i].age);
printf("Grades: ");
for(j=0;j<5;j++)
{
printf("%d ", st[i].scores[j]);
}
printf("\n");
printf("Average of grades: %4.2f\n", avg[i]);
}
return 0;
}