For this part of the lab think about and come up with a poss

For this part of the lab, think about and come up with a possible (doable by you in a reasonable amount of time) projects that involve data structures.

Be very clear about exactly what the problem being tackled is and how data structures is involved in the project.

Equally, be clear about how you will acquire your data.

If you wish to do a project involving an interface, sound, or something along those lines, you will have to google to find out what c++ libraries you will need to use. You should list the libraries you are thinking of including, and what they supply.

Solution

Here is a small project of complex class in cpp. It simulates complex class with operator overloading

#ifndef COMPLEX_H
#define COMPLEX_H
#include<iostream>


class complex {
public:
complex();
complex(double a);
complex(double a,double b);
complex(int a,int b);
void print() const;
void set(double a=0,double b=0);
void set(int a=0,int b=0);
double getReal() const;
double getImag() const;
void get(double&,double&) const;
complex operator+ (double&);
complex operator+ (complex&);
complex operator+= (complex&);
complex operator+= (int&);
complex operator++ (int);
complex operator++ ();
complex operator- (double&);
complex operator- (complex&);
complex operator-= (complex&);
complex operator-= (double&);
complex operator-- (int a);
complex operator-- ();
complex operator* (complex&);
complex operator* (double&);
complex operator*= (complex&);
complex operator*= (double&);
complex operator/ (complex&);
complex operator/= (complex&);
complex operator/= (double);
complex operator/ (double);
void operator= (const complex&);
bool operator== (complex&);
bool operator!=(complex &c);
//std::istream operator>> (std::istream &in, complex& c);
template <typename T>
friend istream& operator>>(istream& os, complex c);
friend ostream& operator<<(ostream& os, const complex &c);
//friend std::ostream &operator<<(std::ostream &out, complex c);
complex conj() ;
double norm() ;
double modulus();


double real;
double imag;
};
#endif // COMPLEX_H

#include \"complex.h\"
//#include<iostream>
#include <string>
#include <stdio.h>
#include<math.h>

using namespace std;

complex::complex(){
real = 0;
imag = 0;
}
complex::complex(double a){
real=a;
imag = 0;
}
complex::complex (double a, double b){
real=a;
imag=b;
}
complex::complex (int a, int b){
real=a;
imag=b;
}
complex complex::operator+ (double& a){
return complex(real + a, imag);
}
complex complex::operator+ (complex& a){
return complex(real + a.real, imag + a.imag);
}
complex complex::operator+= (complex& a){
return complex (real+=a.real, imag+=a.imag);
}
complex complex::operator+= (int& a){
return complex (real+=a, imag);
}
complex complex::operator++ (int a){
return complex (real, imag);
}
complex complex::operator++ ( ){
complex a=complex(real, imag);
real+=1;
return a;
}
complex complex::operator- (double& a){
return complex(real + a, imag);
}
complex complex::operator- (complex& a){
return complex(real - a.real, imag - a.imag);
}
complex complex::operator-= (complex& a){
return complex (real-=a.real, imag-=a.imag);
}
complex complex::operator-= (double& a){
return complex (real-=a, imag);
}
complex complex::operator--(int a){
return complex (real-a, imag);
}
complex complex::operator-- (){
return complex (real, imag);
}

complex complex::operator* (complex& a){
return complex((real * a.real)- (imag* a.imag), (real*a.imag +imag*a.real));
}
complex complex::operator* (double& a){
return complex(real * a, imag);
}
complex complex::operator*= (complex& a)
{
   return complex((real * a.real)- (imag* a.imag), (real*a.imag +imag*a.real));
}

complex complex::operator*= (double& a){
return complex(real*= a, imag);
}
complex complex:: operator/ (complex& a){
double   r=(((real)*(a.real))+((imag)*(a.imag)))/(pow(a.real,2)+pow(a.imag,2));
double   x=(((a.real)*(imag))-((real)*(a.imag)))/(pow(a.real,2)+pow(a.imag,2));

return complex(r,x);
}
complex complex::operator/= (complex& a){
double   r=(((real)*(a.real))+((imag)*(a.imag)))/(pow(a.real,2)+pow(a.imag,2));
double   x=(((a.real)*(imag))-((real)*(a.imag)))/(pow(a.real,2)+pow(a.imag,2));

return complex(r,x);
}
complex complex:: operator/= (double a){
return complex(real /= a, imag);
}
complex complex::operator/ (double a){
return complex(real / a, imag );
}
void complex::operator= (const complex& a){
real=a.real;
imag=a.imag;
}
//bool operator== (complex&);
bool complex::operator==(complex& a){
if ((real == a.real) && (imag == a.imag))
return true;
else
return false;
}
//bool operator!=(complex &c);
bool complex::operator!=(complex &a){
if ((real != a.real) && (imag != a.imag))
return true;
else
return false;
}

istream& operator >> (istream &in, complex& a){
in >> a.real >> a.imag;
return in;
}


ostream &operator <<(std::ostream& out, const complex& c){
out <<c.real<<\' \'<< c.imag;
return out;
}
complex complex::conj() {
return complex(real,-imag);
}

double complex::norm(){
return sqrt(real*real + imag *imag);
}
double complex::modulus(){
return sqrt(real*real + imag *imag);
}
int main()
{
  
   complex c1(1,2);
  
   complex c2,c3,c4,c5;
   cout <<\"Please Enter values for complex c2: \";
   cin >> c2;
   cout << \"You entered C2: \" << c2<< endl;
   double d=2;
   //c1=c2+d;
   //c1=c2+2;
   c3=c1+c2;
   c4=c1*c2;
   c5=c1/c2;
   //c5/=d;
   //c3/=c2;
  
  
   cout << \"Addition (c1,c2): \"<< c3.real << \" \"<< c3.imag <<\"i\" << endl;
   cout << \"Multiplication(c1,c2): \"<< c4.real << \" \"<< c4.imag <<\"i\" << endl;
   cout << \"Division(c1/c2): \"<< c5.real << \" \"<< c5.imag <<\"i\" << endl;

return 0;

}

For this part of the lab, think about and come up with a possible (doable by you in a reasonable amount of time) projects that involve data structures. Be very
For this part of the lab, think about and come up with a possible (doable by you in a reasonable amount of time) projects that involve data structures. Be very
For this part of the lab, think about and come up with a possible (doable by you in a reasonable amount of time) projects that involve data structures. Be very
For this part of the lab, think about and come up with a possible (doable by you in a reasonable amount of time) projects that involve data structures. Be very

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site