Purchase Solution

Classes and objects

Not what you're looking for?

Ask Custom Question

The code is attached below.
Provide operator overloading functions to facilitate the following operations on any complex numbers A, B and C:
a. A == B; overload Boolean operator == to test if A and B are equal
b. C = A*B; overload multiplication operator *
c. C = A/B; overload division operator /
d. A = B; overload assignment operator =
e. cin >> A >> B; overload stream operator >> to take user input for real and imaginary part of the number (You might want to create a friend function to facilitate
this)
Also, write a static function for the complexNumber class which initializes numCount variable. Your function takes an integer argument provided by user. Assign this:
argument to numCount variable.
#include <iostream>
using namespace std;class complexNumber {
private:
static int numCount; int Re, Imag;
public:
complexNumber(){numCount++;} // constructor with no argument
complexNumber(int Real, int Imaginary){numCount++; cout << "constructor
with argument is called" << endl;
Re = Real; Imag = Imaginary;}// constructor with arguments
~complexNumber(){cout << "destructor is called" <<endl; numCount--;}
complexNumber (complexNumber &anycomplex) {numCount++; cout <<endl;
cout <<"Copy constructor called" << endl; Re = anycomplex.Re; Imag =
anycomplex.Imag;} // copy constructor
void printComplex(){ cout <<"number of active complex numbers= " <<
numCount << " and present number.....= " << Re <<" + j" << Imag << endl;}
complexNumber operator+(complexNumber &b){complexNumber temp; cout <<
"overloaded + iscalled" << endl; temp.Re = Re + b.Re; temp.Imag = Imag +
b.Imag; return temp;}
complexNumber operator++(){complexNumber temp; cout << "overloaded
++(pre) called" << endl; temp.Re = ++Re; temp.Imag = ++Imag; return temp;}
complexNumber operator++(int){complexNumber temp; cout << "overloaded
++(post) called" << endl; temp.Re = Re++; temp.Imag = Imag++; return temp;}
friend ostream & operator<< (ostream &out, complexNumber
&somecomplex){cout << "overloaded << called" <<endl; out <<
somecomplex.Re<<"+ j" << somecomplex.Imag; return out;}
};
int complexNumber::numCount = 0 ;
void printC(complexNumber a) {a.printComplex();}
int main (){
complexNumber A, B(1,2), C(2,3);
B.printComplex();
++ B;
printC(C);
A = B + C;
A = B++;
A.printComplex();
B.printComplex();
cout << A << B;
cin.get();
return 0;
}

Problem 2: Look at the following class definition:
class Employee{
private: static int numEmployee; // number of employees
char * firstName; // first name of the employee
char * lastName; // last name of employee
public: // include your methods (constructors, destructors etc..
here)
};
Provide
a. constructor; should take two arguments for firstName and lastName
b. copy constructor
c. destructor
d. Overload assignment operator =
Note that we are using a pointer to character array, therefore, we must use deep copy; also, to facilitate that you must utilize the new/delete operator to create/destroy a dynamic array while designing your methods. You should adjust the numEmployee variable while creating/destroying an object.
e. Provide a method that prints the number of employee, first name and last name of the employee. Show the use of above functions in your main program.

Purchase this Solution

Solution Summary

The expert examines classes and objects for assignment operators.

Solution Preview

There are some points I want to make. Your code for complexNumber uses integers for real and imaginary parts of a complex ...

Purchase this Solution


Free BrainMass Quizzes
Excel Introductory Quiz

This quiz tests your knowledge of basics of MS-Excel.

C++ Operators

This quiz tests a student's knowledge about C++ operators.

Java loops

This quiz checks your knowledge of for and while loops in Java. For and while loops are essential building blocks for all Java programs. Having a solid understanding of these constructs is critical for success in programming Java.

Basic Networking Questions

This quiz consists of some basic networking questions.

Inserting and deleting in a linked list

This quiz tests your understanding of how to insert and delete elements in a linked list. Understanding of the use of linked lists, and the related performance aspects, is an important fundamental skill of computer science data structures.