SlideShare uma empresa Scribd logo
1 de 6
Baixar para ler offline
Please help! The goal of this project is to write the interface and implementation for the
complex number class. The public interface for the complex number class should provide
the following member functions: constructors - There will be three versions of the
constructor function: THE INSTRUCTIONS ARE BELOW (IN BOLD):
a. Complex() : the default constructor sets both real and imag, pri- vate member variables, to 0.
The default constructor is implemented for you.
b. Complex(double r) : the second constructor sets real to r, the double, and imag to 0.
c. Complex(double r, double i) : the third constructor sets real to r and imag to i.
operators: +, -, / and * will be overloaded as non-member friend functions. For the / operator,
when both the real and imaginary parts of the divisor are 0, an exception occurs. The operator
must throw an integer, -1. The << operator has already been implemented for you. Make sure
you understand how it works. Also, the + non-member operator has been implemented for you.
accessors: implement two accessor member functions:
a. getReal(): this function returns the real part of the complex number. This member function has
been implemented for you.
b. getImag() : this function returns the imaginary part of the complex number.
Other member functions :
a. conjugate() : this member function returns a complex number that is the conjugate of the
object used to invoke it. This function has been implemented for you.
b. modulus() : this member function returns the magnitude of the complex number. The square
root function, sqrt, is defined in the math library.
c. argument() : this member function returns the polar angle of a complex number. Given a
complex number z = x + iy, it returns arctan(y/x). Note the arctan function, atan2(y,x), is already
defined in the math library. However, the function must throw an integer, -2, when an exception
occurs. An exception occurs when both y and x are 0.
Define the function pow(const Complex& z, int n) as a friend function of the Complex class. The
function returns a new complex number equivalent to Zn.
Please complete the below STARTER functions (some variables need to be defined) ALL
BOLDED SECTIONS CORRESPOND WITH ONE ANOTHER:
complex.h:
/**
* public interface for the complex number class.
* File: complex.h
* </pre>
*/
#ifndef COMPLEX_H
#define COMPLEX_H
#include <iostream>
using namespace std;
/* YOUR TASK HERE IS TO GIVE THE COMPLETE DEFINITION OF
THE class Complex. BE SURE TO INCLUDE A DESCRIPTION OF EACH OF THE
FUNCTIONS.
YOU WILL PROVIDE ONLY THE PUBLIC INTERFACE OF THE MEMBER
AND FRIEND FUNCTIONS, NOT THEIR DEFINITIONS.
THE MEMBER AND FRIEND FUNCTIONS WILL BE DEFINED IN THE
IMPLEMENTATION FILE.
DEFINE THE CLASS BELOW.
*/
#endif
complex.cpp:
/**
* Implementation for the complex class
* File: complex.cpp
* </pre>
*/
#include <cmath>
#include <cstdlib>
#include "complex.h"
/* SOME FUNCTION HAVE BEEN IMPLEMENTED. IMPLEMENT
ALL OTHER FUNCTIONS.
*/
Complex::Complex()
{
real = 0.0;
imag = 0.0;
}
double Complex::getReal() const
{
return real;
}
Complex Complex::conjugate() const
{
return Complex(real,-imag);
}
Complex operator +(const Complex& z1, const Complex& z2)
{
return Complex(z1.real+z2.real,z1.imag+z2.imag);
}
ostream& operator<<(ostream& out, const Complex& z)
{
if (z.real == 0 && z.imag == 0)
{
out<<"0";
return out;
}
if (z.real == 0)
{
if (z.imag < 0)
{
if (z.imag != -1)
out<<z.imag<<"i";
else
out<<"-i";
}
else
{
if (z.imag != 1)
out<<z.imag<<"i";
else
out<<"i";
}
return out;
}
if (z.imag == 0)
{
out<<z.real;
return out;
}
out <<z.real;
if (z.imag < 0)
{
if (z.imag != -1)
out<<z.imag<<"i";
else
out<<"-i";
}
else
{
if (z.imag != 1)
out<<"+"<<z.imag<<"i";
else
out<<"+i";
}
return out;
}
completest.cpp
/**
* A program to test the complex class implementation
* <pre>
* File: complextester.cpp
* </pre>
*/
#include <iostream>
#include "complex.h"
#include <cstdlib>
using namespace std;
int main(int argc, char **argv)
{
Complex z0(3.6,4.8);
Complex z1(4,-2);
Complex z2(-4,2);
Complex z3(-4,-3);
Complex z4(3,-4);
Complex z5;
Complex z6;
Complex z7;
double ang;
cout<<"z0 = "<<z0<<" and re(z0) = "<<z0.getReal()<<" and "
<<"im(z0) = "<<z0.getImag()<<"."<<endl;
cout<<"z1 = "<<z1<<endl;
cout<<"z2 = "<<z2<<endl;
cout<<"z3 = "<<z3<<endl;
cout<<"z4 = "<<z4<<endl;
cout<<"z2 x z3 = "<<z2*z3<<endl;
cout<<"z1 + z2 = "<<z1+z2<<endl;
cout<<"z3 = "<<z3<<endl;
cout<<"z4 = "<<z4<<endl;
cout<<"z3-z4 = "<<z3-z4<<endl;
cout<<"((z2+z3)x(z3-z4)) = ";
cout<<(z2+z3)*(z3-z4)<<endl;
cout<<"z1^3 = "<<pow(z1,3)<<endl;
cout<<"1/z2^2 = "<<pow(z2,-2)<<endl;
cout<<"z3^0 = "<<pow(z3,0)<<endl;
try
{
cout<<"((z2+z3)x(z3-z4))/z3 = ";
z6 = ((z2+z3)*(z3-z4))/z3;
cout<<z6<<endl;
cout<<"z3 / z4 = "<<(z3/z4)<<endl;
cout<<"Conj(z4) = "<<z4.conjugate()<<endl;
cout<<"The real part of the conjugate of z4 is "<<(z4.conjugate()).getReal()<<endl;
cout<<"The imaginary part of the conjugate of z4 is "<<(z4.conjugate()).getImag()<<endl;
cout<<"The argument of the conjugate of z4 is "<<(z4.conjugate()).argument()<<"."<<endl;
cout<<"The modulus of the conjugate of z4 is "<<(z4.conjugate()).modulus()<<"."<<endl;
cout<<"(z3*conj(z4))/(z4*conj(z4))= ";
cout<<(z3*z4.conjugate())/(z4*z4.conjugate())<<endl;
/* Add statement here to compute ((z1-z2).(z3/z4))/(z4/z3)
and print the result:*/
ang = (z1+z2).argument();
cout<<"angle = "<<ang<<endl;
/* Put a comment here explaining what happened and why?
*/
}
catch(int e)
{
if (e == -1)
cerr<<"DivideByZero Exception in / operator"<<endl;
else if (e == -2)
cerr<<"DivideByZero Exception in argument function"<<endl;
}
return 0;
}

