Suppose we are faced with the need for the unit price on a square pizza. The problem here is to devise in a ‘natural’ way to overload unitPrice to compute the price per square inch of a square as well as a round pizza?

Consider the revised pizza buying program of Display 4.7. This program provides the following overloading for unitPrice functions for round and rectangular pizza:```
double unitPrice(int diameter, double price);
double unitPrice(int length, int width, double price);
```
double unitPrice(int edge, double price);
double unitPrice(double edge, double price);


There is no nice way to do this. A simple minded approach is to write
This attempt involves having two overloaded unitPrice function versions both of
which have argument lists with types int and double, which results in an ability.
A student might overload using two doubles for arguments:
This leads to the problem of remembering always to use a double for the size
(edge length) of a square pizza and an int for the size (diameter). This tends to be
error prone.
We are faced with writing a function with a different name. (Of course, the easiest
way to solve the problem of finding a unit price for a square pizza is to call the
function for rectangular pizza, passing the edge size to the length and the width
parameters, but that begs the question of this test question: how to overload in a
natural way.)

Computer Science & Information Technology

You might also like to view...

Clip art is entered into a document from the ________

A) SmartArt dialog box. B) Quick Style list. C) Clipboard. D) Clip Art task pane.

Computer Science & Information Technology

A specific spot on a grid of thousands of such spots that form an image displayed on a computer is called a(n):

A) image element B) image grid C) grid element D) pixel

Computer Science & Information Technology

You can include capitalization as a sort criterion by clicking Options in the Sort dialog box, then selecting the ____________________ sensitive check box.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology

Restricted websites are part of the ____.

A. deep web B. public web C. visible web D. surface web

Computer Science & Information Technology