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

  How many pieces of candy was just sold and what type

A good friend of yours is managing a fund raiser for a football team. He needs a program to calculate the total amount of candy sold at a football game.

  What do the different colors mean in the wireshark log

This is a flexible and powerful tool. Any network administrator worth his or her salt will know how to run Wireshark. Most professionals use it often.

  What do you consider to be major risks to your environment

What do you consider to be the major risks to your environment and why? Describe the risks and vulnerabilities involved in the above stated environment.

  Write a function that inputs a square picture

Write a function that inputs a square picture and an input color, and draws a diagonal line from upper-left to lower-right using the input color for line color.

  How would you implement the different types of glass

You are the Executive Safety Officer (ESO) and was tasked to ensure that the facility is secure. In this assignment discuss.

  Implement a dynamic array

In this assignment, you will implement a dynamic array. Dynamic arrays provide all the advantages of static arrays--random access, sequential access, compactness-plus the capability to change size

  Write down a program using the vector class

create a program using vector class that allows the user to input the number of days worked in a 7 day workweek and, using a fixed hourly rate, calculates the weeks wages and the average number of hours worked per day.

  Calculate manually the limits and tolerance zones

Calculate manually the limits and tolerance zones for the following fits: Clearance fit of RC5 for a basic size of 5.0000 in.

  Determine the rate of heat loss from the absorber plate

Flat-plate solar collectors are often tilted up toward the sun in order to intercept a greater amount of direct solar radiation.

  Kind of the collapsible furniture

An inventor has just developed a new kind of the collapsible furniture which will be useful for the students in college dorms where space is limited.

  A variety of both technical and business skill sets

An effective project manager wants a variety of both technical and business skill sets. recognize the nontechnical skills that have been associated with superior project management.

  What is minimum sdk meaning in program

Can "Wear Minimum SDK" API version be smaller than that of "Phone and Tablet Minimum SDK" ?

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