Slavik9510

Untitled

Oct 6th, 2022
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.27 KB | None | 0 0
  1. //Laptop.h
  2. #pragma once
  3. #define _CRT_SECURE_NO_WARNINGS
  4. #include "CPU.h"
  5. #include "Display.h"
  6. #include "RAM.h"
  7. #include "Battery.h"
  8. #include <iostream>
  9. class Laptop
  10. {
  11. private:
  12.     CPU cpu;
  13.     Display display;
  14.     RAM ram;
  15.     Battery battery;
  16. public:
  17.     Laptop()
  18.     {
  19.         cpu = CPU();
  20.         display = Display();
  21.         ram = RAM();
  22.         battery = Battery();
  23.     }
  24.     Laptop(CPU cpu, Display display, RAM ram, Battery battery)
  25.     {
  26.         this->cpu = cpu;
  27.         this->display = display;
  28.         this->ram = ram;
  29.         this->battery = battery;
  30.     }
  31.     ~Laptop()
  32.     {
  33.         std::cout << "Laptor destructor called" << std::endl;
  34.     }
  35.     Laptop(const Laptop& laptop)
  36.     {
  37.         cpu = laptop.cpu;
  38.         display = laptop.display;
  39.         ram = laptop.ram;
  40.         battery = laptop.battery;
  41.     }
  42.     Laptop& operator =(const Laptop& laptop)
  43.     {
  44.         if (this != &laptop)
  45.         {
  46.             cpu = laptop.cpu;
  47.             display = laptop.display;
  48.             ram = laptop.ram;
  49.             battery = laptop.battery;
  50.         }
  51.         return *this;
  52.     }
  53.     friend std::ostream& operator <<(std::ostream& out, Laptop laptop);
  54. };
  55. //laptop.cpp
  56. #include "Laptop.h"
  57. #include <iostream>
  58.  
  59. std::ostream& operator <<(std::ostream& out, Laptop laptop)
  60. {
  61.     out << "CPU: " << laptop.cpu.getName() << std::endl;
  62.     out << "Display: " << laptop.display.getName() << std::endl;
  63.     out << "Ram: " << laptop.ram.getName() << std::endl;
  64.     out << "Battery: " << laptop.battery.getName() << std::endl;
  65.     return out;
  66. }
  67. //battery.h
  68. #pragma once
  69. #include <string>
  70. class Battery
  71. {
  72. private:
  73.     std::string name;
  74.     int size;
  75. public:
  76.     Battery()
  77.     {
  78.         name = "Unknown";
  79.         size = 0;
  80.     }
  81.     Battery(std::string name, int size)
  82.     {
  83.         this->name = name;
  84.         this->size = size;
  85.     }
  86.     Battery(const Battery& battery)
  87.     {
  88.         this->size = battery.size;
  89.         this->name = battery.name;
  90.     }
  91.     ~Battery()
  92.     {
  93.     }
  94.     void setName(std::string name)
  95.     {
  96.         this->name = name;
  97.     }
  98.     std::string getName()
  99.     {
  100.         return name;
  101.     }
  102.     void setSize(int size)
  103.     {
  104.         this->size = size;
  105.     }
  106.     int getSize()
  107.     {
  108.         return size;
  109.     }
  110. };
  111. //cpu.h
  112. #pragma once
  113. #include <string>
  114. class CPU
  115. {
  116. private:
  117.     std::string name;
  118.     int cores;
  119. public:
  120.     CPU()
  121.     {
  122.         name = "Unknown";
  123.         cores = 0;
  124.     }
  125.     CPU(std::string name, int cores)
  126.     {
  127.         this->name = name;
  128.         this->cores = cores;
  129.     }
  130.     CPU(const CPU& cpu)
  131.     {
  132.         this->cores = cpu.cores;
  133.         this->name = cpu.name;
  134.     }
  135.     ~CPU()
  136.     {
  137.     }
  138.     void setName(std::string name)
  139.     {
  140.         this->name = name;
  141.     }
  142.     std::string getName()
  143.     {
  144.         return name;
  145.     }
  146.     void setCores(int cores)
  147.     {
  148.         this->cores = cores;
  149.     }
  150.     int getCores()
  151.     {
  152.         return cores;
  153.     }
  154. };
  155. //ram.h
  156. #pragma once
  157. #include <string>
  158. class RAM
  159. {
  160. private:
  161.     std::string name;
  162.     int frequency;
  163. public:
  164.     RAM()
  165.     {
  166.         name = "Unknown";
  167.         frequency = 0;
  168.     }
  169.     RAM(std::string name, int frequency)
  170.     {
  171.         this->name = name;
  172.         this->frequency = frequency;
  173.     }
  174.     RAM(const RAM& ram)
  175.     {
  176.         this->frequency = ram.frequency;
  177.         this->name = ram.name;
  178.     }
  179.     ~RAM()
  180.     {
  181.     }
  182.     void setName(std::string name)
  183.     {
  184.         this->name = name;
  185.     }
  186.     std::string getName()
  187.     {
  188.         return name;
  189.     }
  190.     void setFrequency(int frequency)
  191.     {
  192.         this->frequency = frequency;
  193.     }
  194.     int getsetFrequency()
  195.     {
  196.         return frequency;
  197.     }
  198. };
  199. //display.h
  200. #pragma once
  201. #include <string>
  202. struct Resolution
  203. {
  204.     int width;
  205.     int heigth;
  206. };
  207. class Display
  208. {
  209. private:
  210.     std::string name;
  211.     Resolution resolution;
  212. public:
  213.     Display()
  214.     {
  215.         name = "Unknown";
  216.         resolution = { 0,0 };
  217.     }
  218.     Display(std::string name, Resolution resolution)
  219.     {
  220.         this->name = name;
  221.         this->resolution = resolution;
  222.     }
  223.     Display(const Display& display)
  224.     {
  225.         this->resolution = display.resolution;
  226.         this->name = display.name;
  227.     }
  228.     ~Display()
  229.     {
  230.     }
  231.     void setName(std::string name)
  232.     {
  233.         this->name = name;
  234.     }
  235.     std::string getName()
  236.     {
  237.         return name;
  238.     }
  239.     void setResoultion(Resolution resolution)
  240.     {
  241.         this->resolution = resolution;
  242.     }
  243.     Resolution getResolutin()
  244.     {
  245.         return resolution;
  246.     }
  247.  
  248. };
  249. //main.cpp
  250. #include "CPU.h"
  251. #include "Battery.h"
  252. #include "Display.h"
  253. #include "RAM.h"
  254. #include <iostream>
  255. #include <string.h>
  256.  
  257. int main()
  258. {
  259.     Laptop l1;
  260.     std::cout << l1 << std::endl;
  261.     CPU cpu("Intel", 4);
  262.     Battery battery("bName", 20000);
  263.     Display display("Asus", {1920,1080});
  264.     RAM ram("Samsung", 2993);
  265.     Laptop l2(cpu, display, ram, battery);
  266.     std::cout << l2 << std::endl;
  267.     Laptop l3 = l2;
  268.     std::cout << l3 << std::endl;
  269. }
Advertisement
Add Comment
Please, Sign In to add comment