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

  Implement an intrusion detection system in java

You are to implement an intrusion detection system in java. Calculate a threshold for detecting an intrusion. The threshold is 2*(Sums of weights).

  Write a class that reads a file

In java, write a class that reads a file and outputs a list of the unique words in the file and the number of times each unique word occurs.Hint: use a HashMap with keys being the words and values being integer counts associated with the words.

  Compute area and perimeter of a polygon

Create a project that would let a user compute area and perimeter of a polygon

  Method called wordlengths that accepts a scanner

Write a method called wordLengths that accepts a Scanner representing an input file as its argument. Your method should read from the given file.

  Develop a reservation system program for specific flights.

develop a reservation system program for specific flights. A customer should be able to select from one of four categories of seats on flights from RDU to any of at least three other destinations. Based on the user input of seat type and destination,..

  Inheritancedemo

Create a New Project named InheritanceDemo . 2. Create a new class called Person and cut and paste the Person.java file from Blackboard into the class. Create a new class called Student and cut and paste the Student.java file from Blackboard into the..

  supply a student tester class that tests all methods

Implement a class Student. For the purpose of this exercise, a student has a name and a total quiz score. Supply an appropriate constructor and methods getName( ), addQuiz(int score), getTotalScore( ), and getAverageScore ( ).

  You need to train for 10 weeks

You are preparing for a marathon. In order to prepare, you need to train for 10 weeks, running an increasing number of miles per week, starting at running at least 2 miles your first week up to 26 miles by week 10.

  Develop java code to compute monthly rent for housing units

Develop a java code that computes monthly rent for 3 housing units namely Bungalows,Apartments and hostels. All housing units have got size,color and monthly rental rate.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

  Explain how the loop displaying the menu

Explain how the loop displaying the menu is exited, what value does menuSel have when the program finishes? Describe what happens next when menuSel gets this value.

  Create bean jsp program which will compute simple interest

Create the bean which will compute Simple Interest. Use bean in JSP program. Accept details of saving like principal amount, rate of interest, period-in years from user and show amount

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