Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //MainASPER.cpp
- #include <iostream>
- #include <string>
- #include <iomanip>
- #include <fstream>
- #include <sstream>
- #include <cstdlib>
- using namespace std;
- #include "Owner.h"
- #include "Client.h"
- #include "Staff.h"
- void OwnerToFile();
- void PersonToFile();
- void StaffMenu();
- void ViewAddSuiteOwner();
- void AddSuiteOwner();
- void AddUser();
- void ClientMenu();
- void DeleteUsers();
- void outputOwner();
- void outputUser();
- void OwnerMenu();
- void ViewAllSuite();
- void DisplayUser();
- int main (){
- fstream check("PersonDetails.dat", ios::in | ios::out | ios::binary);
- Person PersonY;
- string username;
- string password;
- cout << "*************************************************************" << endl;
- cout << "* APSER SERVICE APARTMENT MANAGEMENT SYSTEM (SAMS) *" << endl;
- cout << "* *" << endl;
- cout << "*-----------------------------------------------------------*" << endl;
- cout << "* Login *" << endl;
- cout << "*-----------------------------------------------------------*" << endl;
- cout << "* *" << endl;
- cout << "*************************************************************" << endl;
- cout << " " << endl;
- cout << "Please Enter Your Username: ";
- cin >> username;
- cout << "Please Enter Your Password: ";
- cin >> password;
- while(!check.eof())
- {
- check.read(reinterpret_cast<char*>(&PersonY), sizeof(Person));
- if(PersonY.getUsername() == username && PersonY.getPassword() == password)
- break;
- }
- if(PersonY.getUsername() == username && PersonY.getPassword() == password && PersonY.getUserType() == 1)
- StaffMenu();
- else if(PersonY.getUsername() == username && PersonY.getPassword() == password && PersonY.getUserType() == 2)
- OwnerMenu();
- else if(PersonY.getUsername() == username && PersonY.getPassword() == password && PersonY.getUserType() == 3)
- ClientMenu();
- else
- cerr << "Wrong username and password entered" << endl;
- check.flush();
- check.close();
- }
- void StaffMenu() {
- int StaffChoice = 0;
- system("cls");
- cout << "***************************************************************************" <<endl;
- cout << "* APSER SERVICE APARTMENT MANAGEMENT SYSTEM (SAMS) *" << endl;
- cout << "*-------------------------------------------------------------------------*" <<endl;
- cout << "*---------------------------You have login as a Staff---------------------*" <<endl;
- cout << "* 1 - Display User *" <<endl;
- cout << "* 2 - Add User *" <<endl;
- cout << "* 3 - Delete Suite Records *" <<endl;
- cout << "* 4 - View/Add Suite Records *" <<endl;
- cout << "*-------------------------------------------------------------------------*" <<endl;
- cout << "* 5 - Back To Login *" <<endl;
- cout << "* 6 - Exit *" <<endl;
- cout << "***************************************************************************" <<endl;
- cin >> StaffChoice;
- switch(StaffChoice)
- {
- case 1:
- DisplayUser();
- break;
- case 2:
- AddUser();
- break;
- case 3:
- DeleteUsers();
- break;
- case 4:
- ViewAddSuiteOwner();
- break;
- case 5:
- main();
- break;
- case 6:
- exit(1);
- break;
- default:
- cerr << "Invalid Choice" << endl;
- break;
- }
- }
- void ViewAddSuiteOwner() {
- int decision;
- cout << "*****************************************" << endl;
- cout << "* SUITE RECORDS *" << endl;
- cout << "*---------------------------------------*" << endl;
- cout << "* 1 - Add Suite Owner *" << endl;
- cout << "* 2 - View All Suite *" << endl;
- cout << "*---------------------------------------*" << endl;
- cout << "* 0 - Exit *" << endl;
- cout << "*****************************************" << endl;
- cin >> decision;
- if(decision == 1)
- AddSuiteOwner();
- else if(decision == 2)
- ViewAllSuite();
- else if (decision == 0)
- StaffMenu();
- else
- cout << "Invalid Input, Please Re-enter Again" << endl;
- }
- void AddSuiteOwner() {
- fstream addSuite("SuiteOwnerDetails.dat", ios::in | ios::out | ios::binary);
- fstream addOwner("PersonDetails.dat", ios::in | ios::out | ios::binary);
- int ID;
- do{
- cout << "Enter id number between (1-50): ";
- cin >> ID;
- } while(ID < 1 || ID > 50);
- addOwner.seekg((ID - 1)*sizeof(Person));
- Person add;
- addOwner.read(reinterpret_cast<char *>(&add), sizeof(Person));
- if(add.getAccID() == 0)
- {
- int SuiteID;
- int UserType=2;
- string Username;
- string Password;
- string ContactNo;
- string Address;
- string SuiteAddress;
- int NBD;
- int NBT;
- int Facilities;
- int Area;
- int Rental;
- int Availability=0; // 0=Free/Available at default, 1=Booked;
- cout << "Enter username : " << endl;
- cin >> Username;
- cout << "Enter password : " << endl;
- cin >> Password;
- cout << "Enter contact no : " << endl;
- cin >> ContactNo;
- cout << "Enter address : " << endl;
- cin >> Address;
- cout << "Enter suiteID : " << endl;
- cin >> SuiteID;
- cout << "Enter address : " << endl;
- cin >> SuiteAddress;
- cout << "Enter no of bedrooms : " << endl;
- cin >> NBD;
- cout << "Enter no of bathrooms : " << endl;
- cin >> NBT;
- cout << "1. TV" << endl;
- cout << "2. Heater" << endl;
- cout << "3. Air-condiotioner" << endl;
- cout << "4. Internet" << endl;
- cout << "Type any number of facilities you want to include" << endl;
- cin >> Facilities;
- cout << "Enter area of the apartment : " << endl;
- cin >> Area;
- cout << "Enter the rental types (1-Daily, 2-Weekly, 3-Monthly) : " << endl;
- cin >> Rental;
- add.setPerson(ID, UserType, Username, Password, ContactNo, Address);
- addOwner.seekp((ID-1) * sizeof(Person));
- addOwner.write(reinterpret_cast<const char *>(&add), sizeof(Person));
- Owner Add;
- Add.setOwner(ID,UserType, Username, Password, ContactNo, Address, SuiteID, SuiteAddress, NBD, NBT, Facilities, Area , Rental, Availability);
- addSuite.seekp((SuiteID - 1) * sizeof(Owner));
- addSuite.write(reinterpret_cast<const char*>(&Add), sizeof(Owner));
- }
- else
- cerr << "The ID number has been used" << endl;
- }
- void ViewAllSuite()
- {
- /*
- fstream output("SuiteOwnerDetails.dat", ios::in | ios::out | ios::binary);
- output.seekg(0);
- Owner viewas;
- while(!output.eof())
- {
- output.read(reinterpret_cast< char *>(&viewas), sizeof(Owner));
- outputOwner(viewas.getAccID(), viewas.getUserType(),viewas.getUsername(), viewas.getPassword(), viewas.getContactNo(), viewas.getAddress(), viewas.getSuiteID(), viewas.getSuiteAddress(), viewas.getNoBedrooms(),viewas.getNoBathrooms(),viewas.getFacilities(),viewas.getArea(),viewas.getRent(),viewas.getAvailability());
- }
- */
- }
- //Done
- void DisplayUser()
- {
- /*
- fstream display("PersonDetails.dat", ios::in | ios::out | ios::binary);
- display.seekg(0);
- Person show;
- display.read(reinterpret_cast<char *>(&show), sizeof(Person));
- cout << left << " | " << setw(10) << "ID"
- << " | " << setw(10) << "User Type"
- << " | " << setw(25) << "Username"
- << " | " << setw(25) << "Password"
- << " | " << setw(11) << "Contact No"
- << " | " << setw(35) << "Address" <<endl;
- while(!display.eof())
- {
- display.read(reinterpret_cast< char *>(&show), sizeof(Person));
- outputUser(show.getAccID(), show.getUserType(),show.getUsername(), show.getPassword(), show.getContactNo(), show.getAddress());
- }
- */
- }
- //
- void AddUser() //Staff and Client only
- {
- fstream input("PersonDetails.dat", ios::in | ios::out | ios::binary);
- int ID;
- do{
- cout << "Enter id number between (1-50): ";
- cin >> ID;
- } while(ID < 1 || ID > 50);
- input.seekg((ID - 1)*sizeof(Person));
- Person add;
- input.read(reinterpret_cast<char *>(&add), sizeof(Person));
- if(add.getAccID() == 0)
- {
- int UserType;
- string Username;
- string Password;
- string ContactNo;
- string Address;
- int choice = 0;
- cout << "Enter username : " << endl;
- cin >> Username;
- cout << "Enter password : " << endl;
- cin >> Password;
- cout << "Enter contact no : " << endl;
- cin >> ContactNo;
- cout << "Enter address : " << endl;
- cin >> Address;
- do{
- cout << "1. Staff" << endl;
- cout << "2. Client"<<endl;
- cout << "Choose User Type : " << endl;
- cin >> choice;
- if(choice == 1)
- UserType = 1;
- else if(choice == 2)
- UserType = 3;
- else //Invalid
- break;
- }while(choice <= 0 || choice >= 4);
- add.setPerson(ID, UserType, Username, Password, ContactNo, Address);
- input.seekp((ID-1) * sizeof(Person));
- input.write(reinterpret_cast<const char *>(&add), sizeof(Person));
- }
- else
- cerr << "The ID number has been used" << endl;
- }
- void DeleteUsers()
- {
- fstream deleteRecord("PersonDetails.dat", ios::in | ios::out | ios::binary);
- int ID;
- do{
- cout << "Enter id number between (1-50) that you want to delete: ";
- cin >> ID;
- } while(ID < 1 || ID > 100);
- deleteRecord.seekg((ID - 1)*sizeof(Person));
- Person Check;
- deleteRecord.read(reinterpret_cast<char *>(&Check), sizeof(Person));
- if(Check.getAccID() != 0)
- {
- Person Delete;
- Delete.setPerson(0, 0, "", "", "", "");
- deleteRecord.seekp((ID - 1) * sizeof(Person));
- deleteRecord.write(reinterpret_cast<const char*>(&Delete), sizeof(Person));
- cout << "ID #" << ID << " is deleted." << endl;
- }
- else
- cerr << "ID #" << ID << " is empty." << endl;
- }
- void outputUser(int ID, int UserType, const string Username, const string Password, const string ContactNo, const string Address)
- {
- cout << left << " | " << setw(10) << ID
- << " | " << setw(10) << UserType
- << " | " << setw(25) << Username
- << " | " << setw(25) << Password
- << " | " << setw(11) << ContactNo
- << " | " << setw(35) << Address <<endl;
- }
- void outputOwner(int ID, int UserType, string Username, string Password, string ContactNo, string Address, int SuiteID,string SuiteAddress, int NoBedrooms, int NoBathrooms, int Facilities,int Area, int Rent, int Availability)
- {
- cout << left << " | " << setw(10) << ID
- << " | " << setw(10) << UserType
- << " | " << setw(25) << Username
- << " | " << setw(25) << Password
- << " | " << setw(11) << ContactNo
- << " | " << setw(35) << Address
- << " | " << setw(10) << SuiteID
- << " | " << setw(25) << SuiteAddress
- << " | " << setw(10) << NoBedrooms
- << " | " << setw(10) << NoBathrooms
- << " | " << setw(15) << Facilities
- << " | " << setw(10) << Area
- << " | " << setw(25) << Rent
- << " | " << setw(10) << Availability <<endl;
- }
- void ClientMenu()
- {
- }
- void OwnerMenu()
- {
- }
Add Comment
Please, Sign In to add comment