Mais conteúdo relacionado

Semelhante a Please help! The goal of this project is to write the interface and im.pdf

Introduction to functional programming using Ocaml
Introduction to functional programming using OcamlIntroduction to functional programming using Ocaml
Introduction to functional programming using Ocamlpramode_ce
 
Help in JAVAThis program should input numerator and denominator f.pdf
Help in JAVAThis program should input numerator and denominator f.pdfHelp in JAVAThis program should input numerator and denominator f.pdf
Help in JAVAThis program should input numerator and denominator f.pdfmanjan6
 
C++ Programming - 11th Study
C++ Programming - 11th StudyC++ Programming - 11th Study
C++ Programming - 11th StudyChris Ohk
 
Stdlib functions lesson
Stdlib functions lessonStdlib functions lesson
Stdlib functions lessonteach4uin
 
User defined functions
User defined functionsUser defined functions
User defined functionsshubham_jangid
 
Java 8 lambda expressions
Java 8 lambda expressionsJava 8 lambda expressions
Java 8 lambda expressionsLogan Chien
 
write the To Dos to get the exact outputNOte A valid Fraction .pdf
write the To Dos to get the exact outputNOte A valid Fraction .pdfwrite the To Dos to get the exact outputNOte A valid Fraction .pdf
write the To Dos to get the exact outputNOte A valid Fraction .pdfjyothimuppasani1
 
