const int MAX_BOOKS = 500; struct BookType //Structure to be used in program. {
ID: 3542879 • Letter: C
Question
const int MAX_BOOKS = 500;
struct BookType //Structure to be used in program.
{
string title;
string author;
string date;
};
int numberOfBooks;
BookType libraryOfBooks[MAX_BOOKS];
Assume that the booklist.txt is already recorded from a file into an array of structure
libraryOfBooks[numberOfBooks].
Please show me how do I use these functions below?
insertNewItem()
deleteExistingItem()
searchBookAuthor()
searchByBookAuthor()
sortByBookTitle()
displayWholeList()
//******************booklist.txt******************************************************
Idiot's guide to C++
Code Master
2013
Idiot's guide to Java
Code Guru
2012
.
.
.
and so on........
Explanation / Answer
what is max_books and number of books mean here .?? they are confusing can you tell me what they are .Iam assuming them to be max it can hold and number currently in it.
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
struct BookType //Structure to be used in program.
{
string title;
string author;
string date;displayWholeList()
};
const int MAX_BOOKS = 500;
int insertNewItem ( BookType a,BookType** b ,int number);
int deleteExistingItem ( BookType a,BookType** b ,int number);
string searchBookAuthor(BookType a,BookType** b,int number);
BookType searchBookByAuthor(string a,BookType** b,int number);
void sortByBookTitle(BookType** b,int number);
void displayWholeList(BookType** b,int number);
int main()
{
int numberOfBooks;
BookType* libraryOfBooks[MAX_BOOKS];
//your operations here
}
int insertNewItem ( BookType a,BookType** b ,int number)
{
*b[number+1]=a;
number++;
}
int deleteExistingItem ( BookType a,BookType** b ,int number)
{
int i=0;
for(;i<number;i++){
if( *b[i]==a) { break;}
}
int j=i;
while(b[j+1]!=NULL) {*b[j]=*b[j+1];}
return number--;
}
string searchBookAuthor(BookType a,BookType** b,int number)
{
int i=0;
for(;i<number;i++){
if( *b[i]==a) { return a.author ;}
}
cout>>"not found";
return 0;
}
BookType searchBookByAuthor(string a,BookType** b,int number){
int i=0;
for(;i<number;i++){
if( a.compare(b[i]->author)==0) { return *b[i] ;}
}
cout>>"not found";
return 0;
}
void sortByBookTitle(BookType** b,int number){
int temp;
for ( int h = 0 ; h<number ; h++ ) // ordering using two for loops
{
for(int l=0; l<number; l++)
{
if(b[l]->author.compare(b[l+1]->author)>0) //checking if the counter value is bigger or smaller..
{
temp = b[l];
b[l] = b[l+1]; //ordering of both string and int
b[l+1] = temp;}}}
}
BookType displayWholeList(string a,BookType** b,int number){
int i=0;
for(;i<number;i++){cout>>b[i]->author>>" ">>b[i]->date>>" ">>b[i]->title>>" ";
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.