Provide code and full projects neatly and in proper form and in the correct header and cpp files((we have to make 3 files header file , one .cpp file for function and one more main cpp file)
Operator Overloading – Chapter 14
Over load the operators + (add), - (minus), * (multiply), = , != (comparison), and provide the operators << and >> to printout and read in respectively. See section 14.9 of Liang C++ textbook for help with some operators.
Note: Could you plz go through this code and let me
know if u need any changes in this.Thank You
_________________
// Complex.h
#ifndef COMPLEX_H
#define COMPLEX_H
class Complex
{
public :
Complex(double real = 0.0, double imag = 0.0); // constructor
void setReal(double real);
void setImag(double imag);
double getReal();
double getImag();
Complex add(const Complex&)const ; // operator+()
Complex minus(const Complex&)const ; // operator-()
Complex multiply(const Complex&)const ; // operator*()
bool operator!=(const Complex&)const ; // operator*()
/**
* Friend function declarations
* Output complex number to an output stream, Example 3+4i
*/
friend std::ostream & operator <<(std::ostream &dout,
const Complex&);
/**
* read complex number to an input stream
*/
friend std::istream & operator >>(std::istream &din,
Complex &);
private:
double real; // real part
double imag; // imaginary part
};
#endif // COMPLEX_H
_____________________________
// Complex.cpp
#include <iostream>
using namespace std;
#include "Complex.h"
//Parameterized constructor
Complex::Complex(double real,double imag)
{
this->real=real;
this->imag=imag;
}
//Function implementation which add two complex numbers by using
the operator overloading '+'
Complex Complex::add(const Complex &c)const
{
Complex temp;
temp.real=real+c.real;
temp.imag=imag+c.imag;
return temp;
}
//Function implementation which subtract two complex numbers by
using the operator overloading '-'
Complex Complex::minus(const Complex &c)const
{
Complex temp;
temp.real=real-c.real;
temp.imag=imag-c.imag;
return temp;
}
//Function implementation which subtract two complex numbers by
using the operator overloading '*'
Complex Complex::multiply(const Complex &c)const
{
Complex temp;
temp.real=real*c.real;
temp.imag=imag*c.imag;
return temp;
}
//Function implementation which display complex numbers by using
the operator overloading '<<'
ostream & operator << (ostream &dout, const Complex
&c)
{
dout<<"("<<c.real<<",
"<<c.imag<<")";
return dout;
}
//Function implementation which read complex numbers by using the
operator overloading '>>'
istream & operator >> (istream &din, Complex
&c)
{
char comma,bracket;
din>>bracket;
din>>c.real;
din>>comma;
din>>c.imag;
din>>bracket;
return din;
}
//function implementation for the overloading != operator
bool Complex::operator !=(const Complex &c)const
{
if(this->real!=c.real || this->imag!=c.imag)
return true;
else
return false;
}
______________________________
// main.cpp
#include <iostream>
using namespace std;
#include "Complex.h"
int main(int argc, char **argv)
{
Complex c1,c2,add,sub,mul;
cout<<"Enter Complex Number#1 in (a, b) form :";
cin>>c1;
cout<<"Enter Complex Number#2 in (a, b) form :";
cin>>c2;
add=c1.add(c2);
cout<<c1<<" + "<<c2<<" =
"<<add<<endl;
sub=c1.minus(c2);
cout<<c1<<" - "<<c2<<" =
"<<sub<<endl;
mul=c1.multiply(c2);
cout<<c1<<" * "<<c2<<" =
"<<mul<<endl;
if(c1!=c2)
cout<<c1<<" is not equal to
"<<c2<<endl;
else
cout<<c1<<" is equal to "<<c2<<endl;
return 0;
}
______________________________
Output:
_______________Could you plz rate me well.Thank
You
Provide code and full projects neatly and in proper form and in the correct header and cpp files((we have to make 3 file...
Provide code and full projects neatly and in proper form and in the correct header and cpp files((we have to make 3 files header file , one .cpp file for function and one more main cpp file) Operator Overloading – Chapter 14 Design a class Complex for representing complex numbers and the write overloaded operators for adding, subtracting, multiplying and dividing 2 complex numbers. Also create a function that will print a complex number on the screen. Provide appropriate constructors...
Provide code and full projects neatly and in proper form and in the correct header and cpp files((we have to make 3 files header file , one .cpp file for function and one more main cpp file) Template Classes – Chapter 12 Write an example of a template function that can swap 2 generic elements. Create a C++ class vector using the class diagram shown in Figure 12.2. in Liangs textbook. Do not use the C++ provided header file <vector>...
Design a class that contains: we have to make 3 files header file , one .cpp file for function and one more main cpp file 9.3 (The Account class) Design a class named Account that contains: An int data field named id for the account. A double data field named balance for the account. A double data field named annualInterestRate that stores the current interest rate. A no-arg constructor that creates a default account with id 0, balance 0, and...
CSC 252 Week 4 HW Provide code and full projects neatly and in proper form and in the correct header and cpp files. Code must compile, link and run for any credit.This is Microsoft visual Studio C++ and needs to be done correctly and neatly and I need to be able to copy and paste code to visual studio and this is for a grade so if you don't know the answer don't answer please and thank you. Exception Handling...
CSC 252 Week 4 HW Provide code and full projects neatly and in proper form and in the correct header and cpp files. Code must compile, link and run for any credit.This is Microsoft visual Studio C++ and needs to be done correctly and neatly and I need to be able to copy and paste code to visual studio and this is for a grade so if you don't know the answer don't answer please and thank you. Exception Handling...
C++ must use header files and implementation files as separate files. I’ll need a header file, implementation file and the main program file at a minimum. Compress these files into one compressed file. Make sure you have adequate documentation. We like to manipulate some matrix operations. Design and implement a class named matrixMagic that can store a matrix of any size. 1. Overload the addition, subtraction, and multiplication operations. 2. Overload the extraction (>>) and insertion (<<) operators to read...
If you have already answered this question, please do not repost your old solutions, you will be thumbs downed. I'm looking for NEW solutions only! Frac.h: // a Fraction object holds one Fraction number, one fraction #ifndef FRAC_H #define FRAC_H #include <iostream> using namespace std; //Creaing a Fraction class class Fraction { public: Fraction(int = 0, int = 1); // Function Declarations which performs operations on Fraction class Fraction add(const Fraction &); Fraction subtract(const Fraction& a); Fraction multiply(const Fraction& a);...
SCREENSHOTS ONLY PLEASE!!! DON'T POST ACTUAL CODE PLEASE LEAVE A SCREENSHOT ONLY! ACTUAL TEXT IS NOT NEEDED!!! mystring.h: //File: mystring1.h // ================ // Interface file for user-defined String class. #ifndef _MYSTRING_H #define _MYSTRING_H #include<iostream> #include <cstring> // for strlen(), etc. using namespace std; #define MAX_STR_LENGTH 200 class String { public: String(); String(const char s[]); // a conversion constructor void append(const String &str); // Relational operators bool operator ==(const String &str) const; bool operator !=(const String &str) const; bool operator >(const...
This C++ Program consists of: operator overloading, as well as experience with managing dynamic memory allocation inside a class. Task One common limitation of programming languages is that the built-in types are limited to smaller finite ranges of storage. For instance, the built-in int type in C++ is 4 bytes in most systems today, allowing for about 4 billion different numbers. The regular int splits this range between positive and negative numbers, but even an unsigned int (assuming 4 bytes)...