From 29b7674887a9f7290cb1b090b34a72ea81cc7e96 Mon Sep 17 00:00:00 2001 From: cmg2213 Date: Thu, 7 Jul 2016 09:59:35 -0400 Subject: [PATCH] Add files via upload --- banking.c | 71 ++++++++++++++++++++++++++++++++++++++ complex.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++ homework6 | 11 ++++++ structDemo.c | 46 +++++++++++++++++++++++++ 4 files changed, 224 insertions(+) create mode 100644 banking.c create mode 100644 complex.c create mode 100644 homework6 create mode 100644 structDemo.c diff --git a/banking.c b/banking.c new file mode 100644 index 0000000..6d3af40 --- /dev/null +++ b/banking.c @@ -0,0 +1,71 @@ +#include +#include + +typedef struct{ + int accountNum; + char name[100]; + int balance; +}account; + +int deposit(int initial,int cash){ + initial = initial + cash; + return initial; + } +int withdraw(int initial,int cash){ + initial = initial - cash; + return initial; +} +int main(){ + int input; + int remove; + int choice; + int bankAccount; + account A1={2213,"Alex", 500}; + account A2={2214,"Caleb",600}; + printf("choose the account to draw from, 2213 or 2214\n"); + scanf("%d",&bankAccount); + if (bankAccount==2213){ + printf("choose whether to deposit(1) or withdraw(2)\n"); + scanf("%d",&choice); + if (choice==1){ + printf("Enter the money to deposit into the accounts: \n"); + scanf("%d",&input); + printf("The account number is: \n"); + printf("%d\n",A1.accountNum); + printf("the account name is Alex: \n"); + printf("The new total is: \n"); + printf("%d\n",deposit(A1.balance,input));} + else if (choice==2) + {printf("Enter the money you want to withdraw: \n"); + scanf("%d",&remove); + printf("The account number is: \n"); + printf("%d\n",A1.accountNum); + printf("the account name is Alex: \n"); + printf("The new total is: \n"); + printf("%d\n",withdraw(A1.balance,remove)); + } + } + else if (bankAccount==2214) + { + printf("choose whether to deposit(1) or withdraw(2)\n"); + scanf("%d",&choice); + if (choice==1){ + printf("Enter the money to deposit into the accounts: \n"); + scanf("%d",&input); + printf("The account number is: \n"); + printf("%d\n",A2.accountNum); + printf("the account name is Caleb: \n"); + printf("The new total is: \n"); + printf("%d\n",deposit(A2.balance,input));} + else if (choice==2) + {printf("Enter the money you want to withdraw: \n"); + scanf("%d",&remove); + printf("The account number is: \n"); + printf("%d\n",A2.accountNum); + printf("the account name is Caleb: \n"); + printf("The new total is: \n"); + printf("%d\n",withdraw(A2.balance,remove)); + } + } + return 0; + } diff --git a/complex.c b/complex.c new file mode 100644 index 0000000..cc2ef25 --- /dev/null +++ b/complex.c @@ -0,0 +1,96 @@ +#include +#include + +typedef struct{ + float A1; + float B1; + float A2; + float B2; +}comp; + +float addA(float a1, float a2){ + float total; + total = a1+a2; + return total; + } +float addB(float b1,float b2){ + float total; + total = b1+b2; + return total; + } +float subA(float a1, float a2){ + float total; + total = a1-a2; + return total; + } +float subB(float b1,float b2){ + float total; + total = b1-b2; + return total; + } +float multiplyReal(float a1, float a2, float b1, float b2){ + float total; + total = a1*a2-b1*b2; + return total; + } +float multiplyImg(float a1,float a2,float b1,float b2){ + float total; + total = a1*b2+a2*b1; + return total; + } +float divReal(float a1, float a2, float b1, float b2){ + float total; + total = ((a1*b1)+(a2*b2))/((b1*b1)+(b2*b2)); + return total; + } +float divImg(float a1, float a2, float b1, float b2){ + float total; + total = ((a2*b1)-(a1*b2))/((b1*b1)+(b2*b2)); + return total; + } + +int main (){ + int choice; + float a1,b1,a2,b2; + printf("enter you first A value\n"); + scanf("%f",&a1); + printf("enter you first B value\n"); + scanf("%f",&b1); + printf("enter you second A value\n"); + scanf("%f",&a2); + printf("enter you second B value\n"); + scanf("%f",&b2); + comp firstNum={a1,b1}; + comp secondNum={a2,b2}; + printf("Pick the operation (1 is +, 2 is -, 3 is *, 4 is /)\n"); + scanf("%d", &choice); + if (choice==1) + { + printf("%f\n",addA(a1,a2)); + printf("+\n"); + printf("%f\n",addB(b1,b2)); + printf("i\n"); + } + if (choice==2) + { + printf("%f\n",subA(a1,a2)); + printf("+\n"); + printf("%f\n",subB(b1,b2)); + printf("i\n"); + } + if (choice==3) + { + printf("%f\n",multiplyReal(a1,b1,a2,b2)); + printf("+\n"); + printf("%f\n",multiplyImg(a1,a2,b1,b2)); + printf("i\n"); + } + if (choice==4) + { + printf("%f\n",divReal(a1,b1,a2,b2)); + printf("+\n"); + printf("%f\n",divImg(a1,a2,b1,b2)); + printf("i\n"); +} +} + diff --git a/homework6 b/homework6 new file mode 100644 index 0000000..c4c934b --- /dev/null +++ b/homework6 @@ -0,0 +1,11 @@ +1: +It will print out a list of numbers: 203, 1, 23. +It stores the numbers originally in the data structure as 8,1,7, but it updates the set of numbers to their value that shows when it prints. + +2: +Structures are a way of storing large numbers in memory and accessing them easily, especially if they involve different data types, which differentiates them from arrays. +Emunerators just make indexing lists easier because they assign each space in an array with an interger that can be called and printed more easily. + +3: +When you pass an array, it can only deal with the types of data that are used in that specific array, and cannot access other data types. +When you pass a data structure however, it allows you to deal with all types of data that are stored in the data structure, which can be basically any data type. diff --git a/structDemo.c b/structDemo.c new file mode 100644 index 0000000..5678521 --- /dev/null +++ b/structDemo.c @@ -0,0 +1,46 @@ +#include +#include + + +typedef struct { + char name[100]; + int age; + int scores[5]; +} student; + +int average(student list){ + int i; + int total; + total = 0; + for (i=0;i<5;i++) + { + total = total + list.scores[i]; + } + total = total/5; + return total; +} + + +int main(){ + int i; + student st1={"Peter",17, {86,12,84,96,55}}; + student st2={"Caleb",17,{5,46,79,17,77}}; + student st3={"Alex",20,{55,66,77,88,99}}; + student st4={"Justin",16,{46,44,33,22,11}}; + student st5={"Andrew",16,{73,46,90,15,49}}; + + student studentArray[]={st1,st2,st3,st4,st5}; + + int arr[5]; + arr[0]=average(studentArray[0]); + arr[1]=average(studentArray[1]); + arr[2]=average(studentArray[2]); + arr[3]=average(studentArray[3]); + arr[4]=average(studentArray[4]); + for (i=0;i<5;i++) + { + printf("The average of the scores was: %d\n",arr[i]); + } +} + +