Study the code and implement the operator overloading

Assignment Help JAVA Programming
Reference no: EM13163959

 The Table Q3 on the next page is the code of a class named Circle. Study the code and implement the operator overloading for these relational operators (<, <=, ==, !=, >, >=) for the Circle class. Then, write a test program that creates two instances of the Circle class and compare these two instances using the operators (<, <=, ==, !=, >, >=) overloaded for the Circle class.

More specifically, you should develop the following files as the answer for this question.

(1) Revising the Circle class by adding a set of functions implementing operator overloading. That is, the updated class should include:

A revised header file

It should have the definitions of the following new functions:

  • For each relational operator listed above, the prototype of the corresponding operator function.
  • Any new additional variables and/or the prototypes of helper functions.

The definition of each function prototype and variable listed in Table Q3 must be included in this revised header file as well.

For each operator function you added to the header file, specifying its interface, including:

  • Begins with a short description of the module.
  • Purpose - the purpose of the function
  • Parameters(s) - the parameters of the function
  • Precondition(s) - statements about the parameters or the internal state of the module that are assumed to be true (must be true for the function to work correctly)
  • Return - the return value of the function
  • Side Effect - any effect produced by this function that is not described by the return vale

For each new variable in the header file, an inline comment must be provided to explain the purpose of the variable prior to its definition.

A revised C++ program

It should contain the implementation of each new function defined in the header file. The definition of each function listed in Table Q3 must be included in this revised C++ program as well.

(2) A C++ test program

A C++ test program that is used to test the performance of the C++ class you have developed. Its working procedure can be:

  • Create two instances of the Circle class.
  • Compare two instances using each operator function defined in your class
  • Once a comparison is finished, show the result to the user. For example, telling the user if two instances are equal.

Each function in your test program, specifying its interface, including:

  • Begins with a short description of the module.
  • Purpose - the purpose of the function
  • Parameters(s) - the parameters of the function
  • Precondition(s) - statements about the parameters or the internal state of the module that are assumed to be true (must be true for the function to work correctly)
  • Return - the return value of the function
  • Side Effect - any effect produced by this function that is not described by the return vale

For each variable in your test program, an inline comment must be provided to explain the purpose of the variable prior to its definition. 4

Circle Class

//CircleWithConstantMemberFunctions.h

#ifndef CIRCLE_H

#define CIRCLE_H

class Circle

{

public:

Circle();

Circle(double);

double getArea() const;

double getRadius() const;

void setRadius(double);

static int getNumberOfObjects();

private:

double radius;

static int numberOfObjects;

};

#endif

//CircleWithConstantMemberFunctions.cpp

#include "CircleWithConstantMemberFunctions.h"

int Circle::numberOfObjects = 0;

// Construct a circle object

Circle::Circle()

{

radius = 1;

numberOfObjects++;

}

// Construct a circle object

Circle::Circle(double newRadius)

{

radius = newRadius;

numberOfObjects++;

}

// Return the area of this circle

double Circle::getArea() const

{

return radius * radius * 3.14159;

}

// Return the radius of this circle

double Circle::getRadius() const

{

return radius;

}

// Set a new radius

void Circle::setRadius(double newRadius)

{

radius = (newRadius >= 0) ? newRadius : 0;

}

// Return the number of circle objects

int Circle::getNumberOfObjects()

{

return numberOfObjects;

}

 

 

Reference no: EM13163959

Questions Cloud

How many grams of octane were in the sample : A testing facility found that 8.35*10^23 molecules of carbon dioxide were produced when a sample of octane was burned in air. If this combustion process is known to produce an 86.7% yield, how many grams of octane were in the sample?
Calculate the expected ph of the buffer solutions : Given that the pKa for Acetic Acid is 4.77, calculate the expected pH of the buffer solutions using the Henderson-Hasselbalch equation and the concentrations of Acetic Acid and Acetate added to the 250 ml Erlenmeyer flask.
State what is the surrounding : What is the system? What is the surrounding? In what direction does the heat flow? Is the process endothermic or exothermic?
What is the composition of the mixture by volume : A gas mixture composed of helium and argon has a density of 0.605g/L at a 741mmHg and 298K .What is the composition of the mixture by volume?
Study the code and implement the operator overloading : The Table Q3 on the next page is the code of a class named Circle. Study the code and implement the operator overloading for these relational operators ( , >=) for the Circle class. Then, write a test program that creates two instances of the Circle ..
If the number on two of the players'' four cards : If the number on two of the players' four cards is the same and the number on the remaining two cards is also the same yet the number on all four cards in not the same then the player gets their bet back and in addition wins 22 chips for each chip th..
Calculate the concentration of iron in a dilutedsolution : Calculate the concentration (molarity) of iron in a dilutedsolution if 5.00 mL of 5.0x10^-4 M Fe(NH4)2(SO4)2 6H2O isdiluted with water to 100.0 mL.
Calculate the equilibrium constant of reversible reaction : When one mole of hydrogen iodide(HI) is stored in a 1-liter container at 444 oC, 22 % of HI wil be dissociated at equilibirum. Calculate the equilibrium constant of the reversible reaction of hydrogen iodide (HI)at 444 oC.
State acidity has affected many lakes in northern europe : This acidity has affected many lakes in northern Europe, the northern United States, and Canada, reducing fish populations and affecting other parts of the ecological network within the lakes and surrounding forests

Reviews

Write a Review

JAVA Programming Questions & Answers

  Productexception class whose constructor

Create a ProductException class whose constructor receives a String that consists of a product number and price. Save the file as ProductException.java. Create a Product class with two fields, productNum and price. The Product constructor requires va..

  Java program for line item application

This exercise explains you the process of testing and enhancing Line Item application. Open LineItemApp, Validator, Product, LineItem, and ProductDB classes that are in the c:java1.6ch06LineItem directory and review this code.

  Develop a reliable transfer protocol over udp

Develop a reliable transfer protocol over UDP. Focus on a Stop- and-Wait protocol.

  Determine product a inferior or normal good

Research illustrates that prices of related goods are given by Py = $5,900 and ; Pz = $90, while average income of individuals consuming this product is M = $55,000. Is X inferior or normal good?

  Method to calculate all primes in the range [2..n]

One commonly used method to calculate all primes in the range [2..n] is to start with the number 2, mark it as prime, and mark all its multiples (excluding itself) as not prime. Then, we find the next smallest unmarked number, mark it as prime, and m..

  Represent one book in java

Represent one book in java

  Executing stringed musical instrument class

Create and execute a stringed musical instrument class.

  Difference between the two following statements

What exactly is the difference between the two following statements and which is preferred, please provide details: 1) frame.setSize(400, 300); // Set JFrame Size

  Write function in javascript to compute person-s gross pay

Write the function using JavaScript syntax to compute a person's gross pay for a week. The function should receive the number of hours worked and the rate of pay per hour.

  Design a java program that simulates a slot machine

Design a java program that simulates a slot machine. When the program runs, it should do the following: Ask the user to enter the amount of money he or she wants to insert into the slot machine. ? Instead of displaying images, the program will random..

  Compute the temperature in centigrade

Compute the temperature in Centigrade - Display the temperatures in both Centrigrade and Fahrenheit with appropriate labels, using the + operator to concatenate the labels with the variables

  Using a linked implementation of graph write a method

Write a method that takes two nodes as input and returns true if joining an edge between these two nodes, forms a duplicate path to one of the input nodes within the graph.

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