| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi ya'll, thanks to whoever responds to this post, i'm in dire
need of some help on this C++ program. Hate to ask for this much help, but seems like experts can make up these classes and functions better and quicker than i could. The .doc file contains the startup code, PLS PLS someone help me get the func definitions and declarations!!! We want to be able to work with objects that are of type Distance. A Distance can be thought of as consisting of two values: an integer number of feet and a double number of inches. The number of feet in a Distance object needs to be non-negative and the number of inches needs to be non-negative as well as strictly less than 12. When a Distance object is created (using a constructor), the values of feet and inches are specified (as two values, an int and a double); if both values are omitted, the Distance should default to 0 feet and 0 inches; if the only the second value is omitted, a default value of 0 inches should be used for that missing value. If the Distance is specified improperly (i.e., if either the feet or inches is out of range), the values should be automatically adjusted to legal values as follows: if the value for feet is negative, use the value 0 instead; if the value for the inches is either negative or is greater than or equal to 12, use the value 0 instead. There should be a boolean member function, change, that will allow you to adjust the value of an existing Distance. The member function change should have two parameters, an int and a double. If the second parameter is omitted, a default value of zero should be used. If either of the parameters provided to change is out of range, ignore the request and return a value of false; otherwise, make the requested change and return true. There should also be an integer member function, rounded, that returns the number of feet in the given Distance (rounded to the nearest foot … 6 inches or more, go up). There should be a void member function, add, that has one parameter of type Distance. The value of that parameter should be added to the calling object. There should be a boolean member function, times, that has one double parameter. If the value of that parameter is negative, ignore the request and return a value of false; otherwise, multiply the Distance by that parameter and return the value true. Finally, there should be a voidprint member function that will display the Distance (no C/R or spacing before or afterwards) using the format: |
|
#2
|
|||
|
|||
|
Are you refering to Robert Lafore??
|
|
#3
|
|||
|
|||
|
Quote:
For addition and times operation, you need to overload '+' and '*' operators with Distance as return object and parameter as Distance: Code:
Distance operator + ( Distance d1)
{
Distance d;
d.feet = d1.feet + d2.feet;
//d2 is another Distance object.
d.inches = d1.inches + d2.inches;
//check whether sum of inches
//exceed 12
if ( d.inches >= 12)
d.feet += 1;
return d;
}
Similarly, you need to overload '*' for times. For change() and add(), you can do it.You need to call : Code:
d = d1(x,y)+d2(x) //where x,y are to be replaced. HTH |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > C++ Emer. Help!!! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|