# please just help with parts afterr //  3) Write friend function for the following class to overload the << and >> operators. The friend function, input operator (operator >>), should read 5 elements into the array attribute called “grade” for the objet and output (operator <<) should print the content of the array “grade” of the object on the screen. class Math   { // put the prototype of the friend functions here public: intgrade[5]:math( )   {for (int i=0, i<10, i++) grade[i] = 0;}; // implement the overloaded input operator function // implement the overloaded output operator function   void main (){ Math ObjA; //your friend function should be able to take care of the following code  cin >> ObjA; cout << ObjA;

Question
18 views

please just help with parts afterr //

3) Write friend function for the following class to overload the << and >> operators. The friend function, input operator (operator >>), should read 5 elements into the array attribute called “grade” for the objet and output (operator <<) should print the content of the array “grade” of the object on the screen.

class Math

{ // put the prototype of the friend functions here

public:

math( )   {for (int i=0, i<10, i++) grade[i] = 0;};

// implement the overloaded input operator function

// implement the overloaded output operator function

void main ()

{

Math ObjA;

//your friend function should be able to take care of the following code

cin >> ObjA;

cout << ObjA;

check_circle

Step 1

A friend function is defined outside the context of a class, but it has the rights to access the member and member function of that class. That is, it can access private, public and protected members of that class.

A keyword friend is used to defining a friend function.

Syntax:

class class_name

{

friend function_declaration(arguments) {

}

}

Step 2

Algorithm:

• Build a Math class.
• Declare the prototype of the input friend function with the input stream(istream) and the input operator (> >).
• Example:- friend istream & operator >> (istream &input, Math &a)
• Declare the prototype of the output friend function with the output stream(ostream) and the input operator (< <).
• Example:- friend ostream & operator << (ostream &output, const Math &a);
• Declares an integer type array with size 5 called grade.
• Insert default value in array class with the default constructor.
• Implement the function of the overloaded input operator.
• Implement the function of the overloaded output operator.
• Build math class object.
• Calling input output friend function.
Step 3

#include <iostream>

using namespace std;

//build a class Math

class Math {

//declaration of the input friend function

friend istream & operator >> (istream & input, Math & a);

//declaration of the output friend function

friend ostream & operator << (ostream & output,

const Math & a);

public:

//an array declaration which takes 5 elements

//default constructor

Math()

{

for (int i = 0; i < 5; i++) {

}

}

};

//definition of the input friend function

istream & operator >> (istream & input, Math & a)

{

cout << "Please enter 5 Integer ...

### Want to see the full answer?

See Solution

#### Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in