p-Parking-Garage / CSC330_MidtermProj_Parking / Source.cpp
Source.cpp
Raw
// Project Title: Parking Garage
// CSC 330 - Midterm Project
// Code by: Christopher Fernandez
//

#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <Windows.h>
#include "Apartment.h"
#include "Garage.h"
#include "Person.h"
#include "Member.h"
#include "Employee.h"
#include "Guest.h"

using namespace std;

void HourlyRateMenu();
void FancyText();

int main(int argc, char * argv[])
{
	// Cin entry options for users
	string userChoice;
	int guestTicket = 0; // Random number generated for ticket stub
	int hourEntry = 0;
	int guestCost = 0;
	string licplate;

	// oStream guest data creation
	ofstream guestData; // will print out the ticket for Guest to park
	ofstream garOutFile; // will update our garage after somebody parks and a spot is taken

	// For second level of security on member login & employee login
	// See code on 215 & 227 for member login. See code on 254 & 266 for employee login
	// Functions for these are in Apartment, Employee, & Member.
	string apNamecmp;
	string memNamecmp;
	string empNamecmp1;
	string empNamecmp2;

	// For memberList.txt
	ifstream memFile;
	string MemberFile;
	MemberFile = argv[1];
	memFile.open(MemberFile);

	// For apartmentBuilding.txt
	ifstream apFile;
	string ApartFile;
	ApartFile = argv[2];
	apFile.open(ApartFile);

	// For Employee.txt
	ifstream empFile;
	string EmployeeFile;
	EmployeeFile = argv[3];
	empFile.open(EmployeeFile);

	// For Garage.txt
	ifstream garFile;
	string GarageFile;
	GarageFile = argv[4];
	garFile.open(GarageFile);

	// Make sure each database loads correctly
	if (memFile.fail())
	{
		cerr << "Error Opening MemberList database!" << endl;
		exit(1);
	}

	if (apFile.fail())
	{
		cerr << "Error Opening Apartment Building database!" << endl;
		exit(1);
	}

	if (empFile.fail())
	{
		cerr << "Error Opening Employee database!" << endl;
		exit(1);
	}

	if (garFile.fail())
	{
		cerr << "Error Opening Garage database!" << endl;
		exit(1);
	}

	// variables to read database input
	string name;
	string aptno;
	string avail;
	string id;
	string password;
	string restofline;
	string parkingspot;

	////////////// Read in Member.txt database
	vector <Member> membersVec;
	while (!memFile.eof())
	{
		getline(memFile, restofline, ':');
		getline(memFile, restofline, ' ');
		getline(memFile, name);
		getline(memFile, restofline, ':');
		getline(memFile, restofline, ' ');
		getline(memFile, id);
		memFile.ignore(1);
		Person * member = new Member(name, id);
		membersVec.push_back(Member(name, id));
	}
	Member * member = new Member(); // needs to be redeclared outside loop

	////////////// Read in ApartmentBuilding.txt database
	vector <Apartment> apartmentVec;
	while (!apFile.eof())
	{
		getline(apFile, aptno, ':');
		getline(apFile, restofline, ' ');
		getline(apFile, avail, ':');
		getline(apFile, restofline, ' ');
		getline(apFile, name);
		Apartment * apartInfo = new Apartment(aptno, avail, name);
		apartmentVec.push_back(Apartment(aptno, avail, name));
	}
	Apartment * apartInfo = new Apartment(); // needs to be redeclared outside loop

	////////////// Read in Employee.txt database
	vector <Employee> employeesVec;
	while (!empFile.eof())
	{
		getline(empFile, restofline, ':');
		getline(empFile, restofline, ' ');
		getline(empFile, name);
		getline(empFile, restofline, ':');
		getline(empFile, restofline, ' ');
		getline(empFile, id);
		getline(empFile, restofline, ':');
		getline(empFile, restofline, ' ');
		getline(empFile, password);
		empFile.ignore(1);
		Person * employee = new Employee(name, id, password);
		employeesVec.push_back(Employee(name, id, password));
	}
	Employee * employee = new Employee(); // needs to be redeclared outside loop

	////////////// ParkingGarage.txt database
	// Parking Garage will be read INSIDE our class using a function. Completely seperate from Person class (No inheritance).
	// Will use a string input (gst, mem, emp) to search & designate available spots
	// If a user is granted access to our garage, the garage will change from a FREE spot to a RESERVED spot.
	Garage * parkGar = new Garage(5, 16, 15, 300); // (5 Floors, 16 spots, $15 hourly fee, $300 monthly fee)
	parkGar->readGarage(garFile);


	// Close all files
	memFile.close();
	apFile.close();
	empFile.close();
	garFile.close();

	// -------------------------MENU FOR USER-------------------------
	cout << "Greetings user! Welcome to the CSC 330 Parking Garage." << endl;
	do {
		cout << "Please choose from the following options:" << endl;
		cout << "1) Guest Parking" << endl;
		cout << "2) Member Parking" << endl;
		cout << "3) Employee Parking" << endl;
		cout << "4) Exit" << endl;

		getline(cin, userChoice);
		
		if (userChoice == "1")
		{
			HourlyRateMenu();
			cout << "How long would you like to stay here for?" << endl;
			do{
			cin >> hourEntry;
			cin.ignore(1);
				if (hourEntry >= 1 && hourEntry <= 24)
				{
					guestCost = (hourEntry * 15);
					cout << "For " << hourEntry << " hours your cost will be: $" << guestCost << " dollars" << endl;
				}
				else
				{
					cout << "Invalid entry, try again." << endl;
				}
			} while (hourEntry <= 0 || hourEntry >= 25);
			cout << "Please enter you first and last name." << endl;
			getline(cin, name);
			cout << "Great, now please enter your license plate #:" << endl;
			getline(cin, licplate);
			cout << "Thank you, please wait while we generate a ticket # for you..." << endl;
			srand(time(0));
			guestTicket = (rand() % 1000);
			cout << "Please leave this ticket # on your dashboard. " << guestTicket << endl;

			Person * nGuest = new Guest(name, licplate, hourEntry, guestTicket);
			nGuest->createGuestTxt(guestData, *nGuest);
			cout << "Your parking spot is P:" << parkGar->findSpot("gst") << ". Take Care!" << endl;

			// Update garage file now since member has now been assigned a spot
			garOutFile.open(GarageFile, ios::out); // overwrites file at same location
			parkGar->writeGarage(garOutFile);
			garOutFile.close();

			exit(1);
		}

		else if (userChoice == "2")
		{
			cout << "Welcome member, please enter your apartment number." << endl;
			getline(cin, userChoice);
			if (apartInfo->roomNumCheck(apartmentVec, userChoice))
			{
				cout << "Stage 1: Valid Apartment Number." << endl;
				apNamecmp = apartInfo->getAptrTen(apartmentVec, userChoice); // set apNamecmp to tenants name after confirming apartment number
			}
			else
			{
				cout << "Invalid Apartment Number!" << endl;
				continue; // to go back to the beginning menu
			}
			cout << "Now enter your Member ID code." << endl;
			getline(cin, userChoice);
			if (member->memidCheck(membersVec, userChoice))
			{
				cout << "Stage 2: Valid Member ID. Advancing......" << endl;
				memNamecmp = member->getMemName(membersVec, userChoice); // set memNamecmp to members name after confirming their ID
			}
			else
			{
				cout << "Not a valid member! Please try again or select another option." << endl;
				continue; // go back to the beginning of menu
			}
			if (apNamecmp == memNamecmp) // Advanced security check. Will make sure each name matched each database correctly
			{
				cout << "Stage 3: Information between Apartment # & member ID match our system! Welcome " << memNamecmp << "." << endl;
			}
			else
			{
				cout << "However, Apartment # and Member ID did not match! Access DENIED!" << endl;
				continue;
			}
			cout << "Your parking spot is P:" << parkGar->findSpot("mem") << ". Take Care!" << endl;

			// Update garage file now since member has now been assigned a spot
			garOutFile.open(GarageFile, ios::out); // overwrites file at same location
			parkGar->writeGarage(garOutFile);
			garOutFile.close();

			exit(1);
		}

		else if (userChoice == "3")
		{
			cout << "Please enter your Employee ID." << endl;
			getline(cin, userChoice);
			if (employee->emplidCheck(employeesVec, userChoice))
			{
				cout << "Stage 1: Employee ID confirmed." << endl;
				empNamecmp1 = employee->getEmpName(employeesVec, userChoice); // set empNamecmp1 to Employees name of valid ID
			}
			else
			{
				cout << "Invalid Employee ID!" << endl;
				continue;
			}
			cout << "Now enter your password." << endl;
			getline(cin, userChoice);
			if (employee->passwordCheck(employeesVec, userChoice))
			{
				cout << "Stage 2: Password accepted. Advancing....." << endl;
				empNamecmp2 = employee->getEmpPassword(employeesVec, userChoice); // set empNamecmp2 to Employees name of valid password
			}
			else
			{
				cout << "Wrong password! Going back to the main menu." << endl;
				continue;
			}
			if (empNamecmp1 == empNamecmp2) // Advanced security check between classes
			{
				cout << "Stage 3: Username & Password match! Welcome " << empNamecmp1 << "." << endl;
			}
			else
			{
				cout << "However, Employee ID & Password did not match! ACCESS DENIED!" << endl;
				continue;
			}
			cout << "Your parking spot is P:" << parkGar->findSpot("emp") << ". Take Care!" << endl;

			// Update garage file now since member has now been assigned a spot
			garOutFile.open(GarageFile, ios::out); // overwrites file at same location
			parkGar->writeGarage(garOutFile);
			garOutFile.close();

			exit(1);
		}

		else if (userChoice == "4")
		{
			cout << "Take care & come back soon!" << endl;
			exit(1);
		}
		else if (userChoice == "9999")
		{
			FancyText();
			break;
		}
			cout << "You entered an invalid command, please try again.\n" << endl;

	} while (userChoice != "99999"); // Admin code to login to administrative menu

	do {
		cout << "Welcome to the Administrator Menu:" << endl;
		cout << "1) Display the Member(Tenant) Database." << endl;
		cout << "2) Display the Employee Database" << endl;
		cout << "3) Display the Apartment Buildings Database." << endl;
		cout << "4) Display the Parking Garage database." << endl;
		cout << "5) Exit this menu." << endl;
		getline(cin, userChoice);
		if (userChoice == "1")
		{
			cout << "Total Members: " << membersVec.size() << endl;
			vector <Member>::iterator indexItm;
			for (indexItm = membersVec.begin(); indexItm != membersVec.end(); indexItm++)
			{
				indexItm->print();
			}
			cout << endl;
		}
		else if (userChoice == "2")
		{
			cout << "Total Employees: " << employeesVec.size() << endl;
			vector <Employee>::iterator indexIte;
			for (indexIte = employeesVec.begin(); indexIte != employeesVec.end(); indexIte++)
			{
				indexIte->print();
			}
			cout << endl;
		}
		else if (userChoice == "3")
		{
			cout << "Apartment Building Room Total: " << apartmentVec.size() << endl;
			vector <Apartment>::iterator indexItap;
			for (indexItap = apartmentVec.begin(); indexItap != apartmentVec.end(); indexItap++)
			{
				indexItap->print();
			}
			cout << endl;
		}
		else if (userChoice == "4")
		{
			cout << "Total Spots: " << parkGar->maxCapacity() << endl;
			parkGar->print(); // displaying garage from class method through an object rather than using a vector/iterator.
			cout << endl;
		}
		else if (userChoice == "5")
		{
			cout << "Take care my favorite admin!" << endl;
			exit(1);
		}
	} while (userChoice != "5");
}

// Other functions

// Administrative load-in text
void FancyText()
{
	string brain = "\n\n\n\nEntering Administrative Menu\n..........................\n";
	int fancy = 0;
	while (brain[fancy] != '\0')
	{
		cout << brain[fancy];
		Sleep(50);
		fancy++;
	};
}

// Guest menu for prices
void HourlyRateMenu()
{
	cout << "Guest Parking Rates Menu:" << endl;
	cout << "1 hour = $15" << setw(20) << "2 hours = $30" << setw(19) << "3 hours = $45" << endl;
	cout << "4 hours = $60" << setw(19) << "5 hours = $75" << setw(19) << "6 hours = $90" << endl;
	cout << "7 hours = $105" << setw(19) << "8 hours = $120" << setw(19) << "9 hours = $135" << endl;
	cout << "10 hours = $150" << setw(19) << "11 hours = $165" << setw(19) << "12 hours = $180" << endl;
	cout << "13 hours = $195" << setw(19) << "14 hours = $210" << setw(19) << "15 hours = $225" << endl;
	cout << "16 hours = $240" << setw(19) << "17 hours = $255" << setw(19) << "18 hours = $270" << endl;
	cout << "19 hours = $285" << setw(19) << "20 hours = $300" << setw(19) << "21 hours = $315" << endl;
	cout << "21 hours = $330" << setw(19) << "21 hours = $345" << setw(19) << "24 hours = $360" << endl;
	cout << "Please enter the hour number only." << endl;
}