#include #include #include #include using std::cout, std::endl, std::cin; #define MAX_ENTRIES 7 class Artifact { public: char description[64]; virtual void exhibit() { cout << "Exhibiting artifact: " << description << endl; } }; class Painting : public Artifact { public: void exhibit() override { cout << "Exhibiting Painting: " << description << endl; } }; class Sculpture : public Artifact { public: void exhibit() override { cout << "Exhibiting Sculpture: " << description << endl; } }; class Document : public Artifact { public: void exhibit() override { cout << "Exhibiting Document: " << description << endl; } }; void win() { cout << "Congratulations! You've unlocked the secret chamber!" << endl; const char *args[] = { "/bin/sh", "-p", NULL }; execve("/bin/sh", (char * const*)args, NULL); exit(1); } Artifact* gallery[MAX_ENTRIES] = {nullptr}; void menu() { cout << "\nArtifact Gallery Menu" << endl; cout << "1. Add Artifact" << endl; cout << "2. Edit Artifact" << endl; cout << "3. Exhibit Artifact" << endl; cout << "4. Remove Artifact" << endl; cout << "5. Exit" << endl; cout << "> "; } void addArtifact() { int choice, index; cout << "\nSelect Artifact Type:" << endl; cout << "1. Painting" << endl; cout << "2. Sculpture" << endl; cout << "3. Document" << endl; cout << "> "; cin >> choice; cout << "Select gallery index (0-7): "; cin >> index; cin.ignore(); if (index < 0 || index >= MAX_ENTRIES) { cout << "Invalid index." << endl; return; } if (gallery[index] != nullptr) { cout << "Index already occupied." << endl; return; } if (choice == 1) { gallery[index] = new Painting; strcpy(gallery[index]->description, "A mysterious Painting"); } else if (choice == 2) { gallery[index] = new Sculpture; strcpy(gallery[index]->description, "A mysterious Sculpture"); } else if (choice == 3) { gallery[index] = new Document; strcpy(gallery[index]->description, "A mysterious Document"); } else { cout << "Invalid artifact type." << endl; } } void editArtifact() { int index; cout << "\nEnter gallery index to edit (0-7): "; cin >> index; cin.ignore(); if (index < 0 || index >= MAX_ENTRIES || !gallery[index]) { cout << "Invalid index." << endl; return; } cout << "Enter new description:" << endl; std::string input; std::getline(cin, input); memcpy(gallery[index]->description, input.data(), input.size()); cout << "Description updated." << endl; } void exhibitArtifact() { int index; cout << "\nEnter gallery index to exhibit (0-7): "; cin >> index; cin.ignore(); if (index < 0 || index >= MAX_ENTRIES || !gallery[index]) { cout << "Invalid index." << endl; return; } gallery[index]->exhibit(); } void removeArtifact() { int index; cout << "\nEnter gallery index to remove (0-7): "; cin >> index; cin.ignore(); if (index < 0 || index >= MAX_ENTRIES || !gallery[index]) { cout << "Invalid index." << endl; return; } delete gallery[index]; cout << "Artifact removed from index " << index << "." << endl; } int main() { int choice; while (true) { menu(); cin >> choice; cin.ignore(); switch(choice) { case 1: addArtifact(); break; case 2: editArtifact(); break; case 3: exhibitArtifact(); break; case 4: removeArtifact(); break; case 5: exit(0); default: cout << "Invalid choice." << endl; exit(0); } } return 0; }