Chapter 7 functions (c)
Chapter 7 functions (c)Chapter 7 functions (c)
Chapter 7 functions (c)hhliu
 
C++ AssignmentPlease read all the requirements and the overloading.pdf
C++ AssignmentPlease read all the requirements and the overloading.pdfC++ AssignmentPlease read all the requirements and the overloading.pdf
C++ AssignmentPlease read all the requirements and the overloading.pdflakshmijewellery
 
C++20 the small things - Timur Doumler
C++20 the small things - Timur DoumlerC++20 the small things - Timur Doumler
C++20 the small things - Timur Doumlercorehard_by
 
PROGRAM 2 – Fraction Class Problem For this programming as.pdf
PROGRAM 2 – Fraction Class Problem For this programming as.pdfPROGRAM 2 – Fraction Class Problem For this programming as.pdf
PROGRAM 2 – Fraction Class Problem For this programming as.pdfezonesolutions
 
C++ Function
C++ FunctionC++ Function
C++ FunctionHajar
 
C++ Course - Lesson 2
C++ Course - Lesson 2C++ Course - Lesson 2
C++ Course - Lesson 2Mohamed Ahmed
 

Semelhante a Please help! The goal of this project is to write the interface and im.pdf (20)

Introduction to functional programming using Ocaml
Introduction to functional programming using OcamlIntroduction to functional programming using Ocaml
Introduction to functional programming using Ocaml
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
 
Help in JAVAThis program should input numerator and denominator f.pdf
Help in JAVAThis program should input numerator and denominator f.pdfHelp in JAVAThis program should input numerator and denominator f.pdf
Help in JAVAThis program should input numerator and denominator f.pdf
 
Lecture5
Lecture5Lecture5
Lecture5
 
C++ Programming - 11th Study
C++ Programming - 11th StudyC++ Programming - 11th Study
C++ Programming - 11th Study
 
Stdlib functions lesson
Stdlib functions lessonStdlib functions lesson
Stdlib functions lesson
 
User defined functions
User defined functionsUser defined functions
User defined functions
 
Functions12
Functions12Functions12
Functions12
 
Functions123
Functions123 Functions123
Functions123
 
Overloading
OverloadingOverloading
Overloading
 
Java 8 lambda expressions
Java 8 lambda expressionsJava 8 lambda expressions
Java 8 lambda expressions
 
write the To Dos to get the exact outputNOte A valid Fraction .pdf
write the To Dos to get the exact outputNOte A valid Fraction .pdfwrite the To Dos to get the exact outputNOte A valid Fraction .pdf
write the To Dos to get the exact outputNOte A valid Fraction .pdf
 
Chapter 7 functions (c)
Chapter 7 functions (c)Chapter 7 functions (c)
Chapter 7 functions (c)
 
C++ AssignmentPlease read all the requirements and the overloading.pdf
C++ AssignmentPlease read all the requirements and the overloading.pdfC++ AssignmentPlease read all the requirements and the overloading.pdf
C++ AssignmentPlease read all the requirements and the overloading.pdf
 
C++20 the small things - Timur Doumler
C++20 the small things - Timur DoumlerC++20 the small things - Timur Doumler
C++20 the small things - Timur Doumler
 
Computer Network Assignment Help
Computer Network Assignment HelpComputer Network Assignment Help
Computer Network Assignment Help
 
