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
[ 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started