#include <cstdlib> #include <iostream> #include <vector> #include <cmath> using namespace std; class Overload { public: Overload(); Overload(int); Overload operator+(Overload &) ; void SetK(int k); int GetK() const; void SetVect(vector<double> vect); vector<double> GetVect() const; private: vector<double> vect ; int k ; }; int main(int argc, char** argv) { Overload a,b(10),c(10) ; a= b+c ; cout <<"\nAdded :\n" ; for(unsigned int i=0;i<a.GetVect().size(); ++i) cout <<"Res : " << a.GetVect()[i] << endl ; cout << "first element : "<< a.GetVect()[0] << endl ; return 0; } Overload::Overload() { k=10 ; cout << "\nFrist Started\n" ; for(unsigned int i=0;i<k ; ++i){ double res = 1/pow(i,2) ; vect.push_back(res); cout << vect[i] << " " ; } cout << "VEctor size : " << vect.size() << endl ; cout <<"\nfirst ended\n"<< endl ; } Overload::Overload(int k) { double res=0 ; cout << "\nsecond started : \n" ; for(unsigned int i=0;i<k ; ++i){ res = 1/pow(i,2) ; vect.push_back(res); cout << vect[i] << " " ; } cout << "\nsecond ended : \n" ; } Overload Overload::operator+(Overload &a){ double res=0 ; Overload x ; for(unsigned int i=0 ;i<vect.size();i++) { res = vect[i] + a.vect[i]; x.vect.push_back(res) ; } return x ; } void Overload::SetK(int k) { this->k = k; } int Overload::GetK() const { return k; } void Overload::SetVect(vector<double> vect) { this->vect = vect; } vector<double> Overload::GetVect() const { return vect; }
::Overload()
::Overload(int k)
for
1/pow(i,2)
i=0
Inf
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)