-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResult.cpp
More file actions
42 lines (35 loc) · 980 Bytes
/
Copy pathResult.cpp
File metadata and controls
42 lines (35 loc) · 980 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "Result.h"
#include <iostream>
using namespace std;
Result::Result() {
this->clear();
}
void Result::add(Object *object) {
valueSum += object->value;
weightSum += object->weight;
chosenObjectsList.push_back(object);
}
void Result::remove(Object *object) {
valueSum -= object->value;
weightSum -= object->weight;
chosenObjectsList.remove(object);
}
void Result::print() {
cout<<"Objects in Knapsack:\n\n";
int n=1;
for( auto &i : this->chosenObjectsList){
cout<<"Object "<<n<<":\n";
cout << "Value: " << i->value<< "\n";
cout << "Weight: " << i->weight << "\n\n";
n++;
}
cout<<"Their value is "<<this->valueSum<<"\n";
cout<<"Their weight is "<<this->weightSum<<"\n";
cout << "Problem solved in: " << elapsed_sec << " seconds" << endl;
}
void Result::clear() {
this->valueSum = 0;
this->weightSum = 0;
this->elapsed_sec = 0.0;
this->chosenObjectsList.clear();
}