Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.25 KB | None | 0 0
  1. //Wykonała Gabriela Błachut
  2. //zadanie 1_8
  3.  
  4. #include <iostream>
  5. #include <vector>
  6. #include <random>
  7. #include <string>
  8. using namespace std;
  9.  
  10.  
  11. class pixel{
  12.     public:
  13.     int x;
  14.     int y;
  15.     int R;
  16.     int G;
  17.     int B;
  18.  
  19.     pixel(int, int, int, int, int); //konstruktor
  20. };
  21.  
  22. pixel::pixel(int R, int G, int B, int x , int  y ){
  23. }
  24.  
  25. class pixelgray:public pixel{
  26.     public:
  27.         int l_;
  28.         int x;
  29.         int y;
  30.         pixelgray(int, int, int, int, int, int);
  31.         int convertRGB(int, int, int);
  32. };
  33.  
  34.  
  35. pixelgray::pixelgray(int r, int g, int b, int x, int y, int l):pixel(r,g,b,x,y), l_(l){
  36.  
  37. }
  38.  
  39. int pixelgray::convertRGB(int R, int G, int B){
  40.     l_ = 1 *R + 2 *G + 3 * B;
  41. }
  42. int operator > ( const pixelgray &A, const pixelgray &B ){ //przeciazenie operatora >
  43.     if(A.l_  > B.l_) return 1;
  44.     if(A.l_ < B.l_) return 2;
  45.     if(A.l_ == B.l_) return 0;
  46. }
  47.  
  48. int main(){
  49.  
  50.     pixel blue(0, 0, 255, 30, 20);
  51.     pixelgray graypix(20, 20, 20, 20, 20, 20);
  52.  
  53.  
  54.     pixel p1(rand() % 255, rand() % 255, rand() % 255, rand() % 255, rand() % 255);
  55.     pixel p2(rand() % 255, rand() % 255, rand() % 255, rand() % 255, rand() % 255);
  56.     pixel p3(rand() % 255, rand() % 255, rand() % 255, rand() % 255, rand() % 255);
  57.     pixel p4(rand() % 255, rand() % 255, rand() % 255, rand() % 255, rand() % 255);
  58.     pixel p5(rand() % 255, rand() % 255, rand() % 255, rand() % 255, rand() % 255);
  59.     pixel p6(rand() % 255, rand() % 255, rand() % 255, rand() % 255, rand() % 255);
  60.     pixel p7(rand() % 255, rand() % 255, rand() % 255, rand() % 255, rand() % 255);
  61.     pixel p8(rand() % 255, rand() % 255, rand() % 255, rand() % 255, rand() % 255);
  62.     pixel p9(rand() % 255, rand() % 255, rand() % 255, rand() % 255, rand() % 255);
  63.     pixel p10(rand() % 255, rand() % 255, rand() % 255, rand() % 255, rand() % 255);
  64.  
  65.  
  66.     vector <pixelgray> graypixels;  //utworzenie tablicy graypixels do ktorej wrrzucamy obiekty typu pixelgray
  67.  
  68.     for(int i = 0; i < 10; i++){
  69.         int r = rand() % 255;
  70.         int g = rand() % 255;
  71.         int b = rand() % 255;
  72.         int x = rand() % 100 + 1;
  73.         int y = rand() % 100 + 1;
  74.         int l = rand() % 100 +1;
  75.  
  76.         graypixels.push_back(pixelgray(r,g,b,x,y,l));
  77.  
  78.     }
  79.  
  80.  
  81.     return 0;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement