Instructions: All the code should follow the standard object oriented programmin
ID: 3642371 • Letter: I
Question
Instructions:All the code should follow the standard object oriented programming practices (private data field, getter and setters, no inline implementation ect)
Complete this problem:
Complex Numbers are those numbers which are having two parts, real part and imaginary part and is represented as a + ib where a represents real part and b represents imaginary part and i is iota(square root of -1). You have to implement a class for Complex Numbers with the following functionalities given below (Note: i is used only for notational purposes and will not be part of your class de?nition):
A. Create constructors for class Complex Numbers which allows arbitrary values for a and b. If no values are supplied during the object creation, then constructor should make sure that default values for a and b are zero.
B. Create getters, setters and output functions for your class fields which allow you to retrieve, set and output values of data fields. For output function, all data fields are outputted.
C. Write a function multiplication which takes two Complex Numbers as its input parameters and return a Complex Number as its output. The multiplication of two complex numbers (a+ib) and (c + id) is (ac ? bd + i(bc + ad))
Explanation / Answer
#include<iostream>
using namespace std;
class complex
{
public: complex() :a(0) , b(0)
{
}
void setcomplex(int a, int b)
{
this.a = a;
this.b = b;
}
int geta()
{
return a;
}
int getb()
{
return b;
}
complex add(complex a, complex b)
{
complex temp;
temp.setcomplex(a.geta+b.geta , a.getb+b.getb);
return temp;
}
privatve:
int a,b;
};
int main()
{
complex a;
complex b;
a.setcomplex(4,5);
b.setcomplex(1,2);
complex c;
c = add(a,b);
return 0;
}