Advertisement
Josif_tepe

Untitled

Mar 20th, 2021
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4. class Momche {
  5. private:
  6.     char ime[101];
  7.     char prezime[101];
  8.     int godini;
  9. public:
  10.     Momche() { // empty constructor
  11.        
  12.     }
  13.     Momche(const char *i, const char *p, int g) { // constructor with
  14.         strcpy(ime, i);
  15.         strcpy(prezime, p);
  16.         godini = g;
  17.     }
  18.     ~Momche() {
  19.        
  20.     }
  21.     void pecati() {
  22.         cout << "Momche: " << ime << " " << prezime << " " << godini << endl;
  23.     }
  24.     int get_godini() const {
  25.         return godini;
  26.     }
  27. };
  28. class Devojche {
  29. private:
  30.     char ime[101];
  31.     char prezime[101];
  32.     int godini;
  33. public:
  34.     Devojche() {
  35.        
  36.     }
  37.     Devojche(const char *i, const char *p, int g) {
  38.         strcpy(ime, i);
  39.         strcpy(prezime, p);
  40.         godini = g;
  41.     }
  42.     ~Devojche() {
  43.        
  44.     }
  45.     void pecati() {
  46.         cout << "Devojche: " << ime << " " << prezime << " " << godini << endl;
  47.     }
  48.     int get_godini() const {
  49.         return godini;
  50.     }
  51.    
  52. };
  53. class Sredba {
  54. private:
  55.     Momche m;
  56.     Devojche d;
  57. public:
  58.     Sredba() {
  59.        
  60.     }
  61.     Sredba(Momche _m, Devojche _d) {
  62.         m = _m;
  63.         d = _d;
  64.     }
  65.     ~Sredba() {
  66.        
  67.     }
  68.     void print() {
  69.         m.pecati();
  70.         d.pecati();
  71.     }
  72.     void daliSiOdgovaraat() {
  73.         int razlika = abs(m.get_godini() - d.get_godini());
  74.         if(razlika <= 5) {
  75.             cout << "Si odgovaraat" << endl;
  76.         }
  77.         else {
  78.             cout << "Ne si odgovaraat" << endl;
  79.         }
  80.     }
  81. };
  82. int main() {
  83.    
  84.     Momche m("a", "b", 27);
  85.     Devojche d("q", "w", 20);
  86.     Sredba s(m, d);
  87.     s.daliSiOdgovaraat();
  88.     return 0;
  89. }
  90.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement