-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComputer.cpp
More file actions
64 lines (52 loc) · 1.64 KB
/
Computer.cpp
File metadata and controls
64 lines (52 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//Student Bshara Haj, 212590186.
//Student Obaeda Khatib, 201278066.
#pragma once
#include "Computer.h"
#include"PeripheralDevice.h" /////
Computer::Computer(int price, const string& manufacturer, const string& cpu, bool isALaptop, int numOfPorts)
: Item(price, manufacturer), cpu(cpu), isALaptop(isALaptop), numOfPorts(numOfPorts) //the constructor for the Computer class
{
}
Computer::~Computer() /////
{
for (int i = 0; i < connected.size(); i++)
connected[i]->disconnect();
connected.clear();
}
string Computer::getCpu() const //to get the CPU
{
return cpu;
}
void Computer::setCpu(const string& cpu) //to set the CPU
{
this->cpu = cpu;
}
bool Computer::getIsALaptop() const //to get whether the Computer is a laptop
{
return isALaptop;
}
void Computer::setIsALaptop(bool isALaptop) //to set whether the Computer is a laptop
{
this->isALaptop = isALaptop;
}
int Computer::getNumOfPorts() const
{
return numOfPorts;
}
string Computer::toString() const //to get a string representation of the Computer
{
return Item::toString() + (this->isALaptop ? "Laptop" : "Desktop") + ", " + cpu;
}
Computer::operator string() const //string conversion operator for the Computer class
{
return toString();
}
void Computer::printConnected() const /////////////////
{
std::cout << "There are " + std::to_string(connected.size()) + " connection to " + Computer::operator std::string();
for (int i = 0; i < connected.size(); i++) {
std::cout << std::endl;
std::cout << connected[i]->operator std::string();
}
std::cout << std::endl;
}