diff --git a/Book.cpp b/Book.cpp new file mode 100644 index 0000000..0179a43 --- /dev/null +++ b/Book.cpp @@ -0,0 +1,23 @@ +#include +#include +#include "Book.h" + +using namespace std; + +string Book::getBookname() +{return bookname; +} + +int Book::getAmount() + {return amount;} + +void Book::setBookname (string n) + {bookname= n;} + +void Book::displayInfo() + {cout<<"Title:"< +class Book +{ + public: + void setBookname(std::string n); + void setAmount(int a); + std::string getBookname(); + int getAmount(); + void displayInfo(); + + private: + int amount; + std::string bookname; +}; +#endif + + diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..74ea34c --- /dev/null +++ b/main.cpp @@ -0,0 +1,62 @@ +#include +#include +#include +#include "Book.h" +using namespace std; + +int linearSearch(auto data, auto key); + +int main() +{ + string title; + int amt; + Book i; + vectorstock; + for (int x=0;x<4; x++){ + cout<< "Enter book title and amount of books "; + cin>> title>>amt; + + i.setBookname(title); + i.setAmount(amt); + stock.push_back(i); + } + for (int y=0;y < 4;y++){ + stock[y].displayInfo();} + + return 0; + + + + + string search_key, input; + int result; + cout<<"Enter a value to search for: "; + cin>>search_key; + while(search_key != "#") + { + result = linearSearch(stock,search_key); + + cout<<" '"<>search_key; + } + return 0; + +} +int linearSearch(auto data, auto key) +{ + for (int i=0;i < data.size();i++) +{ + if (data[i].getBookname == key){ + return i;} + return -1; +} + +}