Advertisement
metalni

OOP Labs 3 Ureduvanje na dom

May 30th, 2020
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.63 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3.  
  4. using namespace std;
  5. // class Masa
  6. class Masa {
  7.     private:
  8.         int width;
  9.         int length;
  10.     public:
  11.         Masa(){}
  12.         Masa(int w, int l);
  13.         void pecati();
  14. };
  15.  
  16. Masa::Masa(int w, int l) {
  17.     this->width = w;
  18.     this->length = l;
  19. }
  20. void Masa::pecati(){
  21.     cout << "Masa: " << width << " " << length << endl;
  22. }
  23. // class Soba
  24. class Soba {
  25.     private:
  26.         int width;
  27.         int length;
  28.         Masa masa;
  29.     public:
  30.         Soba(){}
  31.         Soba(int w, int l, Masa m);
  32.         void pecati();
  33. };
  34.  
  35. Soba::Soba(int w, int l, Masa m) {
  36.     this->width = w;
  37.     this->length = l;
  38.     this->masa = m;
  39. }
  40.  
  41. void Soba::pecati(){
  42.     cout << "Soba: " << width << " " << length << " ";
  43.     masa.pecati();
  44. }
  45.  
  46. // class Kukja
  47. class Kukja {
  48.     private:
  49.         Soba soba;
  50.         char address[50];
  51.     public:
  52.         Kukja(){}
  53.         Kukja(Soba s, const char * adresa);
  54.         void pecati();
  55. };
  56.  
  57. Kukja::Kukja(Soba s, const char * adresa){
  58.     this->soba = s;
  59.     strcpy(this->address, adresa);
  60. }
  61. void Kukja::pecati(){
  62.     cout << "Adresa: " << address << " ";
  63.     soba.pecati();
  64. }
  65. //ne smee da se menuva main funkcijata!
  66. int main(){
  67.     int n;
  68.     cin>>n;
  69.     for(int i=0;i<n;i++){
  70.         int masaSirina,masaDolzina;
  71.         cin>>masaSirina;
  72.         cin>>masaDolzina;
  73.         Masa m(masaSirina,masaDolzina);
  74.         int sobaSirina,sobaDolzina;
  75.         cin>>sobaSirina;
  76.         cin>>sobaDolzina;
  77.         Soba s(sobaSirina,sobaDolzina,m);
  78.         char adresa[30];
  79.         cin>>adresa;
  80.         Kukja k(s,adresa);
  81.         k.pecati();
  82.     }
  83.    
  84.     return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement