Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

SEPERATE THIS CODE INTO 2 OR 3 CPP FILES AND HEADER FILE . THEN WRITE A MAKE FIL

ID: 3872096 • Letter: S

Question

SEPERATE THIS CODE INTO 2 OR 3 CPP FILES AND HEADER FILE . THEN WRITE A MAKE FILE FOR THESE FILES SO IT CAN BE COMPILED AND RUN ON C++11

#include <iostream>
#include <string>
#include <vector>
using namespace std;

class Media
{
    private:
        string title;
        string leading_actor;
        string director;
        int copyright;
        string genre;
        string media_type;
        string age_rating;
        int id;
        bool checked_out;
        string patron_name;
        string patron_phone;
    public:
        Media(string title, string leading_actor, string director, int copyright,
                    string genre, string media_type, string age_rating, int id)
        {
           this->title = title;
           this->leading_actor = leading_actor;
           this->director = director;
           this->copyright = copyright;
           this->genre = genre;
           this->media_type = media_type;
           this->age_rating = age_rating;
           this->id = id;
        }          
        void check_out(string patron_name, string patron_phone)
        {
           checked_out = true;
           this->patron_name = patron_name;
           this->patron_phone = patron_phone;
        }
        void check_in()
        {
           checked_out = false;
        }
        bool is_checked_out()
        {
           return checked_out;
        }
        string to_string()
        {
           string output = """ + title + "" ";
           output += "with " + leading_actor + ". Directed by " + director + ". " + std::to_string(copyright);
           output += " (" + genre + "). " + age_rating + ". " + media_type + ". ID: " + std::to_string(id);
           if(is_checked_out())
               output += " Checked out to " + patron_name + " (" + patron_phone + ")";
           return output;  
        }
};

class Video_Store
{
    private:
        vector<Media> publications;
    public:
        void add_media(Media pub)
        {
           publications.push_back(pub);
        }
        void check_out(int media_index, string patron_name, string patron_phone)
        {
           publications[media_index-1].check_out(patron_name, patron_phone);
        }
        void check_in(int media_index)
        {
           publications[media_index-1].check_in();
        }
        string publication_to_string(int media_index)
        {
           return publications[media_index-1].to_string();
        }
        int number_of_media()
        {
           return publications.size();
        }
};

void show_menu()
{
    cout << "=======================================" << endl;
    cout << " Video Rental Management System " << endl;
    cout << "=======================================" << endl;
    cout << "Media" << endl;
    cout << "------------" << endl;
    cout << "(1) Add Media" << endl;
    cout << "(2) List all Media" << endl;
    cout << "(3) Check out Media" << endl;
    cout << "(4) Check in Media " << endl;
    cout << "Utility" << endl;
    cout << "-----------" << endl;
    cout << "(9) Help" << endl;
    cout << "(0) Exit " << endl;
}
int main()
{
    Video_Store videoStore;
    int choice, index, copyright, id;
    string title, leading_actor, director, genre, media_type, age_rating, patron_name, patron_phone;
    show_menu();
    Media *pub;
    while(true)
    {
       cout << "Enter your choice: ";
       cin >> choice;
       switch(choice)
       {
          case 1:   cout << "Enter the title of media: ";
                      cin >> title;
                      cout << "Enter the leading actor for publication: ";
                      cin >> leading_actor;
                      cout << "Enter the director for media: ";
                      cin >> director;
                      cout << "Enter the copyright year for media: ";
                      cin >> copyright;
                      cout << "Enter the genre of media: ";
                      cin >> genre;
                      cout << "Enter the medium of media: ";
                      cin >> media_type;
                      cout << "Enter the age rating of media: ";
                      cin >> age_rating;
                      cout << "Enter the ID for media: ";
                      cin >> id;
                      pub = new Media(title, leading_actor, director, copyright, genre, media_type, age_rating, id);
                      videoStore.add_media(*pub);
                      break;
          case 2:   for(int i = 0; i < videoStore.number_of_media(); i++)
                          cout << videoStore.publication_to_string(i) << endl;
                      break;  
          case 3:   cout << "Enter the index of the media to checkout: ";
                      cin >> index;
                      if(index > videoStore.number_of_media() || index <= 0)
                          cout << "Invalid media index. We have only " << videoStore.number_of_media() << " media." << endl;
                      /*else if(library.publications[index].is_checked_out())  
                          cout << "This publication readily checked out. Can't be granted to you." << endl;
                      */  
                      else
                      {
                         cout << "Enter the name of the patron: ";
                         cin >> patron_name;
                         cout << "Enter the phone number of patron: ";
                         cin >> patron_phone;
                         videoStore.check_out(index, patron_name, patron_phone);
                         cout << videoStore.publication_to_string(index) << endl;
                      }  
                      break;
          case 4:   cout << "Enter the index of the media to checkin: ";
                      cin >> index;
                      if(index > videoStore.number_of_media() || index <= 0)
                          cout << "Invalid media index. We have only " << videoStore.number_of_media() << " media." << endl;
                      /*else if(!(library.publications[index].is_checked_out()))
                          cout << "This publication is not checked out. Can't check-in." << endl;
                      */  
                      else
                          videoStore.check_in(index);
                      break;  
                             
          case 9:   show_menu(); break;  
          case 0:   return 0;
          default:   cout << "Invalid menu. Try again." << endl;
       }
    }
}

Explanation / Answer

Hi,

1. Media.h


#ifndef MEDIA_H

#define MEDIA_H

class Media

{

private:

string title;

string leading_actor;

string director;

int copyright;

string genre;

string media_type;

string age_rating;

int id;

bool checked_out;

string patron_name;

string patron_phone;

public:

Media(string title, string leading_actor, string director, int copyright,

string genre, string media_type, string age_rating, int id);

void check_out(string patron_name, string patron_phone);

void check_in();

bool is_checked_out();

string to_string();

};

#endif

2.Video_Store.h

#ifndef VIDEO_STORE_H

#define VIDEO_STORE_H

class Video_Store

{

private:

vector<Media> publications;

public:

void add_media(Media pub);

void check_out(int media_index, string patron_name, string patron_phone);

void check_in(int media_index);

string publication_to_string(int media_index);

int number_of_media();

};

#endif

3. Media.cpp

#include "Media.h"

// Media constructor

Media::Media(string title, string leading_actor, string director, int copyright,

string genre, string media_type, string age_rating, int id)

{

this->title = title;

this->leading_actor = leading_actor;

this->director = director;

this->copyright = copyright;

this->genre = genre;

this->media_type = media_type;

this->age_rating = age_rating;

this->id = id;

}   

void Media::check_out(string patron_name, string patron_phone)

{

checked_out = true;

this->patron_name = patron_name;

this->patron_phone = patron_phone;

}

void Media::check_in()

{

checked_out = false;

}

bool Media::is_checked_out()

{

return checked_out;

}

string Media::to_string()

{

string output = """ + title + "" ";

output += "with " + leading_actor + ". Directed by " + director + ". " + std::to_string(copyright);

output += " (" + genre + "). " + age_rating + ". " + media_type + ". ID: " + std::to_string(id);

if(is_checked_out())

output += " Checked out to " + patron_name + " (" + patron_phone + ")";

return output;  

}

4. Video_Store.cpp

#include "Video_Store.h"

void Video_Store::add_media(Media pub)

{

publications.push_back(pub);

}

void Video_Store::check_out(int media_index, string patron_name, string patron_phone)

{

publications[media_index-1].check_out(patron_name, patron_phone);

}

void Video_Store::check_in(int media_index)

{

publications[media_index-1].check_in();

}

string Video_Store::publication_to_string(int media_index)

{

return publications[media_index-1].to_string();

}

int Video_Store::number_of_media()

{

return publications.size();

}

5. main.cpp

#include <iostream>

#include <string>

#include <vector>

#include "Video_Store.h"

#include "Media.h"

using namespace std;

void show_menu()

{

cout << "=======================================" << endl;

cout << " Video Rental Management System " << endl;

cout << "=======================================" << endl;

cout << "Media" << endl;

cout << "------------" << endl;

cout << "(1) Add Media" << endl;

cout << "(2) List all Media" << endl;

cout << "(3) Check out Media" << endl;

cout << "(4) Check in Media " << endl;

cout << "Utility" << endl;

cout << "-----------" << endl;

cout << "(9) Help" << endl;

cout << "(0) Exit " << endl;

}

int main()

{

Video_Store videoStore;

int choice, index, copyright, id;

string title, leading_actor, director, genre, media_type, age_rating, patron_name, patron_phone;

show_menu();

Media *pub;

while(true)

{

cout << "Enter your choice: ";

cin >> choice;

switch(choice)

{

case 1: cout << "Enter the title of media: ";

cin >> title;

cout << "Enter the leading actor for publication: ";

cin >> leading_actor;

cout << "Enter the director for media: ";

cin >> director;

cout << "Enter the copyright year for media: ";

cin >> copyright;

cout << "Enter the genre of media: ";

cin >> genre;

cout << "Enter the medium of media: ";

cin >> media_type;

cout << "Enter the age rating of media: ";

cin >> age_rating;

cout << "Enter the ID for media: ";

cin >> id;

pub = new Media(title, leading_actor, director, copyright, genre, media_type, age_rating, id);

videoStore.add_media(*pub);

break;

case 2: for(int i = 0; i < videoStore.number_of_media(); i++)

cout << videoStore.publication_to_string(i) << endl;

break;  

case 3: cout << "Enter the index of the media to checkout: ";

cin >> index;

if(index > videoStore.number_of_media() || index <= 0)

cout << "Invalid media index. We have only " << videoStore.number_of_media() << " media." << endl;

/*else if(library.publications[index].is_checked_out())  

cout << "This publication readily checked out. Can't be granted to you." << endl;

*/  

else

{

cout << "Enter the name of the patron: ";

cin >> patron_name;

cout << "Enter the phone number of patron: ";

cin >> patron_phone;

videoStore.check_out(index, patron_name, patron_phone);

cout << videoStore.publication_to_string(index) << endl;

}  

break;

case 4: cout << "Enter the index of the media to checkin: ";

cin >> index;

if(index > videoStore.number_of_media() || index <= 0)

cout << "Invalid media index. We have only " << videoStore.number_of_media() << " media." << endl;

/*else if(!(library.publications[index].is_checked_out()))

cout << "This publication is not checked out. Can't check-in." << endl;

*/  

else

videoStore.check_in(index);

break;  

case 9: show_menu(); break;  

case 0: return 0;

default: cout << "Invalid menu. Try again." << endl;

}

}

Let me know if any change required