Question: Did I correctly implement this code(C++): MediaItemDatabase.hpp #pragma once #include // size_t #include #include #include MediaItem.hpp // Singleton Design Pattern class MediaItemDatabase { public: //
Did I correctly implement this code(C++):

MediaItemDatabase.hpp
#pragma once
#include
#include
#include
#include "MediaItem.hpp"
// Singleton Design Pattern
class MediaItemDatabase
{
public:
// Get a reference to the one and only instance of the database
static MediaItemDatabase & instance( const std::string & filename = "Media_UPC_Database_Sample.dat");
// Locate and return a reference to a particular record
MediaItem * find( const std::string & upc ); // Returns a pointer to the item in the database if
// found, nullptr otherwise
// Queries
std::size_t size() const; // Returns the number of items in the database
private:
MediaItemDatabase ( const std::string & filename );
MediaItemDatabase ( const MediaItemDatabase & ) = delete; // intentionally prohibit making copies
MediaItemDatabase & operator=( const MediaItemDatabase & ) = delete; // intentionally prohibit copy assignments
// We'll look at alternatives to std::vector later
std::vector
};
Media_UPC_Database_Sample.dat
"Citizen Kane", "Orson Welles", "Mercury Productions", 7147 "Casablanca", "Michael Curtiz", "Warner Brothers", 6131 "The Wizard of Oz", "Victor Fleming", "Metro Goldwyn Mayer", 6082 "Modern Times", "Charlie Chaplin", "Charles Chaplin Productions", 5384 "A Night at the Opera", "Sam Wood", "Metro Goldwyn Mayer", 5581 "The Godfather", "Francis Ford Coppola", "Paramount", 10528 "It Happened One Night", "Frank Capra", "Columbia Pictures Corporation", 6315 "The Third Man", "Carol Reed", "British Lion Film Corporation", 6253 "Singin' in the Rain", "Stanley Donen", "Metro Goldwyn Mayer", 6149 "E.T. The Extra-Terrestrial", "Steven Spielberg", "Universal Pictures", 6931 "All About Eve", "Joseph L. Mankiewicz", "Twentieth Century Fox", 8293 "The Kid", "Charlie Chaplin", "Charles Chaplin Productions", 3612 "The Adventures of Robin Hood", "Michael Curtiz", "Warner Brothers", 3736 "King Kong", "Merian C. Cooper", "RKO Radio Pictures Inc.", 3603
// Construction MediaItemDatabase::MediaItemDatabase( const std::string & filename) { std::ifstream fin( filename, std::ios::binary ); /// TO-DO A record has 4 pieces of /// The file contains one record of data on each line of text. See Media_UPC_Database_Sample.dat. /// data delimited with a comma. (This exactly matches how Media Items are read) 1. 2. 3. /// 4. Field Movie Title Director Studio Name Run Time Type String String String Integer Notes May contain spaces, always enclosed in double quotes, used as our search item May contain spaces, always enclosed in double quotes May contain spaces, always enclosed in double quotes In seconds /// Example: 17/"Citizen Kane", ///"Casablanca", ///"The Wizard of Oz", "Orson Welles", "Mercury Productions", 7147 "Michael Curtiz", "Warner Brothers", 6131 "Victor Fleming", "Metro Goldwyn Mayer", 6082 /// Note: double quotes within the string are escaped with the backslash character ///end todo fin.open("Media_UPC_Database_Sample.dat", std::fstream::binary | std::fstream: :out); if (!fin) { std::cout
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
