I need to overload the addition operator of multiple different objects and return a 'cluster object: "Overload the addition operator(+) to add any combination of instances for Desktops, Laptops, and Clusters. This operator should return an object of type cluster" So if I had desktop1+laptop1+laptop2; I would need it to return a cluster that adds all of the RAM, and other variables of each object. But it will only be adding the variables that all of the objects inherit from the computer class. Here is my code of the rest of the project. Thanks!
#include <iostream>
using namespace std;
class computer
{
public:
double RAM;
double CPUSpeed;
int numberOfCores;
double HDDSize;
virtual void print();
};
class desktop : public computer
{
public:
bool hasMonitor;
double monitorSize;
friend istream& operator>> (istream &in, desktop &myDesktop);
};
class laptop : public computer
{
public:
double screenSize;
};
class cluster : public computer
{
public:
int numOfComp;
};
desktop::desktop()
{
RAM = 0;
CPUSpeed = 0;
numberOfCores = 0;
HDDSize = 0;
hasMonitor = 0;
monitorSize = 0;
}
laptop::laptop()
{
RAM = 0;
CPUSpeed = 0;
numberOfCores = 0;
HDDSize = 0;
screenSize = 0;
}
cluster::cluster()
{
RAM = 0;
CPUSpeed = 0;
numberOfCores = 0;
HDDSize = 0;
numOfComp = 0;
}
istream& operator>> (istream &in, desktop &myDesktop)
{
in >> myDesktop.hasMonitor;
in >> myDesktop.monitorSize;
in >> myDesktop.RAM;
in >> myDesktop.CPUSpeed;
in >> myDesktop.HDDSize;
in >> myDesktop.numberOfCores;
return in;
}
istream& operator>> (istream &in, laptop &mylaptop)
{
in >> mylaptop.RAM;
in >> mylaptop.CPUSpeed;
in >> mylaptop.HDDSize;
in >> mylaptop.numberOfCores;
in >> mylaptop.screenSize;
return in;
}
istream& operator>> (istream &in, cluster &myCluster)
{
in >> myCluster.RAM;
in >> myCluster.CPUSpeed;
in >> myCluster.HDDSize;
in >> myCluster.numberOfCores;
in >> myCluster.numOfComp;
return in;
}
operator+(computer &myComp)
{
return