Question: // this is task3 code #include #include //Defineing NUM_OPTIONS constant with 6 #define NUM_OPTIONS 6 //STEP:2 //Creating a structure with tag name 'account' struct account

 // this is task3 code #include #include //Defineing NUM_OPTIONS constant with

// this is task3 code

#include

#include

//Defineing NUM_OPTIONS constant with 6

#define NUM_OPTIONS 6

//STEP:2

//Creating a structure with tag name 'account'

struct account {

char bank_name[50];

int min_deposit;

float rate;

};

//Declaring an array with size of NUM_OPTIONS constant

struct account options[NUM_OPTIONS];

struct account make_account(char *bank, int min_deposit, float rate);

void print_earnings(float deposit);

int main(int argc, const char *argv[]){

// STEP:6

//pushing the different type of bank details data into options array;

options[0] = make_account("Adelaide Bank", 5000, 2.65f);

options[1] = make_account("BankSA", 10000, 2.45f);

options[2] = make_account("CommBank", 5000, 2.30f);

options[3] = make_account("ING", 10000, 2.85f);

options[4] = make_account("NAB", 5000, 2.40f);

options[5] = make_account("PCCU", 5000, 2.70f);

float amount = 0.0f;

printf("How much do you want to inyest? ");

scanf("%f", &amount);

print_earnings(amount);

return 0;

}

struct account make_account(char *bank, int min_deposit, float rate) {

//STEP:5

//creating a temp variable with type 'account'

struct account temp;

//copying the given bank min_deposit and rate into temp variable

strcpy(temp.bank_name , bank);;

temp.min_deposit = min_deposit;

temp.rate = rate;

//returing the temp variable.So that It can be stored in options array;

return temp;

}

void print_earnings(float deposit){

printf("This is how much you will earn in a year: ");

// Use this format string to help with the printf output of each account

printf("%-14s %14s %14s %12s ", "Institution", "Int. Rate", "Min. deposit", "Earnings");

//STEP:7

int i = 0;

//iterating over options array to calculate and print the earnings of each bank

for(i=0;i

float earning = 0;

//calculating the earning only if the deposit is greater than the min deposit

//otherwise it's zero

if(deposit >= options[i].min_deposit)

earning = (options[i].rate/100) * deposit;

//printing the bank details and calculated earning in a table format using format specifiers

printf("%-14s %14.2f %14d %14.2f ", options[i].bank_name, options[i].rate, options[i].min_deposit, earning);

}

}

Task 4 Convert the previous program to utilise multiple files. 1. Make a copy of your task3.c source file and name it task4a.c. 2. Open the files named task4b.h and task4b.c. 3. In task4a..*include the task4b.h header. 4. Migrate aspects of task4a to task4b oMove the struct declaration to task4b.h. Move the two functions prototypes, make_account and print earnings, to task4b.h. Modify the signature of the print earnings function to match the following void print_earnings (float deposit, struct account *options, int num): Move the definitions of make_account and print_earnings to task4b.c. Once again, modify the signature of the print earnings function to match the previous step 5. Fix the print_earnings function in task4b.c to work with its new parameters. You no longer have access to the options array or NUM_OPTIONS macro so you will have to loop through account options via the pointer reference. 6. Modify the call to print earnings in the main function of task4a.c to pass in the options array and size (NUM_OPTIONS). 7. Write a makefile to compile task4a.c and task4b.c. Refer to the lecture slides for an example of a makefile for multiple source files. You do not need to explicity compile the task4b.h header file; it will be compiled when one of the files it is included in is. Hint: You will need three rules: one to build the object files for task4a, one to build the object files for task4b, and one to link them together to form the final program: task4: task4a.o task4b.o gcc. task4a.o: gcc. task4b.o: gcc. 8. Compile your program with make. Verify the output is unchanged from Task 3

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!