Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Convert the following C++ object oriented program to run as gtkmm dialog program insted of command line interface. This is a Library Management system. It

image text in transcribedConvert the following C++ object oriented program to run as gtkmm dialog program insted of command line interface. This is a Library Management system. It should look something like the screenshot at the top.

main.cpp

#include  #include  #include  #include  using namespace std; // ///////////////////////////////////// // A G E G E N R E M E D I A // ///////////////////////////////////// class Age { public: Age(int val) : value(val) { } static const int children = 0; static const int teen = 1; static const int adult = 2; static const int restricted = 3; static const int num_ages = 4; string to_string() { switch(value) { case(children):return "children"; case(teen):return "teen"; case(adult):return "adult"; case(restricted):return "restricted"; default: return "UNKNOWN"; } } private: int value; }; class Genre { public: Genre(int val) : value(val) { } static const int fiction = 0; static const int nonfiction = 1; static const int selfhelp = 2; static const int performance = 3; static const int num_genres = 4; string to_string() { switch(value) { case(fiction):return "fiction"; case(nonfiction):return "nonfiction"; case(selfhelp):return "selfhelp"; case(performance):return "performance"; default: return "UNKNOWN"; } } private: int value; }; class Media { public: Media(int val) : value(val) { } static const int book = 0; static const int periodical = 1; static const int newspaper = 2; static const int audio = 3; static const int video = 4; static const int num_media = 5; string to_string() { switch(value) { case(book):return "book"; case(periodical):return "periodical"; case(newspaper):return "newspaper"; case(audio):return "audio"; case(video):return "video"; default: return "UNKNOWN"; } } private: int value; }; // ///////////////////////////////////// // P A T R O N // ///////////////////////////////////// class Patron { public: Patron(string patron_name, string patron_phone_number) : name(patron_name), number(patron_phone_number) {} Patron() : name("unknown"), number("unknown") {} string to_string(); string get_patron_name(); string get_patron_phone_number(); private: string name; string number; }; string Patron::to_string() {return name + " (" + number + ")";} string Patron::get_patron_name() {return name;} string Patron::get_patron_phone_number() {return number;} // ///////////////////////////////////// // P U B L I C A T I O N // ///////////////////////////////////// class Publication { public: Publication(string p_title, string p_author, string p_copyright, Genre p_genre, Media p_media, Age p_target_age, string p_isbn) : title(p_title), author(p_author), copyright(p_copyright), genre(p_genre), media(p_media), target_age(p_target_age), isbn(p_isbn), patron(Patron()), checked_out(false) { } bool is_checked_out(); void check_out(Patron patron); void check_in(); string to_string(); // Thrown on check_in if publication isn't checked out // or on cheeck_out if publication is already checked out class Invalid_transaction : public exception { }; private: string title; string author; string copyright; Genre genre; Media media; Age target_age; string isbn; Patron patron; bool checked_out; }; bool Publication::is_checked_out() {return checked_out;} void Publication::check_out(Patron p_patron) { if (checked_out) { throw Invalid_transaction(); } else { patron = p_patron; checked_out = true; } } void Publication::check_in() { if (checked_out) { checked_out = false; } else { throw Invalid_transaction(); } } string Publication::to_string() { string pub = "\"" + title + "\"" + " by " + author + ", " + copyright + " (" + target_age.to_string() + " " + genre.to_string() + " " + media.to_string() + ") " + "ISBN: " + isbn; if (checked_out) { pub += " Checked out to " + patron.get_patron_name() + " (" + patron.get_patron_phone_number() + ")"; } return pub; } // ///////////////////////////////////// // L I B R A R Y // ///////////////////////////////////// class Library { public: void add_publication(Publication pub); void add_patron(Patron pat); void check_out(int publication_index, int patron_index); void check_in(int publication_index); string publication_to_string(int publication_index); string patron_to_string(int patron_index); int number_of_publications(); int number_of_patrons(); void easter_egg(); private: vector publications; vector patrons; }; void Library::add_publication(Publication pub) { publications.push_back(pub); } void Library::add_patron(Patron pat) { patrons.push_back(pat); } void Library::check_out(int publication_index, int patron_index) { publications[publication_index].check_out(patrons[patron_index]); } void Library::check_in(int publication_index) { publications[publication_index].check_in(); } string Library::publication_to_string(int publication_index) { return publications[publication_index].to_string(); } string Library::patron_to_string(int patron_index) { return patrons[patron_index].to_string(); } int Library::number_of_publications() { return publications.size(); } int Library::number_of_patrons() { return patrons.size(); } void Library::easter_egg() { add_publication(Publication("The Firm", "John Grisham", "1991", Genre::fiction, Media::book, Age::adult, "0440245923")); add_publication(Publication("Foundation", "Isaac Asimov", "1942", Genre::fiction, Media::book, Age::adult, "0385177259")); add_publication(Publication("Foundation and Empire", "Isaac Asimov", "1943", Genre::fiction, Media::book, Age::adult, "0385177259")); add_publication(Publication("Second Foundation", "Isaac Asimov", "1944", Genre::fiction, Media::book, Age::adult, "0385177259")); add_publication(Publication("War of the Worlds", "Jeff Wayne", "1977", Genre::performance, Media::audio, Age::teen, "9780711969148")); add_publication(Publication("Willy Wonka and the Chocolate Factory", "Roald Dahl", "1971", Genre::performance, Media::video, Age::children, "0142410314")); add_patron(Patron("Larry", "817-555-1111")); add_patron(Patron("Curly", "817-555-2222")); add_patron(Patron("Moe", "817-555-3333")); } // ///////////////////////////////////// // V I E W // ///////////////////////////////////// class View { public: View(Library& lib) : library(lib) { } string get_menu(); string get_publication_list(); string get_patron_list(); string get_age_list(); string get_genre_list(); string get_media_list(); string get_help(); private: Library& library; }; string View::get_menu() { string menu = R"( =============================== C1325 Library Management System =============================== Publications ------------ (1) Add publication (2) List all publications (3) Check out publication (4) Check in publication Patrons ------- (5) Add patron (6) List all patrons Utility ------- (9) Help (0) Exit )"; return menu; } string View::get_publication_list() { string list = R"( ---------------------------- List of Library Publications ---------------------------- )"; for (int i=0; i> cmd; cin.ignore(); // consume execute_cmd(cmd); } } int Controller::get_int(string prompt, int max_int) { int result; while(true) { cout > result; cin.ignore(); // consume if (0  

