Question: Fill in the following program so that it will open the input file, populate the array with your roommate's customer information, and respond to commands

Fill in the following program so that it will open the input file, populate the array with your roommate's customer information, and respond to commands of 1, 2, or 3 from the file.

#include

#define MAX_CUSTOMERS 100

int main() {

int numCommands, i, accounts[ MAX_CUSTOMERS ]; int command, id, amount, j, ok;

char filename[ 20 ];

[ Select ] ["FILE ifp", "FILE *ifp;", "file *ifp;", "f* ifp;"]

printf("What is the name of the file? ");

scanf("%s", filename); [ Select ] ["ifp = fopen(filename, "r");", "ifp = fopen("filename", "r");", "ifp = fopen(filename, "w");", "fopen(filename, "r");"]

[ Select ] ["for(i=0; i<10; i++)", "for(i=0; i 100)"]

[ Select ] ["accounts = 0;", "accounts[0..100] = 0;", "amount = 0;", "accounts[i] = 0;"]

fscanf(ifp, "%d", &numCommands);

for (i=0; i

[ Select ] ["fscanf(ifp, "%d", &command);", "fscanf("%d", &command);", "fscanf(ifp, "%d", command);", "fscanf(ifp, "%d", &amount);", "fprintf(ifp, "%d", &command);", "fprintf("%d", &command);", "fprintf(ifp, "%d", command);", "fprintf(ifp, "%d", amount);"]

if (command == 1) {

[ Select ] ["fscanf(ifp, "%d", id);", "fscanf(ifp, "%d %d", &id, &amount);", "fscanf(ifp, "%d", &amount);", "fscanf(ifp, "%d", &amount);", "fprintf(ifp, "%d", &id);", "fprintf(ifp, "%d %d", &id, &amount);", "fprintf("%d", &id);", "fprintf(ifp, "%d", amount);"]

accounts[ id ] += amount;

}

else if (command == 2) {

fscanf(ifp, "%d %d", &id, &amount);

[ Select ] ["amount = accounts[id];", "accounts[id] = amount;", "accounts[id] -= amount;", "accounts[id] += amount;"]

}

else {

ok = 1;

for (j=0; j

if ( [ Select ] ["j < 0", "accounts[j] < 0", "accounts < 0", "accounts[ 0 ] < j"] ) {

printf("Customer %d, you owe $%d. Please pay immediately! ", j, -accounts[ j ]);

ok = 0;

}

}

if (ok)

printf("All accounts are paid up to date!!! ");

}

}

[ Select ] ["fclose(ifp);", "fclose(filename);", "fclose("ifp");", "fileclose(ifp);"]

return 0;

}

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!