Write a modular program to do initialize a two-d array

Assignment Help Programming Languages
Reference no: EM131321739

Assignment

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.

NOTES ABOUT USER INPUT:

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.

Reference no: EM131321739

Questions Cloud

Density of the person to be about the same : If the density of the life preserver is 100 kg/m3 and it is completely submerged, what must its volume be? Assume that the density of the person to be about the same as the density of water, 1000 kg/m3.
Astronomy and critical thinking : You are standing within a small town on the east coast of the United States looking westward, with one big difference from normal reality:
Develop a research proposal outline : You have selected a research topic and a research methodology to use for that topic. You are now ready to take that topic and develop a research proposal outline. The proposal outline is the documentation of your research design
What is its speed at the bottom of the hill : A child and sled with a combined mass of 52.7 kg slide down a frictionless hill that is 10.9 m high at an angle of 29? from horizontal. The acceleration of gravity is 9.81 m/s2 . If the sled starts from rest, what is its speed at the bottom of the..
Write a modular program to do initialize a two-d array : Write a modular program (minimum of NINE functions that have arguments or return values), to do the Initialize a two-dimensional array, representing the offices in the building, to all EMPTY offices.
Discuss the concept of global privilege : With the principle of "least privileged," is it possible to have too much authorization? What happens when there is too much authorization?
Significant digits and in scientific notation : A certain sound has an intensity of 9.195275×10-4 W/m2 2.33 m from its source. What is the power emitted by this source in watts? Express your result to three significant digits and in scientific notation. Hint: The area of a sphere is 4πr2
Provide a realistic example of a trade-off : Then address the following: Provide a realistic example of a trade-off, where one of these three items is optimized at the detriment of the other two items
Internal energy of the gas : An ideal gas is compressed isobarically from 8.72 m3 to 5.41 m3 at a pressure of 2.04 x 105 Pa due to the addition of 2.35 x 105 J of heat. What is the change in the internal energy of the gas? Express your result in scientific notation and to thre..

Reviews

Write a Review

Programming Languages Questions & Answers

  Design program that determines males live in zip code area

Design a program that determines how many males and females live in each of the Zip Code areas in the Student Enrollment Records Set.

  Write program to create n-dimensional array on th runtime

Write a program to create an n-dimensional array on the runtime with the help of pointers. The user will enter on the run time that how many dimensions are required.

  A program is required which prompts the user

A program is required which prompts the user to enter the individual price of 3 different items and computes and prints the total cost of the 3 items as well as the average cost. remember to add sales tax (5% or 0.05) to the total cost.

  1 protecting the american food supply from terrorist

1. protecting the american food supply from terrorist attacks or natural contamination is a difficult task. the fda and

  Write program to read data of four students from input file

Write C++ program which reads data of 4 students from the input file which name is given by user and displays summary report of students' marks on output file stdMarks.out"

  User defined function to calculate average of three scores

A user defined function that will calculate and display the average of the 3 scores that remain after dropping the highest and lowest scores the performer received.

  Design a flowchart or pseudocode

Design a flowchart or pseudocode for the following:A program that accepts a candy name (for example, "chocolate-covered blueberries"), price per pound, and number of pounds sold in the average month, and displays the item's data only if it is a be..

  Create a class diagram and define the classes

Completed class diagram should show each object's encapsulated methods, the inheritance between subject and course, and the composition of students in courses.

  Implement DFS by using prolog

What can Rowena do to get 4 ounces of liquid into each of the larger two glasses - Implement DFS by using PROLOG.

  Lotteries is that a distinctive sequence

a common misconception about lotteries is that a distinctive sequence, such as 0-0-0-0, is less likely D occur than a random-looking sequence, such as 3-7-5-2. In reality, each number sequence has the ame probability of appearing. It just so happe..

  Function that normalizes a numeric vector

Create a function that normalizes a numeric vector (returns a unit vector).

  Application to print the sum of cubes

Write down the application to print the sum of cubes. Prompt for and read two integer values and print sum of each value raised to third power.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd