Question: I NEED SOME ASSISTANCE. IVE ATTACHED MY CODE,THE CODE PROMPT, TEXT FILE. CAN YOU TELL ME WHAT I NEED TO FIX/ADD/CHANGE TO MAKE THE CODE
I NEED SOME ASSISTANCE. IVE ATTACHED MY CODE,THE CODE PROMPT, TEXT FILE. CAN YOU TELL ME WHAT I NEED TO FIX/ADD/CHANGE TO MAKE THE CODE WORK. I ALSO NEED HELP WITH HAVING MY CODE READ THE DEVICES FROM THE TEXT FILE.
"Config file. txt"
Smartphone
Smartwatch
Laptop
Smartwatch
Laptop
Tablet
Laptop
Smartwatch
Smartphone
Tablet
Code Prompt
Suppose you are writing a program to test the components of the devices. The components we are interested in are displays, batteries, and processors. These components are different in different device. Each device has its own program for testing these components. To know which test to run, you will need to instantiate objects that correspond to each one of the components.
We assume that device to be tested are stored in a configuration file (text file). Because this situation fits the Abstract Factory pattern so well, you can use that pattern to organize the creation of objects that correspond to each device. You will also need to use the variation of singleton pattern to ensure that at most two instances of each device in each test run. Please note finishing running all devicesspecified in the configuration file is considered as one test run.
My Code
#include
using namespace std;
// base class
class Devices
{
public:
virtual ~Devices();
virtual void testBattery() = 0;
virtual void testDisplay() = 0;
virtual void testProcessor() = 0;
};
class Smartphone : public Devices
{
public:
void testBattery() { cout << " Battery Smartphone " << endl; }
void testDisplay() { cout << " Display Smartphone " << endl; }
void testProcessor() { cout << " Processor Smartphone " << endl; }
};
class Smartwatch : public Devices
{
public:
void testBattery() { cout << " Battery Smartwatch " << endl; }
void testDisplay() { cout << " Display Smartwatch " << endl; }
void testProcessor() { cout << " Processor Smartwatch " << endl; }
};
class laptop : public Devices
{
public:
void testBattery() { cout << " Battery Laptop " << endl; }
void testDisplay() { cout << " Display Laptop " << endl; }
void testProcessor() { cout << " Processor Laptop " << endl; }
};
class tablet : public Devices
{
public:
void testBattery() { cout << " Battery Tablet " << endl; }
void testDisplay() { cout << " Display Tablet " << endl; }
void testProcessor() { cout << " Processor Tablet " << endl; }
};
// Abstract Factory
Class Componentfactory
{
public:
virtual ~Componentfactory() {}
virtual Devices *batteryobject() = 0;
virtual Devices *displayobject() = 0;
virtual Devices *displayprocessor() = 0;
};
Class Smartphonecomponentfactory : public Componentfactory{
public :
Devices * batteryobject(){
return new Smartphone;
}
Devices *displayobject()
{
return new Smartphone;
}
Devices *displayprocessor()
{
return new Smartphone;
}
}
;
Class Smartwatchcomponentfactory : public Componentfactory{
public :
Devices * batteryobject(){
return new Smartwatch;
}
Devices *displayobject()
{
return new Smartwatch;
}
Devices *displayprocessor()
{
return new Smartwatch;
}
}
;
Class Laptopcomponentfactory : public Componentfactory{
public :
Devices * batteryobject(){
return new laptop;
}
Devices *displayobject()
{
return new laptop;
}
Devices *displayprocessor()
{
return new laptop;
}
}
;
Class Tabletcomponentfactory : public Componentfactory{
public :
Devices * batteryobject(){
return new Tablet;
}
Devices *displayobject()
{
return new Tablet;
}
Devices *displayprocessor()
{
return new Tablet;
}
}
;
// singleton
class Testrunner
{
protected:
static Testrunner *instance = 0 : public : Testrunner & GetInstance()
{
if (!instance)
instance = new Testrunner;
return *instance;
}
...
};
class Singleton : public Testrunner
{
public:
void DestroyInstance()
{
if (instance)
delete instance;
instance = 0;
}
};
// main
int main(void)
{
Componentfactory *componentfactory;
Devices *Dev;
componentfactory = new Smartphonecomponentfactory;
Dev = componentfactory->batteryobject();
Dev->Testbattery();
Dev->Testdisplay();
Dev->Testprocessor();
cout << " " << endl;
Dev = componentfactory->displayobject();
Dev->Testbattery();
Dev->Testdisplay();
Dev->Testprocessor();
cout << " " << endl;
Dev = componentfactory->processorobject();
Dev->Testbattery();
Dev->Testdisplay();
Dev->Testprocessor();
cout << " " << endl;
componentfactory = new Smartwatchcomponentfactory;
Dev = componentfactory->batteryobject();
Dev->Testbattery();
Dev->Testdisplay();
Dev->Testprocessor();
cout << " " << endl;
Dev = componentfactory->displayobject();
Dev->Testbattery();
Dev->Testdisplay();
Dev->Testprocessor();
cout << " " << endl;
Dev = componentfactory->processorobject();
Dev->Testbattery();
Dev->Testdisplay();
Dev->Testprocessor();
cout << " " << endl;
componentfactory = new Laptopcomponentfactory;
Dev = componentfactory->batteryobject();
Dev->Testbattery();
Dev->Testdisplay();
Dev->Testprocessor();
cout << " " << endl;
Dev = componentfactory->displayobject();
Dev->Testbattery();
Dev->Testdisplay();
Dev->Testprocessor();
cout << " " << endl;
Dev = componentfactory->processorobject();
Dev->Testbattery();
Dev->Testdisplay();
Dev->Testprocessor();
cout << " " << endl;
componentfactory = new Tabletcomponentfactory;
Dev = componentfactory->batteryobject();
Dev->Testbattery();
Dev->Testdisplay();
Dev->Testprocessor();
cout << " " << endl;
Dev = componentfactory->displayobject();
Dev->Testbattery();
Dev->Testdisplay();
Dev->Testprocessor();
cout << " " << endl;
Dev = componentfactory->processorobject();
Dev->Testbattery();
Dev->Testdisplay();
Dev->Testprocessor();
cout << " " << endl;
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
