Question: Please create a Singleton class called MySingleton for the following specifications below: The MySingletone should have the following public methods: static Mysingletone* GetInstance(); static void
Please create a Singleton class called MySingleton for the following specifications below:
The MySingletone should have the following public methods:
static Mysingletone* GetInstance();
static void getBooks(Book books[ ], int size);
static Customer getCustomer(int customer Id);
The MySingleton should have the following private methods and members (in .cpp)
Members: Customer customers[5]; // a private customer array
Private method: void getCustomerList(Customer[ ], int)
The private method getCustomerList should be called via the private constructor
The TestClass.cpp should:
Use the MySingletone static methods to get the array books.
Get the customer id from the console, then use the MySingletone static method to get the customer object for that id.
Print out the Title Author and price for each available books to order.
Print out the Customer information by using the Customer print() method.
Note: Use static methods in the singleton class.
Books.text
Title Author ISBN Price
Once_Upon_A_Time New_Author 1234323456787 25.00
Midnight_Moon Margaret_Brown 3456789765432 50.00
A_Wrinkle_In_Time Madeline_Engle 2535483215987 60.00
Harry_Potter J_K_Rowling 0002569854712 100.00
Charlottes_Web E_B_White 036250125478 25.00
The_Snowy_Day Ezra_Keats 00025523148 50.00
customer.txt
Id
1234 Donna Ford 123_Sesame_street New_York NY 08330
2345 Michael Watson 1591_Neville_Street Vincennes IN 47591
3456 Deborah Nelson 4802_Cook_Hill_Road EDGEWOOD IA 52042
4567 Sharon Ward 3253_Wood_Street Sioux_Street IA 51103
5678 Lisa Harris 3326_Willow_Oaks_Lane Layfayette LA 70506
Book.h
#pragma once
#include
#include
using namespace std;
class Book
{
public:
Book(); //default empty constructor
Book(string ISBN, string author, string title, double price); //overloaded
private:
string ISBN;
string author;
string title;
double price;
public:
void setISBN(string ISBN);
string getISBN();
void setAuthor(string author);
string getAuthor();
void setTitle(string title);
string getTitle();
void setPrice(double price);
double getPrice();
string print();
~Book();
};
Customer.h
#pragma once
#include
#include
using namespace std;
class Customer
{
public:
Customer(); //default empty constructor
Customer(string custID, string firstName, string lastName, string address); //overloaded
private:
string custID;
string firstName;
string lastName;
string address;
public:
void setCustID(string custID);
string getCustID();
void setFirstName(string firstName);
string getFirstName();
void setLastName(string lastName);
string getLastName();
void setAddress(string address);
string getAddress();
string print();
~Customer();
};
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
