Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Cat.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <iostream>
#include <vector>
#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;
}


15 changes: 15 additions & 0 deletions Cat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <iostream>
#include <string>
using namespace std;
class Cat{
public:
Cat();

void setName (string catN);
void setAge (float catAge);
string getName();
float getAge();
private:
string name;
float age;
};
115 changes: 115 additions & 0 deletions driver.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#include <iostream>
#include <vector>
#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;
vector<Cat>catVec;
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<<catVec[i].getName()<<"\t";
cout<<catVec[i].getAge()<<"\n";
}
cout<<"Enter a value to search for: ";


cin>>search_key;
while(search_key != "#")//perform searches until sentinel entered
{
result = linearSearch(catVec,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;


/*vector<string> inputs;
string search_key, input;
int result;

cout<<"Welcome to \"search it\". We first need some input data."<<endl;
cout<<"We'll assume the inputs do not have any spaces."<<endl<<endl;
cout<<"To end input type the #-character (followed by Enter)"<<endl<<endl;

cin>>input;

while(input != "#")//read an unknown number of inputs from keyboard
{
inputs.push_back(input);
cin>>input;
}

cout<<endl<<"["<<inputs.size()<<" values read from input source]"<<endl<<endl;

if(inputs.size() == 0)//no input
{
cout<<endl<<"No input received, quiting..."<<endl<<endl;
exit(1);//nothing to do but quit program
}

cout<<endl<<"To end input type the #-character (followed by Enter)"<<endl<<endl;
cout<<"Enter a value to search for: ";


cin>>search_key;

while(search_key != "#")//perform searches until sentinel entered
{
result = linearSearch(inputs,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;*/
}