Skip to content

Commit

Permalink
去除frequentRenterPoints临时变量
Browse files Browse the repository at this point in the history
  • Loading branch information
chentuo14 committed Mar 5, 2019
1 parent b260249 commit 7ae1782
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
16 changes: 12 additions & 4 deletions ch1_firstCase/ch1_switch/customer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,18 @@ std::__cxx11::string Customer::getName()

std::__cxx11::string Customer::statement()
{
int frequentRenterPoints = 0; //积分点

std::string result = "Rental Record for " + getName() + "\n";
std::vector<Rental>::iterator iter = _rentals.begin();
for(;iter != _rentals.end();++iter) {
Rental each = *iter;
frequentRenterPoints+=each.getFrequentRenterPoints();

//添加详单
result += "\t" + each.getMovie().getTitle() + "\t"
+ std::to_string(each.getCharge()) + "\n";
}
//添加脚注
result += "Amount owed is " + std::to_string(getTotalCharge()) + "\n";
result += "You earned " + std::to_string(frequentRenterPoints) +
result += "You earned " + std::to_string(getTotalfrequentRenterPoints()) +
" frequent renter points" + "\n";
return result;
}
Expand All @@ -57,3 +54,14 @@ double Customer::getTotalCharge()
return result;
}

int Customer::getTotalfrequentRenterPoints()
{
int result = 0; //积分点
std::vector<Rental>::iterator iter = _rentals.begin();
for(;iter != _rentals.end();++iter) {
Rental each = *iter;
result += each.getFrequentRenterPoints();
}
return result;
}

1 change: 1 addition & 0 deletions ch1_firstCase/ch1_switch/customer.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Customer
std::vector<Rental>& getRentals();
double amountFor(Rental aRental);
double getTotalCharge();
int getTotalfrequentRenterPoints();

private:
std::string _name; //顾客名
Expand Down

0 comments on commit 7ae1782

Please sign in to comment.