Ask Java Expert


Home >> Java

 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;

}

 

 

Java, Programming

  • Category:- Java
  • Reference No.:- M9454078

Have any Question?


Related Questions in Java

Chatbotscreate a small networked chat application that is

Chatbots Create a small, networked chat application that is populated by bots. Introduction On an old server park, filled with applications from the early days of the internet, a few servers still run one of the earliest ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Assignment game prototypeoverviewfor this assessment task

Assignment: Game Prototype Overview For this assessment task you are expected to construct a prototype level/area as a "proof of concept" for the game that you have designed in Assignment 1. The prototype should function ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

In relation to javaa what is constructor the purpose of

(In relation to Java) A. What is constructor? the purpose of default constructor? B. How do you get a copy of the object but not the reference of the object? C. What are static variables and instance variables? D. Compar ...

Project descriptionwrite a java program to traverse a

Project Description: Write a java program to traverse a directory structure (DirWalker.java) of csv files that contain csv files with customer info. A simple sample in provided in with the sample code but you MUST will r ...

Fundamentals of operating systems and java

Fundamentals of Operating Systems and Java Programming Purpose of the assessment (with ULO Mapping) This assignment assesses the following Unit Learning Outcomes; students should be able to demonstrate their achievements ...

Assessment -java program using array of Assessment -JAVA Program using array of objects

Assessment -JAVA Program using array of objects Objectives This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details For this assignment, you are required to develop a Windowed G ...

Applied software engineering assignment 1 -learning

Applied Software Engineering Assignment 1 - Learning outcomes - 1. Understand the notion of software engineering and why it is important. 2. Analyse the risk factors associated with phases of the software development lif ...

Retail price calculatorwrite a java program that asks the

Retail Price Calculator Write a JAVA program that asks the user to enter an item's wholesale cost and its markup percentage. It should then display the item's retail price. For example: (If an item's wholesale cost is 5. ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As