PROGRAM 2 – Fraction Class Problem For this programming as.pdf
PROGRAM 2 – Fraction Class Problem For this programming as.pdfPROGRAM 2 – Fraction Class Problem For this programming as.pdf
PROGRAM 2 – Fraction Class Problem For this programming as.pdf
 
C++ Function
C++ FunctionC++ Function
C++ Function
 
C++ Homework Help
C++ Homework HelpC++ Homework Help
C++ Homework Help
 
C++ Course - Lesson 2
C++ Course - Lesson 2C++ Course - Lesson 2
C++ Course - Lesson 2
 

Mais de RyanF2PLeev

Please help me answer these questions below- 1- This organism is in th.pdf
Please help me answer these questions below- 1- This organism is in th.pdfPlease help me answer these questions below- 1- This organism is in th.pdf
Please help me answer these questions below- 1- This organism is in th.pdfRyanF2PLeev
 
please help and explain thoroughly and show work- Thank you! 1- (.pdf
please help and explain thoroughly and show work- Thank you!      1- (.pdfplease help and explain thoroughly and show work- Thank you!      1- (.pdf
please help and explain thoroughly and show work- Thank you! 1- (.pdfRyanF2PLeev
 
Please give me a heads up on- Communications and Servicing The Client.pdf
Please give me a heads up on- Communications and Servicing The Client.pdfPlease give me a heads up on- Communications and Servicing The Client.pdf
Please give me a heads up on- Communications and Servicing The Client.pdfRyanF2PLeev
 
Population Mean formula is provided below- Identify - match the variab.pdf
Population Mean formula is provided below- Identify - match the variab.pdfPopulation Mean formula is provided below- Identify - match the variab.pdf
Population Mean formula is provided below- Identify - match the variab.pdfRyanF2PLeev
 
Portfolio invested in stock- Portfolio invested in bond- Expected Retu.pdf
Portfolio invested in stock- Portfolio invested in bond- Expected Retu.pdfPortfolio invested in stock- Portfolio invested in bond- Expected Retu.pdf
Portfolio invested in stock- Portfolio invested in bond- Expected Retu.pdfRyanF2PLeev
 
Points X-Y- and Z are locations on the topographic map bellow- Elevati.pdf
Points X-Y- and Z are locations on the topographic map bellow- Elevati.pdfPoints X-Y- and Z are locations on the topographic map bellow- Elevati.pdf
Points X-Y- and Z are locations on the topographic map bellow- Elevati.pdfRyanF2PLeev
 
Plot the frequency of p in this population- Make sure you plot the fre.pdf
Plot the frequency of p in this population- Make sure you plot the fre.pdfPlot the frequency of p in this population- Make sure you plot the fre.pdf
Plot the frequency of p in this population- Make sure you plot the fre.pdfRyanF2PLeev
 
Please help me with this from the Dental assistant class 112 Chart D.pdf
Please help me with this from the Dental assistant class 112   Chart D.pdfPlease help me with this from the Dental assistant class 112   Chart D.pdf
Please help me with this from the Dental assistant class 112 Chart D.pdfRyanF2PLeev
 
Please help me with this question! 7-3 Another attacker Mallory interc.pdf
Please help me with this question! 7-3 Another attacker Mallory interc.pdfPlease help me with this question! 7-3 Another attacker Mallory interc.pdf
Please help me with this question! 7-3 Another attacker Mallory interc.pdfRyanF2PLeev
 
please show your work -) T-Scores the question is referring to- 3- A.pdf
please show your work -)  T-Scores the question is referring to- 3- A.pdfplease show your work -)  T-Scores the question is referring to- 3- A.pdf
please show your work -) T-Scores the question is referring to- 3- A.pdfRyanF2PLeev
 
Please explain how you reached the answer if applicable- 1- Find the.pdf
Please explain how you reached the answer if applicable-  1- Find the.pdfPlease explain how you reached the answer if applicable-  1- Find the.pdf
Please explain how you reached the answer if applicable- 1- Find the.pdfRyanF2PLeev
 
