Calculations
Let's write the summing function for our CSV reader app and compile the code.
We'll cover the following...
We'll cover the following...
Once all the records are available we can compute their sum:
Press + to interact
[[nodiscard]] double CalcTotalOrder(const std::vector<OrderRecord>& records,const Date& startDate, const Date& endDate){return std::accumulate(std::begin(records), std::end(records), 0.0,[&startDate, &endDate](double val, const OrderRecord& rec) {if (rec.CheckDate(startDate, endDate))return val + rec.CalcRecordPrice();elsereturn val;});}
The code runs on the vector of all records and then calculates the price of each element if they fit between startDate
and endDate
. Then they are all summed in std::accumulate
.
Design Enhancements
The ...