Answer to Question #102008 in C++ for Fardeen Shaikh

Question #102008
Write a C++ program to create a class Array that contains one float array as member. Overload the Unary ++ and -- operators to increase or decrease the value of each element of an array. Use friend function for operator function.
1
Expert's answer
2020-01-31T04:36:16-0500
 #include<vector>

using namespace std;

class Array {

private:

vector<float> array;

public:

friend void operator++(Array&obj);//prefix increment

friend void operator++(Array&obj,int var);//postfix increment

friend void operator--(Array&obj);//prefix decrement

friend void operator--(Array&obj,int var);//postfix decrement

};

void operator++(Array&obj) {

for (int i = 0; i < obj.array.size(); i++)

obj.array[i]+=1;

}

void operator++(Array&obj, int var) {

for (int i = 0; i < obj.array.size(); i++)

obj.array[i]+=1;

}

void operator--(Array&obj) {

for (int i = 0; i < obj.array.size(); i++)

obj.array[i]-=1;

}

void operator--(Array&obj, int var) {

for (int i = 0; i < obj.array.size(); i++)

obj.array[i]-=1;

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS