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 Book.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include<iostream>
#include<string>
#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:"<<bookname<<endl;
cout <<"Amount of books:"<<amount<<endl;
}
void Book::setAmount (int a)
{amount =a;}

19 changes: 19 additions & 0 deletions Book.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef BOOK_H
#define BOOK_H
#include<string>
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


62 changes: 62 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include<iostream>
#include<string>
#include<vector>
#include "Book.h"
using namespace std;

int linearSearch(auto data, auto key);

int main()
{
string title;
int amt;
Book i;
vector<Book>stock;
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<<"' 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;

}
int linearSearch(auto data, auto key)
{
for (int i=0;i < data.size();i++)
{
if (data[i].getBookname == key){
return i;}
return -1;
}

}