-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathou-cs3203-assignment3.cpp
63 lines (46 loc) · 1.29 KB
/
ou-cs3203-assignment3.cpp
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
class assignment3{
private:
vector<int> vect;
public:
void add_number(int number) {
vect.push_back(number);
};
int add(){
int sum = 0;
for (int i = 0; i < vect.size(); ++i) {
sum += vect.at(i);
}
return sum;
} ;
int product() {
int product = 1;
for (int i = 0; i < vect.size(); ++i) {
product = product * vect.at(i);
}
return product;
};
void reverseThis(){
reverse(vect.begin(), vect.end());
for (int i = 0; i < vect.size(); ++i) {
cout << vect.at(i) << " ";
}
};
};
int main(){
assignment3 vector;
cout<< "Hello! Please input integers to create a vector! Put in a letter to indicate you're finished."<<endl;
int current, count;
while(cin >> current){
++count;
vector.add_number(current);
}
cout << "The total sum of all values is " << vector.add() << "." << endl;
cout << "The product of all the values is " << vector.product() << "." << endl;
cout << "The reversed list is ";
vector.reverseThis();
return 0;
}