Created
December 5, 2023 20:49
-
-
Save Eng-Bunnys/4b2efedd401a287caeac5e1174eb5088 to your computer and use it in GitHub Desktop.
Solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "AssistantLib.h" | |
#include <iostream> | |
using namespace std; | |
AssistantLib::AssistantLib(string name, int status, int noBooksHandled) | |
: Librarian(name, status, noBooksHandled, AssistantLibrarian) {} | |
void AssistantLib::AssignBook(Librarian* otherLibrarian) { | |
if (otherLibrarian->GetType() == AssistantLibrarian && otherLibrarian->GetStatus() < Status) otherLibrarian->IncreaseBooksHandled(); | |
else cout << "Assistant librarians cannot assign books to other assistant librarians" << std::endl; | |
} | |
void AssistantLib::Print() const { | |
cout << "Type is Assistant Librarian\nName is " << Name << "\nStatus is " << Status << "\nNo. of books assigned " << NoBooksHandled << endl; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef ASSISTANTLIB_H | |
#define ASSISTANTLIB_H | |
#include "Librarian.h" | |
#include <iostream> | |
using namespace std; | |
class AssistantLib : public Librarian { | |
public: | |
AssistantLib(string name, int status, int noBooksHandled); | |
void AssignBook(Librarian* otherLibrarian) override; | |
virtual void Print() const override; | |
}; | |
#endif // ASSISTANTLIB_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Librarian.h" | |
#include <iostream> | |
using namespace std; | |
Librarian::Librarian(string name, int status, int noBooksHandled, LibrarianType type) | |
: Name(name), Type(type) | |
{ | |
Status = status > 0 ? status : 0; | |
NoBooksHandled = noBooksHandled > 0 ? noBooksHandled : 0; | |
} | |
void Librarian::IncreaseBooksHandled() { | |
++NoBooksHandled; | |
} | |
void Librarian::IncreaseStatus() { | |
++Status; | |
} | |
int Librarian::GetStatus() const { | |
return Status; | |
} | |
LibrarianType Librarian::GetType() const { | |
return Type; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef LIBRARIAN_H | |
#define LIBRARIAN_H | |
#include <iostream> | |
using namespace std; | |
enum LibrarianType { | |
MajorLibrarian, | |
AssistantLibrarian | |
}; | |
class Librarian { | |
protected: | |
std::string Name; | |
int Status; | |
int NoBooksHandled; | |
LibrarianType Type; | |
public: | |
Librarian(string name, int status, int noBooksHandled, LibrarianType type); | |
void IncreaseBooksHandled(); | |
void IncreaseStatus(); | |
int GetStatus() const; | |
virtual void AssignBook(Librarian* otherLibrarian); | |
virtual void Print() const = 0; | |
LibrarianType GetType() const; | |
}; | |
#endif // LIBRARIAN_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "AssistantLib.h" | |
#include "Librarian.h" | |
#include "MajorLib.h" | |
#include <iostream> | |
using namespace std; | |
//Missing some couts since they're repeated | |
int main() { | |
Librarian *LibrarianList[3]; | |
LibrarianList[0] = new AssistantLib("AssOne", 4, 20); | |
LibrarianList[1] = new AssistantLib("AssTwo", 3, 12); | |
LibrarianList[2] = new MajorLib("MajorOne", 2, 7); | |
cout << "Now printing information:\n\n"; | |
for (int i = 0; i < 3; i++) { | |
LibrarianList[i]->Print(); | |
cout << endl; | |
} | |
LibrarianList[0]->AssignBook(LibrarianList[1]); | |
cout << "AssistantLib1 is assigning a book to AssistantLib2\n"; | |
if (LibrarianList[0]->GetStatus() > LibrarianList[1]->GetStatus()) { | |
cout << "AssistantLib1 has a higher status than AssistantLib2 \n"; | |
} | |
else if (LibrarianList[0]->GetStatus() == LibrarianList[1]->GetStatus()) { | |
cout << "Both have the same status \n"; | |
} | |
else cout << "AssistantLib2 has higher status than AssistantLib1 \n"; | |
for (int i = 0; i < 3; i++) { | |
delete LibrarianList[i]; | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "MajorLib.h" | |
#include <iostream> | |
using namespace std; | |
MajorLib::MajorLib(string name, int status, int noBooksHandled) | |
: Librarian(name, (status > 0 ? status : 0), (noBooksHandled > 0 ? noBooksHandled : 0), MajorLibrarian) {} | |
void MajorLib::AssignBook(Librarian* otherLibrarian) { | |
if (otherLibrarian->GetType() == AssistantLibrarian) otherLibrarian->IncreaseBooksHandled(); | |
else cout << "Major librarians cannot assign books to other major librarians" << std::endl; | |
} | |
void MajorLib::Print() const { | |
cout << "Type is Major Librarian\nName is " << Name << "\nStatus is " << Status << "\nNo. of books assigned " << NoBooksHandled << endl; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef MAJORLIB_H | |
#define MAJORLIB_H | |
#include "Librarian.h" | |
#include <iostream> | |
using namespace std; | |
class MajorLib : public Librarian { | |
public: | |
MajorLib(string name, int status, int noBooksHandled); | |
void AssignBook(Librarian* otherLibrarian) override; | |
virtual void Print() const override; | |
}; | |
#endif // MAJORLIB_H |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment