Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the class Fivelnt that holds an array of 5 ints as data members, and ha

ID: 3706780 • Letter: C

Question

Consider the class Fivelnt that holds an array of 5 ints as data members, and has several operators defined class FiveInt public: int A[5] int& operator [ (int i) return Alil) friend istream&operator; >> (istream ∈, FiveInt &f;) for (int i-0; i> f[i] return in; Implement the following operators so that the code will program will compile and run: For this operator, return void, take a single int as a parameter, and add it to each of the five ints in the array. >operator already defined)

Explanation / Answer

class FiveInt {
public:
   int A[5];
  
   void operator += (int n) {
       for(int i = 0; i < 5; i++) {
           A[i] += n;
       }
   }
  
   friend ostream &operator <<(ostream &out, const FiveInt &f) {
       for(int i = 0; i < 5; i++) {
           cout << f.A[i];
           if(i == 4) {
               cout << endl;
           } else {
               cout << " ";
           }
       }
       return out;
   }
  
};