diff --git a/Cat.cpp b/Cat.cpp new file mode 100644 index 0000000..95dabe2 --- /dev/null +++ b/Cat.cpp @@ -0,0 +1,23 @@ +#include +#include +#include "Cat.h" +using namespace std; + +Cat::Cat(){ + name=" "; + age=0.00; + } + void Cat::setName (string catN){ + name=catN; + } + void Cat::setAge (float catAge){ + age=catAge; + } + string Cat::getName(){ + return name; + } + float Cat::getAge(){ + return age; + } + + diff --git a/Cat.h b/Cat.h new file mode 100644 index 0000000..b6b54c8 --- /dev/null +++ b/Cat.h @@ -0,0 +1,15 @@ +#include +#include +using namespace std; +class Cat{ + public: + Cat(); + + void setName (string catN); + void setAge (float catAge); + string getName(); + float getAge(); + private: + string name; + float age; +}; diff --git a/driver.cpp b/driver.cpp new file mode 100644 index 0000000..17c0ade --- /dev/null +++ b/driver.cpp @@ -0,0 +1,115 @@ +#include +#include +#include "Cat.h" +using namespace std; + +int linearSearch(auto data, auto key)//prototype +{ + for (int i=0; i < data.size(); i++) + { + if(data[i]==key) + { + return i; + } + } + return -1; +} + +int main() +{ + Cat cats; + vectorcatVec; + string catName; + int catAge; + string search_key; + int result; + + for(int i=0;i<=3;i++) + { + cout<<"Please enter cat name and age \n"; + cin>> catName >> catAge; + cats.setName(catName); + cats.setAge(catAge); + catVec.push_back(cats); + } + + for(int i=0;i<=3;i++) + { + cout<>search_key; + while(search_key != "#")//perform searches until sentinel entered + { + result = linearSearch(catVec,search_key); + + cout<<" '"<>search_key; + } + + cout< inputs; + string search_key, input; + int result; + + cout<<"Welcome to \"search it\". We first need some input data."<>input; + + while(input != "#")//read an unknown number of inputs from keyboard + { + inputs.push_back(input); + cin>>input; + } + + cout<>search_key; + + while(search_key != "#")//perform searches until sentinel entered + { + result = linearSearch(inputs,search_key); + + cout<<" '"<>search_key; + } + + cout<