首页 > > 详细

program课程作业代做、代写C++课程设计作业、代做data留学生作业、c++程序语言作业调试代做留学生Processing|代做R语言编程

Computer Science 181
Project 2 – A Complex Number Calculator

Write a C++ class that can be used to represent complex numbers, and that overloads several operations. Then, write a main program that uses your class to implement a simple complex number calculator.

Recall from elementary algebra that a complex number is a number of the form , where and are real numbers, and .
Your complex class should represent the real and imaginary parts of the number as double instance variables. Give the class a single constructor that takes the values of the real and imaginary parts as parameters. Use default parameter values to 0.0 for both. Do not provide any getters or setters for the instance variables.

Overload the following binary operations on Complex objects: +, -, *, /, ==. In addition, your class should overload the insertion and extraction operators << and >> so that Complex objects can be both read from the user and printed to the screen.

When overloading the << operator, your overloaded function should print the Complex number in the form a,b. When overloading the >> operator, you should assume that the user enters the complex number using the same form a,b. Note that there is no space between the real and imaginary parts and the comma in either the input or the output.

When you are overloading the == operator, recall that double values cannot be compared exactly in the computer. Consider two doubles and to be equal if .

After you have writen your Complex class, write a main program that operates as a simple calculator on complex numbers. When executed, your calculator should read a single complex number, a char representing one of the arithmetic operations, and a second complex number from the user, and then print out the result. Your program should use only the operators << and >> for IO.

The calculator must check to make sure it is not asked to perform division by zero. A complex number is equal to zero when both the real and imaginary parts are zero. Use the == operator to test for this in the main program before performing the division.

Here is an example of what your program must look like when it is executed. User input is shown in bold.

Enter a complex number problem: 1.0,-2.5 – 1.0,3.14
Result: 0,-5.64

What to turn in: When you are ready to submit your program, upload all three files to blackboard.

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp2
热点文章
程序代写更多图片

联系我们 - QQ: 99515681 微信:codinghelp2
© 2014 www.7daixie.com
程序代写网!