An office building

An office building

An office building has 5 floors (4 levels above ground and a basement at level 0). There are 8 offices per floor, labeled A - H.

This program will maintain data about the occupant type of employees in each office in the building. The data will be stored in a two-dimensional array. (Be sure to use all defined indexes -- i.e. do not SKIP array index 0 for rows or columns).

Each office will be categorized by the type of employee assigned to the office. Possible occupant type values are: EMPTY, LAWYER, PARALEGAL, ASSISTANT. The array should store the occupant type using an enumerated type.

This week the program will store data into a BINARY file, instead of a text file, between runs. The binary file, BUILDING.BIN, will contain data on all occupied offices (data on EMPTY offices will NOT be stored).

For each for occupied office, the following three pieces of data will be stored in the file, in binary format:

- floor (row) index within the array

- office (column) index within the array

- occupant type (enumerated type)

NOTE: Any office NOT listed in the data file will be assumed to be EMPTY.

The first time you run the program, the BUILDING.BIN file will not exist. Then after you run the program once, you will have a BUILDING.BIN file, which you can use for subsequent runs.

If the BUILDING.BIN file does not exist when the program begins (for example, on the first run), all offices will be assumed to be EMPTY.

Program Details

Write a modular program (minimum of NINE functions that have arguments or return values), to do the following:

a) Initialize a two-dimensional array, representing the offices in the building, to all EMPTY offices.

b) Check if the BUILDING.BIN file exists. If it does, read the data about the occupied offices from the file. (NOTE: Be sure to use an ifstream type variable to read from the file).

First read the floor index, the office index, and the occupant type values from the file. Then use the floor and office indexes to store the occupant type in the correct location in the 2D array.

Be sure to read the floor index, office index, and occupant type in the same order that they were written to the file. A program's correct interpretation of the binary data is dependent upon reading the data in the same order that it was originally written.

NOTE: After you read the data from the file, you will not be using the file again while the user modifies values. All modifications, in part d below, will be made in the 2D array. You will not access the file again until the user chooses to exit the program.

c) Using the data in the array, count and display the total number of Lawyers, Paralegals, and Assistants in occupied offices in the entire building to the screen.

Sample Output:

Current Office Status (40 total offices):

8 lawyers

10 paralegals

13 assistants


31 occupied offices

d) In a loop, allow the user to modify the occupant status of various offices.

i) Display the following office occupant status modification menu choices:

1 - Change office from occupied to empty

2 - Modify office occupant type

3 - Change office from empty to occupied

D - Done making modifications

Allow user to choose from menu. Validate choice and loop until valid choice is made.

ii) Neatly display all offices of the specified type only (either occupied or empty).

For example, if the user chooses to change the office occupant type (or change an office from occupied to empty), the program would display all occupied offices:

Occupied offices:

4A 4B 4D 4E 4F

3A 3B 3C 3D 3E 3F 3G 3H

2A 2B 2C 2E 2G

1A 1B 1C 1D 1E 1F 1G 1H

0A 0B 0C 0G 0H

So if the user chooses to change from empty to occupied, the program would display all empty offices instead.

NOTE: If there are zero offices of the specified type, instead issue an error message and return to the occupant status modification menu immediately.

iii) Ask for the user's choice from the list displayed

Read and error check the floor Number and office Letter from the user.

- Verify the floor number is in the correct range (0-4).

- Verify the office letter is in the correct range (A-H).

Loop until a valid the floor Number and office Letter are entered.


1) You can make the following assumption about data entered by the user (i.e. you do not have to error check these situations):

If you request a number, the user will enter a number.

If you request a char, the user will enter a char.

Characters may be entered in either upper or lowercase

(both should be recognized as the same)

2) Array indexes begin at 0, so the program should transparently take care of converting the user's office letter choices from a letter to the correct numeric indexes in the array, and vice versa.

iv) Validate that the choice is of the type original requested (occupied or empty).

If the office requested is not the same type as originally requested type (For example, if the user chooses to change from occupied to empty, but then enters an office that is already empty), issue an error message saying so. Loop until the floor Number and office Letter are the correct type.

v) Modify the office status

1) If the user chose to change from occupied to empty (and the office was verified as occupied), simply mark the office chosen by the user as EMPTY in the array.

Then display a message confirming the change was made. Example:

Office 2C is now empty.

2) If the user chooses to change occupant type (and the office is verified as occupied) or if the user chooses change from empty to occupied (and the office is verified as empty), display an occupant type menu: LAWYER, PARALEGAL or ASSISTANT

Validate the user choice. Once a valid choice has been entered, change the office status stored in the array to the new value chosen.

Then display a message confirming the change was made. Example:

Office 2D is now occupied by a paralegal.

Continue to let the user modify office occupant statuses until s/he chooses "Done" from the office occupant status modification menu.

e) Again count and display the total number of Lawyers, Paralegals, and Assistants in occupied offices in the entire building to the screen (same as (c) above). Pause until the user is done viewing the data.

f) Save the data in the array back to the BUILDING.BIN file in binary format. (NOTE: Be sure to use an ofstream type variable to write to the file).

The data should overwrite the original BUILDING.BIN, if it previously existed.

Store ONLY the data on the occupied offices. This means that you will NOT be able to just write the entire array out to the file at once (because that would also save data on empty offices).

The array holds one enumerated value in each cell (EMPTY, LAWYER, PARALEGAL, or ASSISTANT). But your program will need to write out three data values for each occupied office (a floor index, an office index, and an office occupant type), so you can place the enumerated value back to the correct place when the data is later read.

Loop through each cell in the array. If the office is occupied, write the data (floor index, office index, and office occupant type) for that office out to the file.

Display a message indicating that the data has been saved.

g) Exit the program

Programming Notes:

1. Your program must conform to all CS362 Coding Standards specified in Content section 1.7.

2. This program should be of modular design (minimum of NINE functions that have arguments or return values), use proper parameter passing and prototypes.

The module breakdown should be logical, with main doing little more than call other functions, and the other functions each performing only one well-defined task.

3. All code will be structured C++ code. Object-oriented programming (classes, templates, etc) will not be used.

4. Your program should be thoroughly tested, and test data files should be submitted.



- your program code

- any data files used to test your code, and a description of how you used them to test your code

to the Wk 5 – Assn 4 folder in the Dropbox area of the online course, by midnight, Sunday of week 5 (next week).


Your program will NOT be accepted if it:

 does not compile

 uses any global variables

 is not adequately modular (i.e. contains fewer than the required number of functions)

Before attaching your files to the assignment submission, please NAME them as follows:


LastnameDatafilename#.txt (number each test data file)

LastnameTestDescription.docx (or .doc, or .txt)

For example:





However, within your code, please use the RELATIVE input/output file names (no drive or pathnames) without your last name appended:


Powered by