Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

12.24 HW2: Practice with Classes Objectives: Become familiar with developing a C++ class, to include developing: A constructor An multiplication operator A friend function (input

12.24 HW2: Practice with Classes

Objectives:

  • Become familiar with developing a C++ class, to include developing:
    • A constructor
    • An multiplication operator
    • A friend function (input operator)
  • Introduce various C and C++ functions for parsing user input

Assignment Details

This assignment consists of 6 parts.

Part 1: Using an IDE of your own choosing (Visual Studio is recommended), create a new project and copy the starter code

  • ComplexNumber.h
  • ComplexNumber.cpp and
  • TestComplexNumber.cpp

to this new project for developing and testing your solution.

Part 2: Complete the specification in ComplexNumber.h by adding function prototypes for:

  • A ComplexNumber constructor which takes as a parameter a single C-sytle string (i.e., const char *)

  • A multiplication operator as a member function which takes as a parameter a single constant reference to a ComplexNumber and returns a ComplexNumber

  • An input operator as a friend function which takes two input parameters

    • A reference to an istream and
    • A reference to a ComplexNumber and

    Initializes the ComplexNumber to value given in the istream and returns the modified istream

Part 3: Write implementations for the three new functions specified in Part 2. Your functions should adhere to the following requirements:

  • Your constructor initializes a ComplexNumber object using a C-string with one of the following forms:
    1. [+|-]realNumber
    2. [+|-][realNumber]i
    3. [+|-]realNumber(+|-)[realNumber]i
    • Please note:
      • | stands for OR,
      • [] stands for OPTIONALLY,
      • () stands for EITHER, and
      • realNumber stands for any valid real number literal, including numbers in signed or unsigned scientific notation.
    • For full credit your constructor must be able to read complex numbers matching any of the three forms.
    • For simplicity, your solution is not required to reject ill-formed complex numbers (i.e., numbers which do not match the specification above)
  • Your multiplication operator must be a member function using * as the operator and correctly multiply the this object and the ComplexNumber parameter and return the resulting ComplexNumber according to the definition for ComplexNumber multiplication from Wolfram.
  • Your input operator must be a friend function using >> as the operator and allow initialization of the ComplexNumber parameter using the input stream (e.g., typically cin).

These three functions are the only new functions you are required to add to ComplexNumber.cpp. While it is not necessary, you may add as many additional non-member or non-friend functions as you want to complete your solution.

Part 4: Test your implementations from Parts 2 and 3 using TestComplexNumber.cpp and various valid complex numbers.

Example Inputs and Results:

 Testing the string constructor with "1.23e-1+4.5i" results in the value 0.123+4.5i 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application Development And Administration

Authors: Mannino Michael

5th Edition

0983332401, 978-0983332404

More Books

Students also viewed these Databases questions

Question

Develop a program for effectively managing diversity. page 303

Answered: 1 week ago

Question

List the common methods used in selecting human resources. page 239

Answered: 1 week ago