Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.86 KB | None | 0 0
  1. #include <iostream>
  2. #include "fn.h"
  3.  
  4. int main(){
  5. /*  Skaicius s1,s2;
  6.     const Skaicius konst(2);
  7.    
  8.    
  9.     s1.print();
  10.     s1=konst*konst;
  11.     s1.print();
  12.     ++s1=++s1 * konst;
  13.     s1.print();
  14.     s2=s1-- * ++s1;
  15.     s2.print();*/
  16.     //s2=++konst * konst--;  //neveikia, nes negalima keist konst
  17.     //s2--=s2-- * konst; //neveikia, nes gale --.
  18.  
  19.  
  20. Skaicius a(5);
  21.  
  22.     std::cout << "a:" << std::endl;
  23.     a.print();
  24.     a.adresas();
  25.     std::cout << "b:" << std::endl;
  26.     Skaicius b(5);
  27.     b = a;
  28.     b.print();
  29.     b.adresas();
  30. }
  31.  
  32. //main.cpp
  33.  
  34. #include <iostream>
  35. #include "fn.h"
  36.  
  37. using namespace std;
  38.  
  39. /*Skaicius& Skaicius::operator++(){
  40.     this->nr += 1;
  41.     return *this;
  42. }
  43.  
  44. const Skaicius Skaicius::operator--(int){
  45.     Skaicius tmp(0);
  46.     tmp.nr = this->nr;
  47.     this->nr -= 1;
  48.     return tmp;
  49. }
  50.  
  51. const Skaicius Skaicius::operator*(const Skaicius &desin) const{
  52.     Skaicius tmp(0);
  53.     tmp.nr = this->nr * desin.nr;
  54.     return tmp;
  55. }*/
  56.  
  57. Skaicius::Skaicius(short val){
  58.     x = new short;
  59.     *x = val;  
  60.    
  61.    
  62. }
  63.  
  64. void Skaicius::print () const{
  65.     cout << *(this->x) << endl;
  66. }
  67.  
  68. void Skaicius::adresas () const{
  69.     cout << this->x << endl;
  70. }
  71.  
  72. const Skaicius& Skaicius:: operator=(const Skaicius &desine){
  73.         if (this == &desine) {
  74.             std::cout << "iejo\n";
  75.             return *this;
  76.         }
  77.         *this->x = *desine.x;
  78.         return *this;
  79.    
  80. }
  81.  
  82. //fn.cpp
  83.  
  84. #ifndef FN_H
  85. #define FN_H
  86.  
  87. #include <iostream>
  88. #include <string>
  89.  
  90. class Skaicius
  91. {
  92.     short nr;
  93.     short * x;
  94. public:
  95.     Skaicius(short);
  96. //  Skaicius &operator++();
  97.     //const Skaicius operator--(int);
  98. //  const Skaicius operator*(const Skaicius &desin) const;
  99.     void print () const;
  100.     void adresas () const;
  101.     const Skaicius &operator=(const Skaicius &desine);
  102. };
  103.  
  104. #endif
  105.  
  106.  
  107. //fn.h
  108.  
  109. all: main.o fn.o
  110.     g++ main.o fn.o -o program
  111.     ./program
  112. main2.o: fn.cpp fn.h
  113.     g++ fn.cpp -c
  114.  
  115. main.o: main.cpp fn.h
  116.     g++ main.cpp -c
  117.  
  118. clean:
  119.     rm -f *.o *~
  120.  
  121. //Makefile
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement