# 50033. Accounts

## Problem Description

Write as program to manage a set of accounts within a binary file. An account has the following information.

### account.h

1234567891011#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.

## Sample Input

p10075-sample.bin


file download

## Sample Output (if a #define SORTBY ZIPCODE is defined)

account, age, zipcode, balance0, 24, 100, 60002, 24, 101, 62003, 25, 100, 65005, 24, 100, 63007, 26, 101, 6000zipcode, sum_balance100, 18800101, 12200


## Sample Output (if a #define SORTBY AGE is defined)

account, age, zipcode, balance0, 24, 100, 60002, 24, 101, 62003, 25, 100, 65005, 24, 100, 63007, 26, 101, 6000age, sum_balance24, 1850025, 650026, 6000


## Compile

$gcc -std=c99 -O2 a.c -DSORTBY=ZIPCODE -DAGE=1 -DZIPCODE=2 -o testzip.out$ gcc -std=c99 -O2 a.c -DSORTBY=AGE -DAGE=1 -DZIPCODE=2 -o testage.out


## part of main.c

#define AGE 1#define ZIPCODE 2


## Testdata Set

Download Testdata