Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Laptop.h
- #pragma once
- #define _CRT_SECURE_NO_WARNINGS
- #include "CPU.h"
- #include "Display.h"
- #include "RAM.h"
- #include "Battery.h"
- #include <iostream>
- class Laptop
- {
- private:
- CPU cpu;
- Display display;
- RAM ram;
- Battery battery;
- public:
- Laptop()
- {
- cpu = CPU();
- display = Display();
- ram = RAM();
- battery = Battery();
- }
- Laptop(CPU cpu, Display display, RAM ram, Battery battery)
- {
- this->cpu = cpu;
- this->display = display;
- this->ram = ram;
- this->battery = battery;
- }
- ~Laptop()
- {
- std::cout << "Laptor destructor called" << std::endl;
- }
- Laptop(const Laptop& laptop)
- {
- cpu = laptop.cpu;
- display = laptop.display;
- ram = laptop.ram;
- battery = laptop.battery;
- }
- Laptop& operator =(const Laptop& laptop)
- {
- if (this != &laptop)
- {
- cpu = laptop.cpu;
- display = laptop.display;
- ram = laptop.ram;
- battery = laptop.battery;
- }
- return *this;
- }
- friend std::ostream& operator <<(std::ostream& out, Laptop laptop);
- };
- //laptop.cpp
- #include "Laptop.h"
- #include <iostream>
- std::ostream& operator <<(std::ostream& out, Laptop laptop)
- {
- out << "CPU: " << laptop.cpu.getName() << std::endl;
- out << "Display: " << laptop.display.getName() << std::endl;
- out << "Ram: " << laptop.ram.getName() << std::endl;
- out << "Battery: " << laptop.battery.getName() << std::endl;
- return out;
- }
- //battery.h
- #pragma once
- #include <string>
- class Battery
- {
- private:
- std::string name;
- int size;
- public:
- Battery()
- {
- name = "Unknown";
- size = 0;
- }
- Battery(std::string name, int size)
- {
- this->name = name;
- this->size = size;
- }
- Battery(const Battery& battery)
- {
- this->size = battery.size;
- this->name = battery.name;
- }
- ~Battery()
- {
- }
- void setName(std::string name)
- {
- this->name = name;
- }
- std::string getName()
- {
- return name;
- }
- void setSize(int size)
- {
- this->size = size;
- }
- int getSize()
- {
- return size;
- }
- };
- //cpu.h
- #pragma once
- #include <string>
- class CPU
- {
- private:
- std::string name;
- int cores;
- public:
- CPU()
- {
- name = "Unknown";
- cores = 0;
- }
- CPU(std::string name, int cores)
- {
- this->name = name;
- this->cores = cores;
- }
- CPU(const CPU& cpu)
- {
- this->cores = cpu.cores;
- this->name = cpu.name;
- }
- ~CPU()
- {
- }
- void setName(std::string name)
- {
- this->name = name;
- }
- std::string getName()
- {
- return name;
- }
- void setCores(int cores)
- {
- this->cores = cores;
- }
- int getCores()
- {
- return cores;
- }
- };
- //ram.h
- #pragma once
- #include <string>
- class RAM
- {
- private:
- std::string name;
- int frequency;
- public:
- RAM()
- {
- name = "Unknown";
- frequency = 0;
- }
- RAM(std::string name, int frequency)
- {
- this->name = name;
- this->frequency = frequency;
- }
- RAM(const RAM& ram)
- {
- this->frequency = ram.frequency;
- this->name = ram.name;
- }
- ~RAM()
- {
- }
- void setName(std::string name)
- {
- this->name = name;
- }
- std::string getName()
- {
- return name;
- }
- void setFrequency(int frequency)
- {
- this->frequency = frequency;
- }
- int getsetFrequency()
- {
- return frequency;
- }
- };
- //display.h
- #pragma once
- #include <string>
- struct Resolution
- {
- int width;
- int heigth;
- };
- class Display
- {
- private:
- std::string name;
- Resolution resolution;
- public:
- Display()
- {
- name = "Unknown";
- resolution = { 0,0 };
- }
- Display(std::string name, Resolution resolution)
- {
- this->name = name;
- this->resolution = resolution;
- }
- Display(const Display& display)
- {
- this->resolution = display.resolution;
- this->name = display.name;
- }
- ~Display()
- {
- }
- void setName(std::string name)
- {
- this->name = name;
- }
- std::string getName()
- {
- return name;
- }
- void setResoultion(Resolution resolution)
- {
- this->resolution = resolution;
- }
- Resolution getResolutin()
- {
- return resolution;
- }
- };
- //main.cpp
- #include "CPU.h"
- #include "Battery.h"
- #include "Display.h"
- #include "RAM.h"
- #include <iostream>
- #include <string.h>
- int main()
- {
- Laptop l1;
- std::cout << l1 << std::endl;
- CPU cpu("Intel", 4);
- Battery battery("bName", 20000);
- Display display("Asus", {1920,1080});
- RAM ram("Samsung", 2993);
- Laptop l2(cpu, display, ram, battery);
- std::cout << l2 << std::endl;
- Laptop l3 = l2;
- std::cout << l3 << std::endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment