float Budget::CategoryTotal(string category) { if (!_CategoryExists(category)) { return 0; } Category* c = _categories.find(category)->second; float total = 0; for (Category::Iterator i = c->Begin(); i != c->End(); i++) { total += i->second->Amount(); } return total; }
void RemoveCategoryCommand::SetDocument(Budget* document) { Command::SetDocument(document); list<Transaction*>::iterator list_it; // Delete any old transactions (there probably aren't any) for (list_it = _transactions.begin(); list_it != _transactions.end(); list_it++) { delete *list_it; } Category* c = _document->Categories()->find(_category)->second; // Save all of the transactions that are in this category for (Category::Iterator i = c->Begin(); i != c->End(); i++) { Transaction* t = i->second; Transaction* new_t = new Transaction(t->Timestamp(), t->Reason(), t->Amount(), t->Action()); _transactions.push_back(new_t); } }