Please review the guide by CoinTelegraph 1) Come up with an idea- thin.pdf
Please review the guide by CoinTelegraph 1) Come up with an idea- thin.pdfPlease review the guide by CoinTelegraph 1) Come up with an idea- thin.pdf
Please review the guide by CoinTelegraph 1) Come up with an idea- thin.pdfRyanF2PLeev
 
Please provide the code and the explanation for Question 1-1 and 1-2-.pdf
Please provide the code and the explanation for Question 1-1 and 1-2-.pdfPlease provide the code and the explanation for Question 1-1 and 1-2-.pdf
Please provide the code and the explanation for Question 1-1 and 1-2-.pdfRyanF2PLeev
 
Please provide a new answer- Do not copy and paste a response- Thank y.pdf
Please provide a new answer- Do not copy and paste a response- Thank y.pdfPlease provide a new answer- Do not copy and paste a response- Thank y.pdf
Please provide a new answer- Do not copy and paste a response- Thank y.pdfRyanF2PLeev
 
Please identify the type of protein complex that will be recruited to.pdf
Please identify the type of protein complex that will be recruited to.pdfPlease identify the type of protein complex that will be recruited to.pdf
Please identify the type of protein complex that will be recruited to.pdfRyanF2PLeev
 
Please help me with this question! 6- Certificates and PKI- (10 points.pdf
Please help me with this question! 6- Certificates and PKI- (10 points.pdfPlease help me with this question! 6- Certificates and PKI- (10 points.pdf
Please help me with this question! 6- Certificates and PKI- (10 points.pdfRyanF2PLeev
 
Please help me with this question! 7- Kerberos- (15 points) The EECS D.pdf
Please help me with this question! 7- Kerberos- (15 points) The EECS D.pdfPlease help me with this question! 7- Kerberos- (15 points) The EECS D.pdf
Please help me with this question! 7- Kerberos- (15 points) The EECS D.pdfRyanF2PLeev
 
Java Circle-java -Make the 'color' attribute private -Make a constr.pdf
Java  Circle-java   -Make the 'color' attribute private -Make a constr.pdfJava  Circle-java   -Make the 'color' attribute private -Make a constr.pdf
Java Circle-java -Make the 'color' attribute private -Make a constr.pdfRyanF2PLeev
 
Jeters Company uses a periodic inventory system and reports the follow.pdf
Jeters Company uses a periodic inventory system and reports the follow.pdfJeters Company uses a periodic inventory system and reports the follow.pdf
Jeters Company uses a periodic inventory system and reports the follow.pdfRyanF2PLeev
 
Jill Perry invested $10-000 for a 5- interest in a limited partnership.pdf
Jill Perry invested $10-000 for a 5- interest in a limited partnership.pdfJill Perry invested $10-000 for a 5- interest in a limited partnership.pdf
Jill Perry invested $10-000 for a 5- interest in a limited partnership.pdfRyanF2PLeev
 

Mais de RyanF2PLeev (20)

Please help me answer these questions below- 1- This organism is in th.pdf
Please help me answer these questions below- 1- This organism is in th.pdfPlease help me answer these questions below- 1- This organism is in th.pdf
Please help me answer these questions below- 1- This organism is in th.pdf
 
please help and explain thoroughly and show work- Thank you! 1- (.pdf
please help and explain thoroughly and show work- Thank you!      1- (.pdfplease help and explain thoroughly and show work- Thank you!      1- (.pdf
please help and explain thoroughly and show work- Thank you! 1- (.pdf
 
Please give me a heads up on- Communications and Servicing The Client.pdf
Please give me a heads up on- Communications and Servicing The Client.pdfPlease give me a heads up on- Communications and Servicing The Client.pdf
Please give me a heads up on- Communications and Servicing The Client.pdf
 
Population Mean formula is provided below- Identify - match the variab.pdf
Population Mean formula is provided below- Identify - match the variab.pdfPopulation Mean formula is provided below- Identify - match the variab.pdf
Population Mean formula is provided below- Identify - match the variab.pdf
 
Portfolio invested in stock- Portfolio invested in bond- Expected Retu.pdf
Portfolio invested in stock- Portfolio invested in bond- Expected Retu.pdfPortfolio invested in stock- Portfolio invested in bond- Expected Retu.pdf
Portfolio invested in stock- Portfolio invested in bond- Expected Retu.pdf
 
Points X-Y- and Z are locations on the topographic map bellow- Elevati.pdf
Points X-Y- and Z are locations on the topographic map bellow- Elevati.pdfPoints X-Y- and Z are locations on the topographic map bellow- Elevati.pdf
Points X-Y- and Z are locations on the topographic map bellow- Elevati.pdf
 
Plot the frequency of p in this population- Make sure you plot the fre.pdf
Plot the frequency of p in this population- Make sure you plot the fre.pdfPlot the frequency of p in this population- Make sure you plot the fre.pdf
Plot the frequency of p in this population- Make sure you plot the fre.pdf
 
Please help me with this from the Dental assistant class 112 Chart D.pdf
Please help me with this from the Dental assistant class 112   Chart D.pdfPlease help me with this from the Dental assistant class 112   Chart D.pdf
Please help me with this from the Dental assistant class 112 Chart D.pdf
 
Please help me with this question! 7-3 Another attacker Mallory interc.pdf
Please help me with this question! 7-3 Another attacker Mallory interc.pdfPlease help me with this question! 7-3 Another attacker Mallory interc.pdf
Please help me with this question! 7-3 Another attacker Mallory interc.pdf
 
please show your work -) T-Scores the question is referring to- 3- A.pdf
please show your work -)  T-Scores the question is referring to- 3- A.pdfplease show your work -)  T-Scores the question is referring to- 3- A.pdf
please show your work -) T-Scores the question is referring to- 3- A.pdf
 
Please explain how you reached the answer if applicable- 1- Find the.pdf
Please explain how you reached the answer if applicable-  1- Find the.pdfPlease explain how you reached the answer if applicable-  1- Find the.pdf
Please explain how you reached the answer if applicable- 1- Find the.pdf
 
Please review the guide by CoinTelegraph 1) Come up with an idea- thin.pdf
Please review the guide by CoinTelegraph 1) Come up with an idea- thin.pdfPlease review the guide by CoinTelegraph 1) Come up with an idea- thin.pdf
Please review the guide by CoinTelegraph 1) Come up with an idea- thin.pdf
 
