Sunteți pe pagina 1din 7

Computer Aggregation – Example1

============================================
#include <string.h>
#include <iostream.h>
#include "list.h"

/*========== Hard Disk ==========*/

class HardDisk{
public:
HardDisk(){}
HardDisk(int c){hddCapacity=c;}

void setHddCapacity(int c){hddCapacity=c;}


int getHddCapacity(){return hddCapacity;}

private:
int hddCapacity;

};

/*========== Ram ==========*/

class Ram{
public:
Ram(){}
Ram(int c){ramCapacity=c;}

void setRamCapacity(int c){ramCapacity=c;}


int getRamCapacity(){return ramCapacity;}

private:
int ramCapacity;

};

/*========== Processor ==========*/

class Processor{
public:
Processor(){}
Processor(int s){processorClockSpeed=s;}

void setProcessorClockSpeed(int s){processorClockSpeed=s;}


int getProcessorClockSpeed(){return processorClockSpeed;}

private:
int processorClockSpeed;

};

/*========== Speaker ==========*/

class Speaker{
public:
Speaker(){}
Speaker(int s){speakerSize=s;}

void setSpeakerSize(int s){speakerSize=s;}


int getSpeakerSize(){return speakerSize;}

private:
int speakerSize;

};

/*========== Mouse ==========*/

class Mouse{
public:
Mouse(){}
Mouse(char *t){strcpy(mouseType,t);}

void setMouseType(char *t){strcpy(mouseType,t);}


char *getMouseType(){return mouseType;}

private:
char mouseType[20];
};

/*========== KeyBoard ==========*/

class KeyBoard{

public:
KeyBoard(){}
KeyBoard(char *t){strcpy(keyBoardType,t);}
void setKeyBoardType(char *t){strcpy(keyBoardType,t);}
char *getKeyBoardType(){return keyBoardType;}

private:
char keyBoardType[20];
};

/*========== Monitor ==========*/

class Monitor{

public:
Monitor(){}
Monitor(char *t){strcpy(monitorType,t);}

void setMonitorType(char *t){strcpy(monitorType,t);}


char *getMonitorType(){return monitorType;}

private:
char monitorType[20];
};

/*========== CdRom ==========*/

class CdRom{

public:
CdRom(){}
CdRom(char *t){strcpy(cdRomType,t);}

void setCdRomType(char *t){strcpy(cdRomType,t);}


char *getCdRomType(){return cdRomType;}

private:
char cdRomType[20];
};

/*========== Computer ==========*/

enum Status{OutOfOrder,OK};
class Computer{

public:
Computer(){}
Computer(Status s,int hs,int rs,int ps, char *mt,char *kt, char
*mot):hardDisk(hs),ram(rs),processor(ps),mouse(mt),keyBoard(kt)
,monitor(mot)
{
status=s;
cdRom=NULL;
speaker=NULL;
}

/*========== Getter Setters of All above Classes


==========*/

void setStatus(Status s){status=s;}


Status getStatus(){return status;}

void setHardDisk(int hd){hardDisk.setHddCapacity(hd);}


int getHardDisk(){hardDisk.getHddCapacity();}

void setRam(int rm){ram.setRamCapacity(rm);}


int getRam(){ram.getRamCapacity();}

void setProcessor(int
pr){processor.setProcessorClockSpeed(pr);}
int getProcessor(){processor.getProcessorClockSpeed();}

void setMouse(char *ms){mouse.setMouseType(ms);}


char *getMouse(){mouse.getMouseType();}

void setKeyBoard(char *kb){keyBoard.setKeyBoardType(kb);}


char *getKeyBoard(){keyBoard.getKeyBoardType();}

void setMonitor(char *mt){monitor.setMonitorType(mt);}


char *getMonitor(){monitor.getMonitorType();}

void setCdRom(char *cd)


{
cdRom->setCdRomType(cd);
}

char *getCdRom()
{
if(cdRom!=NULL)
return cdRom->getCdRomType();
else
return "?";
}

void removeCdRom()
{
delete cdRom;

void setSpeaker(int sp)


{
speaker->setSpeakerSize(sp);
}

int getSpeaker()
{
if(speaker!=NULL)
return speaker->getSpeakerSize();
else
return -1;
}

void removeSpeaker()
{
delete speaker;

/*========== Print Specifications of Aggregation Classes


==========*/

void PrintSpecifications()
{

cout<<"\nStatus: "<<getStatus();
cout<<"\nCapacity of Hard Disk:
"<<hardDisk.getHddCapacity()<<" GB";
cout<<"\nCapacity of Ram:
"<<ram.getRamCapacity()<<" GB";
cout<<"\nProcessor Speed Clock:
"<<processor.getProcessorClockSpeed()<<" Mhz";
cout<<"\nMouse of Type:
"<<mouse.getMouseType();
cout<<"\nKeyBoard of Type:
"<<keyBoard.getKeyBoardType();
cout<<"\nMonitor of Type:
"<<monitor.getMonitorType();

private:

Status status;
HardDisk hardDisk;
Ram ram;
Processor processor;
Mouse mouse;
KeyBoard keyBoard;
Monitor monitor;
CdRom *cdRom;
Speaker *speaker;

};

class Lab{

public:

Lab(){}
Lab(int n,int s):ls(s){no=n;}

bool addComputer(Computer c)
{
return ls.addObject(c);
}

void Print()
{
Computer t;
for(int i=0;i<ls.getUsed(); i++)
{
ls.getObject(i,t);
t.PrintSpecifications();
}

private:

int no;
List<Computer>ls;
};

/*========== Client Program ==========*/

void main()
{
Lab l1(1,5),l2(1,5);
Computer
obj(OK,80,2,4,"Laser","Multimedia","LCD_Flat_Screen");
l1.addComputer(obj);
CdRom c;
c.setCdRomType("ASUS");
cout<<"====================================
===========================================";
l1.Print();
cout<<"\nCdRom: "<<c.getCdRomType();
cout<<"\n==================================
============================================
=\n\n";

Computer obj2(OK,40,1,2,"Ball","Simple","Flat_Screen");
l2.addComputer(obj2);
cout<<"====================================
===========================================";
l2.Print();
cout<<"\n==================================
============================================
=\n\n";
}

http://www.ravianeducation.blogspot.com
FARHAN: 03008855006