Advertisement
StefiIOE

momche i devojce

Mar 30th, 2019
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.16 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #include <cmath>
  4. using namespace std;
  5. class Momche{
  6.     private:
  7.   char ime[20];
  8.   char prezime[20];
  9.   int godini;
  10.   public:
  11.   Momche(char *ime,char *prezime, int godini){
  12.       strcpy(this->ime,ime);
  13.       strcpy(this->prezime,prezime);
  14.       this->godini=godini;
  15.   }
  16.   Momche(const Momche  &m){
  17.        strcpy(this->ime,m.ime);
  18.       strcpy(this->prezime,m.prezime);
  19.       this->godini=m.godini;
  20.      
  21.   }
  22.  
  23.  void pecati(){
  24.      cout<<"Momche: "<<"Ime"<<" "<<"prezime"<<", "<<"godini"<<endl;  
  25.  }
  26.      int getGodini()
  27.      {
  28.          return godini;
  29.      }
  30.  
  31.   ~Momche (){}
  32. };
  33. class Devojche{
  34.     private:
  35.   char ime[20];
  36.   char prezime[20];
  37.   int godini;
  38.   public:
  39.   Devojche(char *ime,char *prezime, int godini){
  40.       strcpy(this->ime,ime);
  41.       strcpy(this->prezime,prezime);
  42.       this->godini=godini;
  43.   }
  44.   Devojche(const Devojche  &d){
  45.        strcpy(this->ime,d.ime);
  46.       strcpy(this->prezime,d.prezime);
  47.       this->godini=d.godini;
  48.      
  49.   }
  50.  
  51.  void pecati(){
  52.      cout<<"Devojche: "<<"Ime"<<" "<<"prezime"<<", "<<"godini"<<endl;  
  53.  }
  54.       int getGodini(){
  55.          return godini;
  56.      }
  57.   ~Devojche (){}
  58. };
  59. class Sredba{
  60.     private:
  61.     Momche momche;
  62.     Devojche devojche;
  63.     public:
  64.     Sredba(const Momche m, const Devojche d);
  65.    
  66. void pecati(){
  67.     cout<<"Sredba:"<<endl;
  68.     momche.pecati();
  69.     devojche.pecati();
  70.    
  71. }    
  72. void daliSiOdgovaraat(){
  73.     if(abs(momche.getGodini()-devojche.getGodini())<=5){
  74.         cout<<"Si odgovaraat"<<endl;
  75.     }
  76.     else{
  77.         cout<<"Ne si odgovaraat "<<endl ;
  78.     }
  79. }
  80.    
  81. };
  82.  
  83. int main() {
  84.  
  85. int godini;
  86. char ime[20], prezime[20];
  87. cout << "Informacii za momche: " << endl;
  88. cout << "Ime: ";
  89. cin >> ime;
  90. cout << "Prezime: ";
  91. cin >> prezime;
  92. cout << "Godini: ";
  93. cin >> godini;
  94. Momche m(ime, prezime, godini);
  95. Momche momche(m);
  96. cout << "Informacii za Devojche: " << endl;
  97. cout << "Ime: ";
  98. cin >> ime;
  99. cout << "Prezime: ";
  100. cin >> prezime;
  101. cout << "Godini: ";
  102. cin >> godini;
  103. Devojche d(ime, prezime,godini);
  104. Devojche devojche(d);
  105. Sredba s(momche, devojche);
  106. s.pecati();
  107. s.daliSiOdgovaraat();
  108. return 0;
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement