#include #include #include #include "DocumentStore.h" #include "Email.h" #include "Memo.h" #include "Report.h" using namespace std; DocumentStore::DocumentStore() : m_nextID(10001) {} string DocumentStore::InputText(const char *prompt) { string input; cout << prompt; getline(cin, input); return input; } string DocumentStore::InputMultilineText(const char *prompt) { string input, nextLine; bool endSeen = false; cout << prompt << "(type END on separate line to stop):\n"; do { getline(cin, nextLine); if (nextLine.compare("END") == 0) { endSeen = true; } else { input.append(nextLine + "\n"); } } while (!endSeen); return input; } void DocumentStore::CreateMemo(){ Memo *newMemoPtr; string author, subject, recipientName, distributionList, textBody; author = InputText("Enter author:\n"); subject = InputText("Enter subject:\n"); recipientName = InputText("Enter recipient:\n"); distributionList = InputMultilineText("Enter distribution list "); textBody = InputMultilineText("Enter text body "); newMemoPtr = new Memo(m_nextID++, author, subject, recipientName, distributionList, textBody); cout << "Memo #" << newMemoPtr->GetID() // Verification of ID << " entered into documents list.\n"; m_active.push_back(newMemoPtr); } void DocumentStore::CreateEmail(){ Email *newEmailPtr; string author, subject, recipientName, recipientEmail, textBody; >> TO DO: >> >> USE DocumentStore::CreateMemo() IMPLEMENTATION ABOVE FOR IDEAS >> ON HOW TO COMPLETE THIS FUNCTION } void DocumentStore::CreateReport(){ Report *newReportPtr; string author, title, textBody; >> TO DO: >> >> USE DocumentStore::CreateMemo() IMPLEMENTATION ABOVE FOR IDEAS >> ON HOW TO COMPLETE THIS FUNCTION } void DocumentStore::Display(int docID){ Document *doc = NULL; for (int i = 0; i < m_active.size(); i++) { if (m_active[i]->GetID() == docID) { doc = m_active[i]; break; } } if (doc != NULL) { if (doc->GetType() == DOC_TYPE_EMAIL) { Email *email = static_cast(doc); email->DisplayHeader(); email->DisplayBody(); } else if (doc->GetType() == DOC_TYPE_MEMO) { Memo *memo = static_cast(doc); memo->DisplayHeader(); memo->DisplayBody(); } else if (doc->GetType() == DOC_TYPE_REPORT) { Report *report = static_cast(doc); report->DisplayHeader(); report->DisplayBody(); } else { cout << "Unknown/unexpected document type?\n"; exit(1); } } else { cout << "Document #" << docID << " not found.\n"; } } void DocumentStore::ListDocuments(){ >> USE DocumentStore::Display() IMPLEMENTATION ABOVE FOR IDEAS >> ON HOW TO COMPLETE THIS FUNCTION } void DocumentStore::Search(string queryStr){ >> USE DocumentStore::Display() IMPLEMENTATION ABOVE FOR IDEAS >> ON HOW TO COMPLETE THIS FUNCTION } void DocumentStore::ClearDocuments(){ Document *doc; for (int i = 0; i < m_active.size(); i++) { doc = m_active[i]; if (doc->GetType() == DOC_TYPE_EMAIL) { Email *email = static_cast(doc); delete email; } else if (doc->GetType() == DOC_TYPE_MEMO) { Memo *memo = static_cast(doc); delete memo; } else if (doc->GetType() == DOC_TYPE_REPORT) { Report *report = static_cast(doc); delete report; } else { cout << "Unknown/unexpected document type?\n"; exit(1); } m_active[i] = NULL; } m_active.clear(); cout << "Document collection has been cleared\n"; }