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

  Distributed systems

Build robust, secure distributed systems using advanced programming techniques

  Design an object-oriented java application

You are to design an object-oriented Java application to let the user play a dice game that uses two dices. The player bets on a value and the dices roll

  Display student details and classes in applet

Display student details and classes they have enrolled in Applet. The Applet should have following features. Update and View.

  Programming exercises

Programming Exercises 1. Write an application named BadSubscriptCaught in which you declare an array of 10 first names. Write a try block in which you prompt the user for an integer and display the name in the requested position.

  Sets a loop to find 10 random generated

Write a java code that 1) uploads a file 2) sets a loop to find 10 random generated words from the file and then search those words by a. IndexSequential Method b. indexBinary Method. then, report how much time both methods took.

  Design a function named "falling distance"

Design a function named "fallingDistance" that accepts an objects falling time, in seconds, as an argument. The function should return the distance, in meters, that the object has fallen during that time interval. Design a program that calls the func..

  Create a world class that contains a 2d array

You have to create a world class that contains a 2d array then create an abstract class called organism that contains move() method the organism should move randomly one step at the time.

  Write an interface for an abstract method

Write an interface, PointingDevice, containing:  an abstract method, getXCoord that returns an int and an abstract method, getYCoord that returns an int.

  Create and implement class called date to store month

Create and Implement the class called Date which has data members to store month (as a number), day, year, and name of month.

  Java program which demonstrates cellular automata

Using the internet, locate a Java program (or Java applet) which demonstrates "Cellular Automata", in particular "the Game of Life".

  Enterprise java beans (ejb) in software development

Enterprise Java Beans (EJB) in software development, EJB technology, EJB application, Stateless Session Beans (SLSB), Stateful Session Beans (SFSB), Message Driven Bean (MDB), Entity Bean

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

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