Advertisement
Guest User

Operatori

a guest
Mar 20th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.36 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3. using namespace std;
  4.  
  5. class Covek{
  6. private:
  7.     char *ime;
  8.     char *prezime;
  9.     int godini;
  10. public:
  11.     Covek(){
  12.         ime =new char[0];
  13.         prezime=new char[0];
  14.     strcpy(ime,"");
  15.     strcpy(prezime,"");
  16.     godini=0;
  17.     }
  18.     Covek(char *ime1,char *prezime1,int godini1){
  19.     ime=new char[strlen(ime1)+1]; // +1 se dodava za null terminator new char ili new int ili new float
  20.     ime=ime1;
  21.     prezime=new char[strlen(prezime1)+1];
  22.     strcpy(prezime,prezime1);
  23.     godini=godini1;
  24.     }
  25.  
  26.  
  27.     Covek(const Covek &old){
  28.        ime=new char[strlen(old.ime)+1];
  29.        prezime=new char[strlen(old.prezime)+1];
  30.        godini=old.godini;
  31.        strcpy(ime,old.ime);
  32.        strcpy(prezime,old.prezime);
  33.     }
  34.  
  35.     void setIme(char *ime1){
  36.      ime=new char[strlen(ime1)+1];
  37.    ime=ime1;
  38.     }
  39.  char *getIme(){
  40.  return ime;
  41.  }
  42. void setGodina(int godina1){
  43. godini=godina1;
  44.  
  45. }
  46. int getGodina(){
  47. return godini;
  48. }
  49.  
  50. Covek operator +( int brojce){
  51. Covek novCovek(ime,prezime,godini+brojce);
  52. return novCovek;
  53.  
  54. }
  55. Covek operator +( Covek &vtoriotArgument){
  56. Covek novCovek(ime,prezime,godini+covek1.godini);
  57. return novCovek;
  58. }
  59.  
  60. };
  61. int main()
  62. {
  63.     Covek c1("ime","prezime",24);
  64.     //c1.setGodina(c1.getGodina()+1);
  65.     c1=c1+3;//optovaruvanje na +
  66.     cout<<c1.getGodina();
  67.  
  68.     return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement