forked from BitSails/hellogit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignment0.cpp
More file actions
78 lines (56 loc) · 1.5 KB
/
Assignment0.cpp
File metadata and controls
78 lines (56 loc) · 1.5 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <iostream>
#include <string>
#include <vector>
#include "NumMan.h"
using namespace std;
void SquareAndAddition(vector<NumberManip>&);
void printnumbers(vector<NumberManip>&);
int linearSearch(auto data, double key);
int main() {
double search_key;
int result;
vector<NumberManip> NumManip;
SquareAndAddition(NumManip);
printnumbers(NumManip);
cout<<"Enter a value to search for, enter -1 to exit.";
cin>>search_key;
while(search_key != -1)//perform searches until sentinel entered
{
result = linearSearch(NumManip,search_key);
cout<<" '"<<search_key<<"' was ";
if (result == -1)
cout<<"not found";
else
cout<<"found at index "<<result;
cout<<endl<<endl<<"Enter a value to search for: ";
cin>>search_key;
}
return 0;
}
void SquareAndAddition(vector<NumberManip>& ManipNumber) {
NumberManip val1;
val1.setSquareNum(20);
val1.setAdditionNum(2.3);
ManipNumber.push_back(val1);
val1.setSquareNum(4);
val1.setAdditionNum(5.5);
ManipNumber.push_back(val1);
}
void printnumbers(vector<NumberManip>& ManipNumber) {
int size = ManipNumber.size();
for (int i = 0; i < size; i++) {
cout << "Number when squared: " << ManipNumber[i].getSquare() << endl;
cout << "Number when added to itself: " << ManipNumber[i].getAddition() << endl;
}
}
int linearSearch(auto Data, double key)
{
for(int i = 0; i < Data.size(); i++)
{
if (Data[i].getAddition() == key)
{
return i;
}
}
return -1;
}