class/composition

Hey!!
How can i add price from Computer class with Monitor class price and calculate it in Complect class.Kind a stuck in here.Thanks.


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

class Computer
{
public:
Computer();
void setComputer(string, int, double);
void printComputer();
string getComputerBrand();
int getRam();
double getComputerPrice();

private:
string cb;
int r;
double cp;
};

class Monitor
{
public:
Monitor();
void setMonitor(string, int, double);
void printMonitor();
string getMonitorBrand();
int getResolution();
double getMonitorPrice();

private:
string mb;
int rl;
double mp;
};

class Complect
{
public:
Complect(string n, double cppr, double mrpr, Computer kompis, Monitor monis);
string getComplectName();
double getTotalPrice(double, double);
void printComplect();
private:
string name;
Computer kompisObj;
Monitor monisObj;
};

int main()
{
Computer kompisObj;
kompisObj.setComputer("Intel" , 8, 570.25);
kompisObj.printComputer();
cout<<"Computer brand: "<<kompisObj.getComputerBrand()<<endl;
cout<<"Computer RAM: "<<kompisObj.getRam()<<" GB"<<endl;
cout<<"Computer price: "<<kompisObj.getComputerPrice()<<" EUR"<<endl;


Monitor monisObj;
monisObj.setMonitor("Dell", 20, 70);
monisObj.printMonitor();
cout<<"Monitor brand: "<<monisObj.getMonitorBrand()<<endl;
cout<<"Monitor resolution: "<<monisObj.getResolution()<<" inches"<<endl;
cout<<"Monitor price: "<<monisObj.getMonitorPrice()<<" EUR"<<endl;

Complect compObj("Complect",kompisObj, monisObj,getTotalPrice);
cout<<"\nComplect name: "<<compObj.getComplectName()<<endl;
cout<<"Total price of complect: "<<compObj.getTotalPrice()<<endl;
compObj.printComplect();

return 0;
}

void Computer::setComputer(string cBrand, int ram , double cmpr)
{
cb = cBrand;
r = ram;
cp = cmpr;
}

Computer::Computer()
{
setComputer(cb, r, cp);
}

void Computer::printComputer()
{
cout<<"Computer brand:"<<cb<<" //RAM:"<<r<<" GB"<<" //Price:"<<cp<<" EUR"<<endl;
}

string Computer::getComputerBrand()
{
return cb;
}

int Computer::getRam()
{
return r;
}

double Computer::getComputerPrice()
{
return cp;
}

void Monitor::setMonitor(string mBrand, int resl, double mrpr)
{
mb = mBrand;
rl = resl;
mp = mrpr;
}

Monitor::Monitor()
{
setMonitor(mb, rl, mp);
}

void Monitor::printMonitor()
{
cout<<"Monitor brand:"<<mb<<" //Resolution:"<<rl<<" inches"<<" //Price:"<<mp<<" EUR"<<endl;
}

string Monitor::getMonitorBrand()
{
return mb;
}

int Monitor::getResolution()
{
return rl;
}

double Monitor::getMonitorPrice()
{
return mp;
}

Complect::Complect(string n, double cmpr, double mrmp, Computer kompis, Monitor monis)
:name(n), cp(cmpr), mp(mrmp), kompisObj(kompis), monisObj(monis)
{
}

string Complect::getComplectName()
{
return name;
}

double Complect::getTotalPrice(double cp, double mp)
{
return cp + mp;
}

void Complect::printComplect()
{
kompisObj.printComputer();
monisObj.printMonitor();
getTotalPrice();
}
1
2
3
double Complect::getPrice() const{
   return this->kompisObj.getPrice() + this->monisObj.getPrice();
}
Thank you, it did help.
Topic archived. No new replies allowed.