Answer to Question #193418 in C++ for Bulb

Question #193418

Design a class template with overloaded operator / to perform a = b / c.


1
Expert's answer
2021-05-16T12:23:31-0400
#include<iostream>
using namespace std;
template<class T,class U>
class A
{
    T a;
    U b;
public:
    A(T c,  U d) { a = c; b = d; }
    friend A operator /(A a1, A a2)
    {
        float x1,x2;
        x1=a1.a/a2.a;
        x2=a1.b/a2.b;
        return A(x1,x2);
    }
    friend ostream& operator<<(ostream& out, A& v)
    {
        out << v.a << "+ ";


        out << v.b << "i ";


        return out;
     }
};
int main()
{
    A<int,int> a1(8,4),a2(6,2);
    A<int,int> val=a1/a2;
    cout<<val;
}

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