Write as program to manage a set of accounts within a binary file. An account has the following information.
account.h
#ifndef _ACCOUNT_H
#define _ACCOUNT_H
typedef struct account {
int balance;
int accountNum;
int zipcode;
int age;
} Account;
#endif
First you need to read the name of the file from the standard input. After you read the account information from the file, you need to write a summary report.
A sorted listing according to increasing accountNum. All accountNum are different.
A summary according to the preprocessor flag SORTBY
If the SORTBY flag is ZIPCODE, then you need to print the sum of balance of all accounts from the same zipcode, sorted by increasing zip code.
If the SORTBY flag is AGE, then you need to print the sum of balance of all accounts from the same age, sorted by increasing age.
You may assume that the constants AGE and ZIPCODE are 1 and 2 respectively.
Subtasks
5pt. There is only one record in the file, and the SORTBY flag is ZIPCODE.
10pt. There are no more than 3 records in the file, all zip codes are different, and the SORTBY flag is ZIPCODE.
15pt. There are no more than 10 records in the file, some zip codes may be the same, and the SORTBY flag is ZIPCODE.
20pt. There are no more than 1000 records in the file, and the SORTBY flag is AGE.
50pt. There are no more than 100000 records in the file.
Hints
If we sort the array according to a field, it becomes much easier to sum up all balance from that field.
Problem Description
Write as program to manage a set of accounts within a binary file. An account has the following information.
account.h
First you need to read the name of the file from the standard input. After you read the account information from the file, you need to write a summary report.
accountNum
. AllaccountNum
are different.SORTBY
SORTBY
flag isZIPCODE
, then you need to print the sum of balance of all accounts from the same zipcode, sorted by increasing zip code.SORTBY
flag isAGE
, then you need to print the sum of balance of all accounts from the same age, sorted by increasing age.You may assume that the constants AGE and ZIPCODE are 1 and 2 respectively.
Subtasks
SORTBY
flag isZIPCODE
.SORTBY
flag isZIPCODE
.SORTBY
flag isZIPCODE
.SORTBY
flag isAGE
.Hints
If we sort the array according to a field, it becomes much easier to sum up all balance from that field.
Sample Input
file download
Sample Output (if a
#define SORTBY ZIPCODE
is defined)Sample Output (if a
#define SORTBY AGE
is defined)Compile
part of main.c