//This a partially completed prototype of project 2
//currently use file FlatData1.dat as its initial roster
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <stdlib.h>
#include <cstring>
#include <algorithm>
using namespace std;
typedef enum { thisWeek, nextWeek } WEEK;
typedef enum { clean, wash, shop } DUTY_TYPE;
typedef enum { lounge,tv,bathroom} RESOURCES_TYPE;
typedef enum {addresident,deleteresident} MANAGERS_TASK;
class RESIDENT {
string name;
public:
RESIDENT() { name = ""; }
RESIDENT(string n) { name = n; }
string getName() { return name; }
void setResident(string n) { name = n; }
};
//Boundary object - HOME PAGE
//Only boundary object as we have no GUI capability
class HOMEPAGE {
string loginName;
string Password;
MANAGERS_TASK managerstask;
public:
void login() {
cout << "Login: ";
cin >> loginName;
}
void password() {
cout<< "Password:";
cin>> Password;
}
void selectManagement(vector <string> &residents);
string getLoginName(){ return loginName; }
string getPassword() { return Password;}
MANAGERS_TASK getManagersTask() {return managerstask;}
};
void HOMEPAGE::selectManagrTask(vector <string> &residents)
{
string residentname;
char option;
int a;
cout << "select ManagersTask" << endl;
cout << "a) Add Resident " << endl;
cout << "b) Delete Resident" << endl;
cout << "make selection: ";
cin >> option;
switch(option) {
case 'a': managerstask = addresident;
cout<<" Enter Resident Name ";
cin>> residentname;
for ( a = 0; a< residents.size(); a++)
{if (residents.at(a) != residentname){ residents.push_back(residentname);cout <<"Add New Resident ";}
else cout<<"No New Resident to add ";
break;
case 'b': managerstask = deleteresident;
cout<<" Enter Resident Name ";
cin>> residentname;
for ( a = 0; a< residents.size(); a++)
{if (residents.at(a) == residentname){ residents.erase(residents.begin()+a); cout<<"Delete Resident ";}
else cout<<"No Resident to delete ";
break;
default: cout << " managertask not recognised" << option << endl;
break;
}
}
void loadfile( vector <string> &residents){
ifstream myfile;
string line;
int a=0;
myfile.open("residentfile.txt");
if (myfile.is_open())
{
// Read the file until it's finished, displaying lines as we go.
while (!myfile.eof())
{
getline(myfile, line, '\n'); // getline reads a line at a time
residents.push_back(line);
a++;
}
myfile.close();
}
else // Some kind of error opening the file
{
cout << "ERROR: Could not open the residentfile: " <<myfile << endl;
exit(1);
}
}
void UpdateFile( vector <string> &residents){
ofstream myfile;
myfile.open("residentfile.txt");
if (myfile.is_open())
{
for (int a=0; a<(residents.size()); a++)
myfile << residents[a] << endl;
myfile.close();
}
else
{
cout << "ERROR: could not open file: " << "residentfile.txt" << endl;
cout << "If absent, please create an EMPTY dat file named " << "residentfile.txt" << " in directory." << endl;
}
}
int main()
{
HOMEPAGE home;
string fileName("FlatData1.dat");
string residentname;
vector <string> residents;
home.login();
home.password();
loadfile(residents);
if (residents.at(0) == home.getLoginName()){ cout<<"Manager Home Page"<<endl; home.selectManagerTask(residents);}
else {cout<<"Rsidient Home Page" << endl;}
UpdateFile(residents);
system("pause");
return 0;
}}}
awesome3000 0 Newbie Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
awesome3000 0 Newbie Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.