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
41 changes: 41 additions & 0 deletions Books.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include "Books.h"
#include <string>
#include <vector>
using namespace std;

Books::Books()
{
fee=0;
}

Books::Books(string member, int numDays)
{
name=member;

fee=numDays * 0.50;
}

void Books::setName(string member)
{
name=member;
}

string Books::getName() const
{
return name;
}


void Books::setFee(int numDays)
{

fee=numDays * 0.50;

}

double Books::getFee() const
{
return fee;
}


37 changes: 37 additions & 0 deletions Books.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

#ifndef BOOKS_H
#define BOOKS_H

#include <iostream>
#include <string>

using namespace std;

class Books
{

public:
Books();

Books(string, int);

void setName(string);

string getName() const;

void setFee(int);

double getFee() const;





private:
string name;
double fee;


};

#endif
86 changes: 86 additions & 0 deletions Library.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#include <iostream>
#include <vector>
#include <string>
#include <iomanip>

#include "Books.h"

using namespace std;

int linearSearch(vector<Books>&, string);

int main()
{

vector<Books>Obooks; //vector of object overdue books

string member;
int days,amt,num;

cout<<"\nPlease enter the following information for overdue books";
cout<<"\n How many late members are there? ";
cin>>amt;

for (int x=0; x<amt; x++)
{
cout<<"\nPlease enter member's name: ";
cin>>member;

cout<<"Please enter the number of days late: ";
cin>>days;

Books lateMembers(member,days);

Obooks.push_back(lateMembers);

cout<<endl;
}
cout<<endl;

for (int x=0; x<amt; x++)
{
cout<<"Members with outstanding fees: "<<endl;
cout<<Obooks[x].getName()<<" : $";
cout<<fixed<<setprecision(2)<<Obooks[x].getFee();
cout<<endl;
}
cout<<endl;

string value;

cout<<"Please enter a name to be searched(to end input,enter '!'): ";
cin>>value;

while(value != "!")
{
num= linearSearch(Obooks,value);

if (num==-1)
{
cout<<"Name was not found"<<endl;
}
else
cout<<"Name found at index: "<<num<<endl;

cout<<"\nEnter a name to be searched for: ";
cin>>value;

}


return 0;
}


int linearSearch (vector<Books>& Data, string key)
{
for(unsigned int i=0; i<Data.size();i++)
{
if (Data[i].getName() == key)
{
return i;
}
}
return -1;
}