Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string.h>
- using namespace std;
- class Covek{
- private:
- char *ime;
- char *prezime;
- int godini;
- public:
- Covek(){
- ime =new char[0];
- prezime=new char[0];
- strcpy(ime,"");
- strcpy(prezime,"");
- godini=0;
- }
- Covek(char *ime1,char *prezime1,int godini1){
- ime=new char[strlen(ime1)+1]; // +1 se dodava za null terminator new char ili new int ili new float
- ime=ime1;
- prezime=new char[strlen(prezime1)+1];
- strcpy(prezime,prezime1);
- godini=godini1;
- }
- Covek(const Covek &old){
- ime=new char[strlen(old.ime)+1];
- prezime=new char[strlen(old.prezime)+1];
- godini=old.godini;
- strcpy(ime,old.ime);
- strcpy(prezime,old.prezime);
- }
- void setIme(char *ime1){
- ime=new char[strlen(ime1)+1];
- ime=ime1;
- }
- char *getIme(){
- return ime;
- }
- void setGodina(int godina1){
- godini=godina1;
- }
- int getGodina(){
- return godini;
- }
- Covek operator +( int brojce){
- Covek novCovek(ime,prezime,godini+brojce);
- return novCovek;
- }
- Covek operator +( Covek &vtoriotArgument){
- Covek novCovek(ime,prezime,godini+covek1.godini);
- return novCovek;
- }
- };
- int main()
- {
- Covek c1("ime","prezime",24);
- //c1.setGodina(c1.getGodina()+1);
- c1=c1+3;//optovaruvanje na +
- cout<<c1.getGodina();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement