Represent the private data of the class

Assignment Help Computer Engineering
Reference no: EM132157043

Use double variables to represent the private data of the class. Provide a constructor that enables an object of this class to be initialized when it is declared.

The constructor should contain default values in case no initializers are provided. Provide public member functions that perform the following tasks:

a) Adding two Complex numbers: The real parts are added together and the imaginary parts are added together

b) Subtracting two Complex numbers: The real part of the right operand is subtracted from the real part of the left operand and the imaginary part of the right operand is subtracted from the imaginary part of the left operand.

c) Printing Complex numbers in the form (a, b) where a is the real part and b is the imaginary part.

Here are the files used:

header file:complex.h:

#ifndef COMPLEX_H
#define COMPLEX_H

class Complex
{
public: //not sure if these are correct
void printComplex();
void setComplexNumber(double, double);
double add(double);
double subtract(double);

private: //must add the variables

};

#endif

------

complex.cpp:

#include
using namespace std;

#include "Complex.h"

Complex::Complex(double real, double imaginary)
{
setComplexNumber(real, imaginary);
}

Complex Complex::add(const Complex &right)
{ //Write a statement to return a complex object. Add the real part of right to the real part of this Complex object and add the imaginary part of right to the imaginary part of this Complex object.

}

Complex::subtract(const Complex &right)
{//Same as above but with subtraction

}

void Complex::printComplex()
{
cout << '(' << realPart << "," << imaginaryPart << ')';
}

void Complex::setComplexNumber(double rp, double ip)
{
realPart = rp;
imaginaryPart = ip;
}

-------

main : complextest.cpp:

#include
using namespace std;

#include "Complex.h"

int main()
{
Complex a(1, 7), b(9, 2), c;

a.printComplex();
cout << "+";
b.printComplex();
cout << "=";
c = a.add(b);
c.printComplex();

cout << "\n";
a.setComplexNumber(10, 1);
b.setComplexNumber(11, 5);
a.printComplex();
cout << "-";
b.printComplex();
cout << "=";
c = a.subtract(b);
c.printComplex();
cout << endl;
}

Reference no: EM132157043

Questions Cloud

Design an html form to enter a country : Use the database file to design an HTML form to enter a country and the php code loads information about the country and a list of its cities.
Analyze algorithm and show the results in order notation : Use the divide-and-conquer approach to write a recursive algorithm that finds the maximum sum in any contiguous sublist of a given list of n real values.
Create the hash function that produces an n bit hash : Use an encryption function to create a hash function. Assume you have an encryption function of n bits - and you are to construct a hash function of n bits.
Create an informative website : Create an informative website. The site must also include a minimum of two interactive data visualizations.
Represent the private data of the class : Adding two Complex numbers: The real parts are added together and the imaginary parts are added together
Show that the energy expression for the particle in a box : compare these to the energy levels the molecule would have if both walls of the box were infinite.
Annual rate of inflation in the price of bread : If the price of a loaf of bread has tripled over the past 5 years, what has been the annual rate of inflation in the price of bread over that time period?
How much money would be in the account : Assume that you deposit $410 into an account that pays 7 percent per annum. How much money would be in the account 8 years from today?
What is the expected future value : Assume that you have a lump sum $140 that you are investing for 3 years at a nominal rate of 24%. What is the expected Future Value?

Reviews

Write a Review

Computer Engineering Questions & Answers

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd