The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 304 Weeks Ago, 2 Days Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
i need help with the following attached file with two problems on overloading and i need a complete program with all the functions. thank you.
P6.1 The interface for the Complex class is provided below (Note that the first letter of Complex is capitalized in order to distinguish it from the complex class defined in <complex> header file). A complex number c is defined as c = a + bi where c is the complex number consisting of two part: real part denoted by ‘a’ and an imaginary part denoted by ‘b’ multiplied by i and i =
. (The website at https://en.wikipedia.org/wiki/Complex_number provides an introductory level discussion of complex numbers.) Operations such as addition, subtraction, multiplication, and division can be performed on complex number in a way similar to the operations performed on rational numbers since computations only involve a and b, which are real numbers. For you convenience, the basic four operations or computations are provided below. Note that all four computations involve only real numbers (double type in C++), this program is very similar to the rational number problem.
Addition:
Subtraction: ![]()
Multiplication: ![]()
Division: ![]()
where i =
; it does not even enter into your program code.
classComplex
{
friendostream&operator<<(ostream&out, constComplex&cobj);
// Postcondition: contents of cobj is display in (a, b) format, e.g., 3 - 4i ==> (3, -4)
friendistream&operator>>(istream&out, Complex&cobj);
// prompt message "Enter real and imaginary values: " is displayed in main() by the client of the class
// Postconodition: two values entered by the users are assinged to real and imag of cobj, respectively
public:
Complex();
// default constructor
Complex(doubler, doublei);
// Postcondition: a complex object is declared and initialized to (r, i) or (0, 0) if no values are passed to the constructor
void setComplexNumber(doublea, doubleb);
// a mutator function
// Postcondition: set the real and imaginary parts of the calling complex object to a and b, respectively
Complexoperator+(constComplex&c2) const;
// Postcondition: sum of (*this) - c2 is returned
Complexoperator-(constComplex&c2) const;
// Postcondition: difference of (*this) - c2 is returned
Complexoperator*(constComplex&c2) const;
// Postcondition: product of (*this) * c2 is returned
Complexoperator/(constComplex&c2) const;
// Postcondition: quotient of (*this) / c2 is returned
booloperator==(constComplex&c2) const;
// Postcondition: returns true if (*this == c2) is true; returns false otherwise
private:
double real; // real part of a complex number (a, b)
double imag; // imaginary part of a complex number (a, b)
};
1. You are asked to implement all the member and non-member functions.
2. Write a main() function to test all the above functions.The output should be similar to the following sample display:

P6.2 (Optional) The interface for the String class (notice that the first letter of String in capitalized to distinguish it from the “string” class defined by C++ in <string> header file) is provide below.
classString
{
friendostream&operator<<(ostream&, constString&obj);
// Postcondition: output/display sobj
friendistream&operator>>(istream&, String&sobj);
// Client of this function prompts the user to enter a string
// Postcondition: input values from the user to initialize sobj
public:
String(constchar* = "");
// Default constructor
String(constString&sobj);
// copy constructor
// Postcondition: newly created object is initialized with values from sobj
~String();
// destructor
constString&operator=(constString&sobj);
// Postcondition: calling object gets the values of sobj
constString&operator+=(constString&sobj);
// Postcondition: sum/concatenation of the calling object and sobj is returned
bool operator==(constString&sobj) const;
// Postcondition: return true if calling object == sobj; return false otherwise
bool operator<(constString&) const;
// Postcondition: return true if calling object < sobj; return false otherwise
bool operator>(constString&) const;
// Postcondition: return true if calling object > sobj; return false otherwise
char operator[](int) const;
// Postcondition: return true if calling object < sobj; return false otherwise
int getLength() const;
// Postcondition: return true if calling object < sobj; return false otherwise
private:
int length;
char *sPtr; // points to a dynamic C-string, which is a null-terminated char array
};
You are asked to
1. Implement all member and friend functions
2. Write a main() function to test all those functions. You are asked to format the outputs to make it easy to read.
· Note: To carry out this assignment, you may need to use some of the C-string manipulation functions such as strcpy, strcat, strcmp, etc. You may want to visit http://www.cplusplus.com/reference/cstring/for more detailed information.
----------- ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly