Facebook
From Burly Elephant, 6 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 267
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. class Product
  8. {
  9. public:
  10.         Product();
  11.         ~Product();
  12.         string nazwa;
  13.         double cena;
  14.         friend class Order;
  15.         void wyswietl();
  16. };
  17.  
  18. void Product::wyswietl() {
  19.         cout <<endl << nazwa;
  20.         cout <<endl << cena;
  21. }
  22.  
  23. Product::Product()
  24. {
  25.         cout << endl << "Nazwa produktu: ";
  26.         cin >> nazwa;
  27.         cena = rand() % 10;
  28. }
  29.  
  30. Product::~Product()
  31. {
  32. }
  33.  
  34. class Order
  35. {
  36. public:
  37.         Order();
  38.         ~Order();
  39.         int licznik;
  40.         int ID;
  41.         Product* produkty;
  42.         int iloscProduktow;
  43.         int limit = 5;
  44.         void show();
  45. }
  46.  
  47. Order::Order()
  48. {
  49.         Product prod[5];
  50.        
  51.         for (int i = 0; i <= 4; i++) {
  52.                 prod[i].cena = 0;
  53.                 prod[i].nazwa = " ";
  54.         }
  55. }
  56.  
  57. void Order::show() {
  58.        
  59. }
  60.  
  61. Order::~Order()
  62. {
  63. }
  64.  
  65. Order* operator +=(Order &ord, Product prod) {
  66.         *ord.produkty = prod;
  67.         ord.iloscProduktow++;
  68.         return &ord;
  69. }
  70.  
  71. Order* operator -=(Order &ord, Product prod) {
  72.        
  73.         ord.iloscProduktow--;
  74.         return &ord;
  75. }
  76.  
  77. int main()
  78. {
  79.         Product prod1;
  80.         //Product prods[3];
  81.  
  82.         Order ord1;
  83.  
  84.         ord1 += prod1;
  85.  
  86.         prod1.wyswietl();
  87.  
  88.         ord1.show();
  89.  
  90.         ord1 -= prod1;
  91.  
  92.         system("pause");
  93.     return 0;
  94. }
  95.  
  96.