All pastes #191304 Raw Edit

Something

public cpp v1 · immutable
·published 2006-10-04 21:00 UTC
rendered paste body
/*************************************************************************** *   Copyright (C) 2006 by Nicholas Omann                                  * *   nicholas.omann@st.bemidjistate.edu                                    * *                                                                         * *   Permission is hereby granted, free of charge, to any person obtaining * *   a copy of this software and associated documentation files (the       * *   "Software"), to deal in the Software without restriction, including   * *   without limitation the rights to use, copy, modify, merge, publish,   * *   distribute, sublicense, and/or sell copies of the Software, and to    * *   permit persons to whom the Software is furnished to do so, subject to * *   the following conditions:                                             * *                                                                         * *   The above copyright notice and this permission notice shall be        * *   included in all copies or substantial portions of the Software.       * *                                                                         * *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       * *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    * *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.* *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR     * *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * *   OTHER DEALINGS IN THE SOFTWARE.                                       * ***************************************************************************//**\  money.cpp\__/  _____________________________________________________________________/  \  Implements the constructors and methods for the Money class defined \__/  in money.h./  \  _____________________________________________________________________\**/#include "money.h"// ********************// **  CONSTRUCTORS  **// ********************Money::Money(int dollars, int cents){  pennies = 100 * dollars + cents;}Money::Money(double amount){  pennies = int(amount * 100 + .5);}// **********************// **  PUBLIC METHODS  **// **********************double Money::ToDouble() const{  return double(pennies) / 100;}void Money::Round(){  pennies = (pennies / 100) * 100;}// ************************// **  FRIEND FUNCTIONS  **// ************************ostream& operator<< (ostream & output, const Money & val){  output << '$' << val.pennies / 100 << '.' << abs(val.pennies % 100);  return output;}istream& operator>>(istream & input, Money & val){  double temp;  input >> temp;  val.pennies = int(temp * 100 + .5);  return input;}bool operator<(const Money & val1, const Money & val2){  return val1.pennies < val2.pennies;}Money operator+(const Money & val1, const Money & val2){  int cents;  cents = val1.pennies + val2.pennies;  return Money(cents / 100 ,cents % 100 );}Money operator*(double m, const Money & val){	int cents;	cents = int(m * val.pennies);	return Money(cents / 100 , cents % 100);}Money operator*(const Money & val, double m){	int cents;	cents = (val.pennies * m);	return Money(cents / 100 , cents % 100);}