Input Title? Main Menu The Incredibles Cancel OK CSE1325 Library Management System Publications Select a Beloved Patron X (1) Add publication (2) List all publications (3) Check out publication (4) Check in publication 0) Larry (817-555-1111) 1) Curly (817-555-2222) 2) Moe (817-555-3333) Patrons Cancel OK (5) Add patron (6) List all patrons Utility (9) Help List of Library Publications "The Firm" byJohn Grisham 1991 (adulk fiction bock (0) Exit 0440245923 11 "Foundation" by Isaac Asimov, 1942 (adut fiction book) SBN 0385177259 2 "Foundation and Empire" by Isaac Asima 1943 (adulk fiction bock lSBt 0385177259 3)Second Foundation. by Isaac Asimov 1944 (adut fiction book) SBN 0385177259 "War of the Worlds by Joff Wayrnie, Cancel OK 1977 (teen performance audio lSB978071 1969148 5) "milly Wonka and the Chocolare Factory by Roald Dahl 1971 (children performance video) SBN 0142410314 Input Title? Main Menu The Incredibles Cancel OK CSE1325 Library Management System Publications Select a Beloved Patron X (1) Add publication (2) List all publications (3) Check out publication (4) Check in publication 0) Larry (817-555-1111) 1) Curly (817-555-2222) 2) Moe (817-555-3333) Patrons Cancel OK (5) Add patron (6) List all patrons Utility (9) Help List of Library Publications "The Firm" byJohn Grisham 1991 (adulk fiction bock (0) Exit 0440245923 11 "Foundation" by Isaac Asimov, 1942 (adut fiction book) SBN 0385177259 2 "Foundation and Empire" by Isaac Asima 1943 (adulk fiction bock lSBt 0385177259 3)Second Foundation. by Isaac Asimov 1944 (adut fiction book) SBN 0385177259 "War of the Worlds by Joff Wayrnie, Cancel OK 1977 (teen performance audio lSB978071 1969148 5) "milly Wonka and the Chocolare Factory by Roald Dahl 1971 (children performance video) SBN 0142410314

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions