UNIVERSIDAD

REGIS

UNIVERSITY

CS362 – Data Structures

Dr. Jesús Borrego

Homework 5

A condo building has 10 floors, with 8 units per floor, labeled A-H.

You will store data about the status of each condo in the building in a two-dimensional array. Use all defined indexes (i.e. do not SKIP array index 0). Each condo can have a status of occupied, for sale, or for rent. The array should store the condo status using an enumerated type.

NOTE: You may want to create other additional enumerated types for use in this program.

This week you will store your data in a BINARY file, instead of a text file, between program runs.

The binary file, CONDO.BIN, will contain data on all for sale and for rent condo units (data on occupied units will NOT be stored). If the CONDO.BIN file does not exist when the program begins, all units will be assumed to be occupied. The first time you run the program, the CONDO.BIN file will not exist. Then after you run the program once, you will have a CONDO.BIN file, which you can use for subsequent runs.

For each for sale/for rent unit, the following three pieces of data will be stored in the file, in binary format:

- floor

- unit letter

- for sale or for rent (enumerated type)

NOTE: Any unit NOT listed in the data file is assumed to be occupied.

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

a) Initialize a two-dimensional array, representing the condo units in the building, to all occupied units.

b) Check if the CONDO.BIN file exists. If it does, read the data about for sale and for rent units from the file. (NOTE: Be sure to use an ifstream type variable to read from the file).

First read the floor, the unit letter, and the unit status value from the file. Then use the floor and unit letter values to store the enumerated unit status in the correct location in the 2D array. Be sure to read the floor, unit letter, and unit status 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 changes the unit statuses. All modifications 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 Occupied, For Sale, and For Rent condo units in the entire building to the screen.

Sample Output:

Current Status:

22 for sale

8 for rent

50 occupied

---

80 total units

If the building is fully occupied, do not display the status. Instead, the program should just issue a "No units available" type message and exit.

d) Loop, letting the user change the status of condo units.

i) Display a preference menu, prompting the user to choose to change the status of an occupied unit, a unit for sale, or a unit for rent, or choose "Done modifying".

Use mnemonic CHARACTERS as menu options (NOT numbers).

ii) Display all units of the specified type only (occupied, for sale, or for rent).

NOTE: You may format the output however you wish, as long as it does not run off the screen before the user can read it.

If there are zero condo units of the specified type, instead issue an error message and return to the preference menu.

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

Read and error check a floor Number and a unit Letter from the user.

NOTES ABOUT USER INPUT:

1) The user should be able to enter the floor number as numbers 1-10 and the unit letter as letters A-H. And the program should always display the floors as 1-15 and the units as A-H.

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

3) 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 or a string, the user will enter a char or a string.

iv) Verify the choice is of the type original requested (occupied, for sale, or for rent).

If the unit requested is not the same status as originally requested type, issue an error message.

If unit requested is the correct type and for sale or for rent, simply mark the unit chosen by the user as occupied in the array.

If unit requested is the correct type and occupied, ask whether to list it For Sale or For Rent. Then mark the unit chosen by the user as For Sale or For Rent in the array.

Continue to let the user modify condo statuses until s/he chooses " Done modifying" from the menu.

e) Again count and display the total number of Occupied, For Sale, and For Rent condo units 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 CONDO.BIN file in binary format. (NOTE: Be sure to use an ofstream type variable to write to the file).

Store the data on ONLY the for sale and for rent units. 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 occupied units).

The array holds one enumerated value in each cell (occupied, for sale, or for rent). But your program will need to write out three data values for each for sale or for rent unit (a floor, a unit letter, and a unit status).

Loop through each cell in the array. If the unit is NOT occupied, write the data (floor, unit letter, and unit status) for that unit out to the file.

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

g) Exit the program

This program should be of modular design (minimum of seven functions that have arguments), use proper parameter passing, and conform to the coding standards specified in the week-by-week. The main function should do little more than call other functions.

The program is due next week, on Wednesday, December 4, 2013. Submit your source code and related files in a zip file to WorldClass for week 6’s programming assignments.