-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSource.cpp
More file actions
78 lines (62 loc) · 1.55 KB
/
Source.cpp
File metadata and controls
78 lines (62 loc) · 1.55 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
78
#include <iostream>
#include <string>
#include <vector>
#include "Cake.h"
using namespace std;
int linearSearch(auto data, auto key);//prototype
int main() {
vector <Cake> Cakes;
Cake cakeObj;
string ingredient;
string ingredients[10];
string flav;
string search_key = "Vanilla";
int result;
for(int i = 0; i<4;i++) {
Cakes.push_back(cakeObj);
}
for (auto u : ingredients) {
u="";
}
cout << "Enter the ingredient and type information for the four cakes \n" << endl;
for (int o =0; o<4;o++){
cout << "\nEnter each ingredient for the cake (Max 10 ingredients). A '-' (dash) indicates no more ingredients\n" << endl;
for (int x =1;x<11;x++){
cout << "Ingredient " <<x<<":";
cin >> ingredient;
if(ingredient == "-") {
cin.ignore();
break;
}
else {
ingredients[x-1] = ingredient;
cin.ignore();
}
}
Cakes[o].gatherIngredients(ingredients);
cout << "Please enter the type of cake you are making" << endl;
getline(cin,flav);
Cakes[o].setCakeFlavour(flav);
}
while(search_key != "#")//perform searches until sentinel entered
{
result = linearSearch(Cakes,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;
}
cout<<endl<<"Program \"search it\" is now finished."<<endl<<endl;
return 0;
}
int linearSearch(auto data,auto key){
for(int i=0;i<data.size();i++){
if(data[i].getCakeFlavour() == key) {
return i;
}//endif
}//endfor
return -1; //not found
}