1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
|
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <iomanip>
#include <cctype>
#include <cmath>
using namespace std;
// CONSTANTS
const string BIN_OFFICE = "OFFICE.BIN"; // office file name
const int MAX_OFFICES = 50; // max number of offices in building
const int MAX_FLOORS = 5; // max number of floors
const int MAX_UNITS = 10; // max number of units per floor
const int MAX_STATUS = 3; // max number of possible statuses
//enum OFFICE_UNIT {A, B, C, D, E, F, G, H, I, J};
enum OFFICE_STATUS {OCCUPIED, AVAILABLE, REMODELING}; // status of the office
const string STAT1 = "OCCUPIED";
const string STAT2 = "AVAILABLE";
const string STAT3 = "REMODELING";
const char OCC = 'O';
const char AVA = 'A';
const char REM = 'R';
const char EXIT = 'D';
struct EachUnit {
int floor;
char unit;
char status; // status of unit
};
// Prototypes
void programDesc(); // program description
void OpenFile(ifstream& BinFile, int& officeTotal, int& floorCount, int& unitCount, EachUnit OfficeArray[][MAX_UNITS], int& occupiedCount);
void InitializeArray(EachUnit OfficeArray[][MAX_UNITS], int& floorCount, int& unitCount);
void ReadFile(ifstream& BinFile, EachUnit OfficeArray[][MAX_UNITS],int& theAvailable, int& theRemodeled, int& theOccupied, int& officeTotal);
void DisplayStatus(int& theAvailable, int& theRemodeled, int& occupiedCount, int& officeTotal);
void PreferenceMenu(EachUnit OfficeArray[][MAX_UNITS], char& choice, int& theOccupied, int& theAvailable, int& theRemodeled);
void ChoiceFunc(EachUnit OfficeArray[][MAX_UNITS], char& choice, int& theOccupied, int& theAvailable, int& theRemodeled);
void OccStatusDisplay(EachUnit OfficeArray[][MAX_UNITS], int& theOccupied);
void AVAStatusDisplay(EachUnit OfficeArray[][MAX_UNITS], int& theAvailable);
void REMStatusDisplay(EachUnit OfficeArray[][MAX_UNITS], int& theRemodeled);
void ModifyFunc(EachUnit OfficeArray[][MAX_UNITS], int& theAvailable, int& theOccupied, int&theRemodeled, int& officeTotal);
int UnitConvert(char& unitCount);
char ReUnitConversion(int& uCount);
void SaveData(ofstream& BoutFile, EachUnit OfficeArray[][MAX_UNITS]);
int main()
{
int officeTotal; // total number of offices
int floorCount, // number of floor
unitCount, // number of unit
availableCount = 0, // total number of available offices
remodelCount = 0, // total number of remodeling offices
occupiedCount = 0; // total number of occupied offices
int * theAvailable;
int * theRemodeled;
int * theOccupied;
char choice = ' ';
theAvailable = &availableCount;
theRemodeled = &remodelCount;
theOccupied = &occupiedCount;
EachUnit OfficeArray[MAX_FLOORS][MAX_UNITS];
ifstream BinFile;
ofstream BoutFile;
bool fileExists = true;
programDesc();
OpenFile(BinFile, officeTotal, floorCount, unitCount, OfficeArray, occupiedCount);
ReadFile(BinFile, OfficeArray,*theAvailable,*theRemodeled,*theOccupied, officeTotal);
DisplayStatus(*theAvailable, *theRemodeled, occupiedCount, officeTotal);
PreferenceMenu(OfficeArray, choice, *theOccupied, *theAvailable, *theRemodeled);
ModifyFunc(OfficeArray, *theAvailable, *theOccupied, *theRemodeled, officeTotal);
SaveData(BoutFile, OfficeArray);
return 0;
}
void programDesc()
{
cout << "This program will do this and that" << endl << endl;
}
void openFile(ifstream& BinFile, int& officeTotal, int& floorCount, int& unitCount, EachUnit OfficeArray[][MAX_UNITS], int& occupiedCount)
{
BinFile.open("OFFICE.bin" , ios::in | ios::binary);
if (BinFile)
{
cout << "File was opened successfully." << endl << endl;
}
else
{
//fileExists = false;
cout << "All of the units are assumed to be occupied." << endl << endl;
InitializeArray(OfficeArray, floorCount, unitCount);
occupiedCount = MAX_OFFICES;
}
}
void InitializeArray(EachUnit OfficeArray[][MAX_UNITS], int& floorCount, int& unitCount)
{
for(floorCount = 0; floorCount < MAX_FLOORS; floorCount++)
{
for(unitCount = 0; unitCount < MAX_UNITS; unitCount++)
{
OfficeArray[floorCount][unitCount].status = OCCUPIED;
}
}
}
void ReadFile(ifstream& BinFile, EachUnit OfficeArray[][MAX_UNITS], int& theAvailable, int& theRemodeled, int& theOccupied, int& officeTotal)
{
//int myfloor;
int fl = 0;
char theUnit = ' ';
int unitConverted;
char thestat = ' ';
if (BinFile)
{
while (BinFile)
{
BinFile.read((char*)&fl,sizeof(fl));
BinFile.read((char*)&theUnit, sizeof(theUnit));
BinFile.read((char*)&thestat,sizeof(thestat));
unitConverted = UnitConvert(theUnit);
OfficeArray[fl][unitConverted].floor = fl;
OfficeArray[fl][unitConverted].unit = theUnit;
OfficeArray[fl][unitConverted].status = thestat;
if (thestat == AVA) {
theAvailable++;
}
else if (thestat == REM){
theRemodeled++;
}
else
{
theOccupied++;
}
officeTotal++;
}
}
BinFile.close();
}
void DisplayStatus(int& theAvailable, int& theRemodeled, int& occupiedCount, int& officeTotal)
{
if (occupiedCount < MAX_OFFICES){
cout << "Current Status:" << endl;
cout << " " << occupiedCount << " " << STAT1 << endl;
cout << " " << theAvailable << " " << STAT2 << endl;
cout << " " << theRemodeled << " " << STAT3 << endl;
cout << " ----" << endl;
cout << " " << officeTotal << " Total Units" << endl;
}
else{
cout << "All units occupied. Program will now EXIT." << endl << endl;
}
}
|