Please provide the code and the explanation for Question 1-1 and 1-2-.pdf
Please provide the code and the explanation for Question 1-1 and 1-2-.pdfPlease provide the code and the explanation for Question 1-1 and 1-2-.pdf
Please provide the code and the explanation for Question 1-1 and 1-2-.pdf
 
Please provide a new answer- Do not copy and paste a response- Thank y.pdf
Please provide a new answer- Do not copy and paste a response- Thank y.pdfPlease provide a new answer- Do not copy and paste a response- Thank y.pdf
Please provide a new answer- Do not copy and paste a response- Thank y.pdf
 
Please identify the type of protein complex that will be recruited to.pdf
Please identify the type of protein complex that will be recruited to.pdfPlease identify the type of protein complex that will be recruited to.pdf
Please identify the type of protein complex that will be recruited to.pdf
 
Please help me with this question! 6- Certificates and PKI- (10 points.pdf
Please help me with this question! 6- Certificates and PKI- (10 points.pdfPlease help me with this question! 6- Certificates and PKI- (10 points.pdf
Please help me with this question! 6- Certificates and PKI- (10 points.pdf
 
Please help me with this question! 7- Kerberos- (15 points) The EECS D.pdf
Please help me with this question! 7- Kerberos- (15 points) The EECS D.pdfPlease help me with this question! 7- Kerberos- (15 points) The EECS D.pdf
Please help me with this question! 7- Kerberos- (15 points) The EECS D.pdf
 
Java Circle-java -Make the 'color' attribute private -Make a constr.pdf
Java  Circle-java   -Make the 'color' attribute private -Make a constr.pdfJava  Circle-java   -Make the 'color' attribute private -Make a constr.pdf
Java Circle-java -Make the 'color' attribute private -Make a constr.pdf
 
Jeters Company uses a periodic inventory system and reports the follow.pdf
Jeters Company uses a periodic inventory system and reports the follow.pdfJeters Company uses a periodic inventory system and reports the follow.pdf
Jeters Company uses a periodic inventory system and reports the follow.pdf
 
Jill Perry invested $10-000 for a 5- interest in a limited partnership.pdf
Jill Perry invested $10-000 for a 5- interest in a limited partnership.pdfJill Perry invested $10-000 for a 5- interest in a limited partnership.pdf
Jill Perry invested $10-000 for a 5- interest in a limited partnership.pdf
 

Último

Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 

Último (20)

Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 

Please help! The goal of this project is to write the interface and im.pdf

  • 1. Please help! The goal of this project is to write the interface and implementation for the complex number class. The public interface for the complex number class should provide the following member functions: constructors - There will be three versions of the constructor function: THE INSTRUCTIONS ARE BELOW (IN BOLD): a. Complex() : the default constructor sets both real and imag, pri- vate member variables, to 0. The default constructor is implemented for you. b. Complex(double r) : the second constructor sets real to r, the double, and imag to 0. c. Complex(double r, double i) : the third constructor sets real to r and imag to i. operators: +, -, / and * will be overloaded as non-member friend functions. For the / operator, when both the real and imaginary parts of the divisor are 0, an exception occurs. The operator must throw an integer, -1. The << operator has already been implemented for you. Make sure you understand how it works. Also, the + non-member operator has been implemented for you. accessors: implement two accessor member functions: a. getReal(): this function returns the real part of the complex number. This member function has been implemented for you. b. getImag() : this function returns the imaginary part of the complex number. Other member functions : a. conjugate() : this member function returns a complex number that is the conjugate of the object used to invoke it. This function has been implemented for you. b. modulus() : this member function returns the magnitude of the complex number. The square root function, sqrt, is defined in the math library. c. argument() : this member function returns the polar angle of a complex number. Given a complex number z = x + iy, it returns arctan(y/x). Note the arctan function, atan2(y,x), is already defined in the math library. However, the function must throw an integer, -2, when an exception occurs. An exception occurs when both y and x are 0. Define the function pow(const Complex& z, int n) as a friend function of the Complex class. The function returns a new complex number equivalent to Zn. Please complete the below STARTER functions (some variables need to be defined) ALL BOLDED SECTIONS CORRESPOND WITH ONE ANOTHER: complex.h: /** * public interface for the complex number class.
  • 2. * File: complex.h * </pre> */ #ifndef COMPLEX_H #define COMPLEX_H #include <iostream> using namespace std; /* YOUR TASK HERE IS TO GIVE THE COMPLETE DEFINITION OF THE class Complex. BE SURE TO INCLUDE A DESCRIPTION OF EACH OF THE FUNCTIONS. YOU WILL PROVIDE ONLY THE PUBLIC INTERFACE OF THE MEMBER AND FRIEND FUNCTIONS, NOT THEIR DEFINITIONS. THE MEMBER AND FRIEND FUNCTIONS WILL BE DEFINED IN THE IMPLEMENTATION FILE. DEFINE THE CLASS BELOW. */ #endif complex.cpp: /** * Implementation for the complex class * File: complex.cpp * </pre> */ #include <cmath> #include <cstdlib> #include "complex.h" /* SOME FUNCTION HAVE BEEN IMPLEMENTED. IMPLEMENT ALL OTHER FUNCTIONS. */ Complex::Complex() { real = 0.0; imag = 0.0; } double Complex::getReal() const {
  • 3. return real; } Complex Complex::conjugate() const { return Complex(real,-imag); } Complex operator +(const Complex& z1, const Complex& z2) { return Complex(z1.real+z2.real,z1.imag+z2.imag); } ostream& operator<<(ostream& out, const Complex& z) { if (z.real == 0 && z.imag == 0) { out<<"0"; return out; } if (z.real == 0) { if (z.imag < 0) { if (z.imag != -1) out<<z.imag<<"i"; else out<<"-i"; } else { if (z.imag != 1) out<<z.imag<<"i"; else out<<"i"; } return out; } if (z.imag == 0) { out<<z.real; return out; } out <<z.real; if (z.imag < 0) { if (z.imag != -1) out<<z.imag<<"i";
  • 4. else out<<"-i"; } else { if (z.imag != 1) out<<"+"<<z.imag<<"i"; else out<<"+i"; } return out; } completest.cpp /** * A program to test the complex class implementation * <pre> * File: complextester.cpp * </pre> */ #include <iostream> #include "complex.h" #include <cstdlib> using namespace std; int main(int argc, char **argv) { Complex z0(3.6,4.8); Complex z1(4,-2); Complex z2(-4,2); Complex z3(-4,-3); Complex z4(3,-4); Complex z5; Complex z6; Complex z7; double ang; cout<<"z0 = "<<z0<<" and re(z0) = "<<z0.getReal()<<" and " <<"im(z0) = "<<z0.getImag()<<"."<<endl; cout<<"z1 = "<<z1<<endl; cout<<"z2 = "<<z2<<endl; cout<<"z3 = "<<z3<<endl; cout<<"z4 = "<<z4<<endl;
  • 5. cout<<"z2 x z3 = "<<z2*z3<<endl; cout<<"z1 + z2 = "<<z1+z2<<endl; cout<<"z3 = "<<z3<<endl; cout<<"z4 = "<<z4<<endl; cout<<"z3-z4 = "<<z3-z4<<endl; cout<<"((z2+z3)x(z3-z4)) = "; cout<<(z2+z3)*(z3-z4)<<endl; cout<<"z1^3 = "<<pow(z1,3)<<endl; cout<<"1/z2^2 = "<<pow(z2,-2)<<endl; cout<<"z3^0 = "<<pow(z3,0)<<endl; try { cout<<"((z2+z3)x(z3-z4))/z3 = "; z6 = ((z2+z3)*(z3-z4))/z3; cout<<z6<<endl; cout<<"z3 / z4 = "<<(z3/z4)<<endl; cout<<"Conj(z4) = "<<z4.conjugate()<<endl; cout<<"The real part of the conjugate of z4 is "<<(z4.conjugate()).getReal()<<endl; cout<<"The imaginary part of the conjugate of z4 is "<<(z4.conjugate()).getImag()<<endl; cout<<"The argument of the conjugate of z4 is "<<(z4.conjugate()).argument()<<"."<<endl; cout<<"The modulus of the conjugate of z4 is "<<(z4.conjugate()).modulus()<<"."<<endl; cout<<"(z3*conj(z4))/(z4*conj(z4))= "; cout<<(z3*z4.conjugate())/(z4*z4.conjugate())<<endl; /* Add statement here to compute ((z1-z2).(z3/z4))/(z4/z3) and print the result:*/ ang = (z1+z2).argument(); cout<<"angle = "<<ang<<endl; /* Put a comment here explaining what happened and why? */ } catch(int e) { if (e == -1) cerr<<"DivideByZero Exception in / operator"<<endl; else if (e == -2) cerr<<"DivideByZero Exception in argument function"<<endl;