예제 #1
0
// customer rental statement
std::string Customer::statement() const {

    double totalAmount = 0;
    int frequentRenterPoints = 0;
    std::string result = "Rental Record for " + getName() + "\n";
    for(std::vector<Rental>::const_iterator it = rentals.begin(); it != rentals.end(); ++it) {
        double thisAmount = 0;
        Rental each = (Rental) *it;

        //determine amounts for each line
        switch (each.getMovie().getPriceCode()) {
            case Movie::REGULAR:
                thisAmount += 2;
                if (each.getDaysRented() > 2)
                    thisAmount += (each.getDaysRented() - 2) * 1.5;
                break;
            case Movie::NEW_RELEASE:
                thisAmount += each.getDaysRented() * 3;
                break;
            case Movie::CHILDRENS:
                thisAmount += 1.5;
                if (each.getDaysRented() > 3)
                    thisAmount += (each.getDaysRented() - 3) * 1.5;
                break;

        }

        // add frequent renter points
        ++frequentRenterPoints;
        // add bonus for a two day new release rental
        if ((each.getMovie().getPriceCode() == Movie::NEW_RELEASE) &&
            each.getDaysRented() > 1) frequentRenterPoints ++;

        //show figures for this rental
        result += "\t" + each.getMovie().getTitle()+ "\t";
        std::ostringstream amount_stream;
        amount_stream << thisAmount;
        result +=  amount_stream.str();
        result += "\n";
        totalAmount += thisAmount;

    }

    //add footer lines
    // total amount owed
    result += "Amount owed is: ";
    std::ostringstream owed_stream;
    owed_stream << totalAmount;
    result += owed_stream.str();
    result += "\n";

    // frequent renter points earned
    result += "You earned: ";
    std::ostringstream frequent_stream;
    frequent_stream << frequentRenterPoints;
    result += frequent_stream.str();
    result += " frequent renter points\n";

    return result;
}
예제 #2
0
string Customer::statement() {
		double totalAmount = 0;
		int frequentRenterPoints 	= 0;
    ostringstream result;
    result << "Rental Record for " << getName () << "\n";
		
    for(Iter iter = rentals.begin(); iter != rentals.end(); ++iter) {
			double thisAmount = 0;
			Rental* each = *iter;
			
			// determines the amount for each line
			switch (each->getMovie()->getPriceCode()) {
        case Movie::Regular:
					thisAmount += 2;
					if (each->getDaysRented () > 2)
						thisAmount += (each->getDaysRented () - 2) * 1.5;
					break;
        case Movie::NewRelease:
					thisAmount += each->getDaysRented () * 3;
					break;
        case Movie::Childrens:
					thisAmount += 1.5;
					if (each->getDaysRented () > 3)
						thisAmount += (each->getDaysRented () - 3) * 1.5;
					break;
			}
			
			frequentRenterPoints++;
			
      if (each->getMovie()->getPriceCode() == Movie::NewRelease && each->getDaysRented () > 1)
				frequentRenterPoints++;
				
			result << "\t" << each->getMovie()->getTitle() << "\t" << thisAmount << "\n";
			totalAmount += thisAmount;
		}
		
		result << "You owed " << totalAmount << "\n" << "You earned " << frequentRenterPoints << " frequent renter points\n";
		
		return result.str();
	}
예제 #3
0
//拆分函数(提炼到独立函数)
//独立函数名称修改
double amountFor(Rental aRental) {
    double result = 0;
    //determin amounts for each line
    switch(aRental.getMovie().getPriceCode()) {
        case Movice.REGULAR:
            result += 2;
            if(aRental.getDaysRented() > 2) {
                result += (aRental.getDaysRented() - 2) * 1.5;
            }
            break;
        case Movice.NEW_RELEASE:
            result += aRental.getDaysRented() * 3;
            break;
        case Movice.CHILDRENS:
            result += 1.5;
            if (aRental.getDaysRented() > 3) {
                result += (aRental.getDaysRented() - 3) * 1.5;
            }
            break;
    }
    return result;
}