Question

Please provide original Answer, I can not turn in the same as my classmate. thanks In...

Please provide original Answer, I can not turn in the same as my classmate. thanks

In this homework, you will implement a single linked list to store a list of computer science textbooks. Every book has a title, author, and an ISBN number. You will create 2 classes: Textbook and Library. Textbook class should have all above attributes and also a “next” pointer.

Textbook

Type

Attribute

String

title

String

author

String

ISBN

Textbook*

next

Textbook Type Attribute String title String author String ISBN Textbook* next Library class should have a head node as an attribute to keep the list of the books. Also, following member functions should be implemented in this class:

Library

Type

Attribute

Textbook*

head

Return Type

Function

constructor

void

addBook(string title, string author, string ISBN)

void

removeBook(string ISBN)

void

print()

void

print(char startingLetter)

void

print(string author)

Textbook

at(int index)

int

getSize()

bool

isEmpty()

Library Type Attribute Textbook* head Return Type Function constructor void addBook(string title, string author, string ISBN) void removeBook(string ISBN) void print() void print(char startingLetter) void print(string author) Textbook at(int index) int getSize() bool isEmpty() addBook(): Adds a new book to the list. The new book is placed based on the ALPHABETICAL ORDER of the titles. You shouldn’t add the textbook directly to the end or front of the list. The new book has to be inserted to the correct position. For example, if you have following three books:

                    The Algorithms -à The Programming Language-à The Society Mind

A new book, “Applied Cryptography” will be placed in alphabetical order between the first and second book.

removeBook(): This functions will remove a book using the given ISBN number. If the given ISBN number is not in the list, it will give an error.

print(): Print all books in (alphabetical) order. Title, author, and the ISBN should be printed for each book.

print(char startingLetter): Prints all books whose title starts with the input character, “startingLetter”.

print(string author): Prints all books of an author.

at(int index): Returns the book at given index

getSize(): returns the number of books in the list is

Empty(): returns true if list is empty, returns false otherwise.

The main program (main.cpp) is provided for you. So you will only implement the Textbook and library classes. I expect you to have 2 files: Library.h and Library.cpp. Textbook class definition will be in the Library.h file.

main.cpp includes all necessary functions to read the dataset file (dataset.txt). Also, several test cases are prepared for you to see whether your code is running or not. You do not need to change any code in the main.cpp file. Whenever you include your library class and main cpp to your project, they must run properly together.

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

This is the cpp file, zip file didn't work.

#include <iostream>

#include <fstream>

#include <string>

#include "Library.h"

using namespace std;

Library myLib;

//Read the dataset file and loads myLib list

void loadDataset(string fileName){

ifstream inFile;

inFile.open(fileName.c_str());

string line;

while(getline(inFile,line)){

int ind1 = line.find("#");

int ind2 = line.find("#",ind1+1);

string title = line.substr(0,ind1);

string author = line.substr(ind1+1, ind2-ind1-1);

string ISBN = line.substr(ind2+1);

//Here we add the new book. Please make sure your function name matches

myLib.addBook(title,author,ISBN);

}

}

//Just for convenience...

void continueMessage(string message){

cout << message << endl;

cout << "Press Enter to continue.." << endl; cin.get();

}

int main() {

string fileName = "dataset.txt";

loadDataset(fileName);

continueMessage("Dataset file is loaded to the program!");

//---------------------------------------------------------------------------

myLib.print();

continueMessage("All books in the library are listed!");

//---------------------------------------------------------------------------

string title = "Total Recall: How the E-Memory Revolution Will Change Everything";

string author = "C. Gordon Bell";

string ISBN = "592968760-9";

myLib.addBook(title,author,ISBN);

continueMessage("New book, with " + ISBN + " ISBN is added to the library.");

//---------------------------------------------------------------------------

myLib.print(title[0]); string s(1, title[0]);

continueMessage("The books, whose title starts with "+s+", are listed.");

//---------------------------------------------------------------------------

author = "W. Richard Stevens";

myLib.print(author);

continueMessage("The books, whose author is "+author+", are listed.");

//---------------------------------------------------------------------------

myLib.removeBook(ISBN);

continueMessage("The book, with " + ISBN + " ISBN is removed from the library.");

//---------------------------------------------------------------------------

Textbook tb = myLib.at(5);

cout << "Textbook at index 5: \n" << tb.title << "\n" << tb.author << "\t" << tb.ISBN << endl;

//---------------------------------------------------------------------------

int size = myLib.getSize();

cout << "There are currently " << size << " books in the library." << endl;

return 0;

}

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

data set

Introduction to Algorithms#Thomas H. Cormen#878134263-2
Structure and Interpretation of Computer Programs#Harold Abelson#336190405-6
The C Programming Language#Brian W. Kernighan#699022731-1
The Pragmatic Programmer: From Journeyman to Master#Andy Hunt#888099490-5
The Art of Computer Programming, Volumes 1-3 Boxed Set#Donald Ervin Knuth#625268126-1
Design Patterns: Elements of Reusable Object-Oriented Software#Erich Gamma#604854500-2
Introduction to the Theory of Computation#Michael Sipser#615228728-6
Code: The Hidden Language of Computer Hardware and Software#Charles Petzold#822491420-8
The Mythical Man-Month: Essays on Software Engineering#Frederick P. Brooks Jr.#987411743-5
Artificial Intelligence: A Modern Approach#Stuart Russell#704058716-5
Code Complete#Steve McConnell#465609758-6
The Protocols (TCP/IP Illustrated, Volume 1)#W. Richard Stevens#126456048-6
Algorithms#Robert Sedgewick#873746894-4
Advanced Programming in the UNIX Environment#W. Richard Stevens#598255768-4
A Discipline of Programming#Edsger W. Dijkstra#412861075-5
Introduction to Automata Theory, Languages, and Computation#John E. Hopcroft#952883775-1
Compilers: Principles, Techniques, and Tools#Alfred V. Aho#557104773-9
Joel on Software#Joel Spolsky#394368902-6
Learn You a Haskell for Great Good!: A Beginner's Guide#Miran Lipova a#260995077-2
The Society of Mind#Marvin Minsky#539224508-0

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Additional Resources

#include <iostream>

using namespace std;

class Node{

public:

int value;

Node* next;

Node(int newVal){

value = newVal;

next = NULL;

}

};

class LinkedList{

private:

Node* head;

int _size;

public:

LinkedList(){_size=0;}

LinkedList(int newVal){

head = new Node(newVal);

_size = 1;

}

int size(){ return _size;}

bool isEmpty(){return (_size==0)?true:false;}

void pushBack(int newValue){

//Create the node to be added

Node* newElement = new Node(newVal);

//Find the node that has a NULL next pointer. (Last node)

Node* current = head;

while(current->next != NULL){

current = current->next;

}

current->next = newElement;

_size++;

}

void insertAt(int newValue,int index){

//The index must be in the range

if(index <= _size && index >= 0){

//Create the node to be added

Node* newElement = new Node(newVal);

//If the node is added at the beginning we have a special case

if(index == 0){

newElement->next = head;

head = newElement;

}

else{

Node* current = head;

for(int i = 0;i<index-1;i++)

current = current->next;

newElement->next = current->next;

current->next = newElement;

}

_size++;

}

else{

cout << newValue << " cannot be added. Index " << index << " is out of range" << endl;

}

}

//Access the element in given index

int at(int index){

if(index < _size && index >= 0){

Node* current = head;

for(int i = 0;i<index;i++)

current = current->next;

return current->value;

}

else{

cout << "Index " << index << " is out of range." << endl;

}

}

int removeAt(int index){

if(index < _size && index >= 0){

//If the node is added at the beginning we have a special case

Node* deletedNode;

if(index == 0){

deletedNode = head;

head = head->next;

}

else{

Node* current = head;

for(int i = 0;i<index-1;i++)

current = current->next;

deletedNode = current->next;

current->next = current->next->next;

}

int deletedVal = deletedNode->value;

delete deletedNode;

_size--;

return deletedVal;

}

else{

cout << "Index " << index << " is out of range." << endl;

return -1;

}

}

//print the list

void print(){

Node* current = head;

while(current!=NULL){

cout << current->value << " ";

current = current->next;

}

cout << endl;

}

};

int main(){

LinkedList myList(5);

myList.pushBack(4); myList.print();

myList.pushBack(1); myList.print();

myList.pushBack(3); myList.print();

myList.pushBack(7); myList.print();

myList.insertAt(8,2); myList.print(); //Add to ind = 2

myList.insertAt(2,0); myList.print(); //Add to the beginning

myList.insertAt(6,myList.size()); myList.print(); //Add to the end

int val;

val = myList.removeAt(0); cout << val << " removed! -> "; myList.print();

val = myList.removeAt(2); cout << val << " removed! -> ";myList.print();

val = myList.removeAt(myList.size()-1); cout << val << " removed! -> ";myList.print();

if(myList.isEmpty())

cout << "The list is Empty" << endl;

else

cout << "The list is NOT Empty" << endl;

for(int i=0;i<myList.size();i++)

cout << "List[" << i << "] = " << myList.at(i) << endl;

cout << "There are " << myList.size() << " elements in the list." << endl;

return 0;

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

clas Textbook pubtic: Stina tithe Shing auitlo,, าท rO Sh JSBN Teitbovk head void pnt ( chau Void Tuxt book at (int) Size ()Text book * : NULL。 authos nuwwbook ruxt NULL hed book Putusnthe laut OR Dhead nwbook-) ment = -> next ntw book Void Li : umove book Tet beok SBNmurxt - muxt 그SBN tout book,

- - NULL) Cout << lut void. Li print ( stit elae ! = NULLetae auuto - metTont book lmp hund elue ritu book Lib ubu TRUE elue Auhww CALSE

Add a comment
Know the answer?
Add Answer to:
Please provide original Answer, I can not turn in the same as my classmate. thanks In...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ In this homework, you will implement a single linked list to store a list of computer science textbooks. Ever...

    C++ In this homework, you will implement a single linked list to store a list of computer science textbooks. Every book has a title, author, and an ISBN number. You will create 2 classes: Textbook and Library. Textbook class should have all above attributes and also a "next" pointer. Textbook Туре String String String Attribute title author ISBN Textbook* next Library class should have a head node as an attribute to keep the list of the books. Also, following member...

  • fully comments for my program, thank you will thumb up #include <iostream> #include <fstream> #include <string>...

    fully comments for my program, thank you will thumb up #include <iostream> #include <fstream> #include <string> #include <iomanip> using namespace std; struct book { int ISBN; string Author; string Title; string publisher; int Quantity; double price; }; void choice1(book books[], int& size, int MAX_SIZE) { ifstream inFile; inFile.open("inventory.txt"); if (inFile.fail()) cout <<"file could not open"<<endl; string str;    while(inFile && size < MAX_SIZE) { getline(inFile, str); books[size].ISBN = atoi(str.c_str()); getline(inFile, books[size].Title);    getline(inFile, books[size].Author); getline(inFile, books[size].publisher);          getline(inFile,...

  • Question 10 What is the functionality of the following code? void myFunction() Node* current = head;...

    Question 10 What is the functionality of the following code? void myFunction() Node* current = head; while(current ! =NULL) { cout << current->value << ""; current = current->next; cout < endl; } Return the element at the given position in the list Inserting a node at the beginning of the list Deleting a node at the beginning of the list Printing all elements in the llst Deleting a node at the end of the llst quizzes/363010/take Question 7 What is...

  • A library maintains a collection of books. Books can be added to and deleted from and...

    A library maintains a collection of books. Books can be added to and deleted from and checked out and checked in to this collection. Title and author name identify a book. Each book object maintains a count of the number of copies available and the number of copies checked out. The number of copies must always be greater than or equal to zero. If the number of copies for a book goes to zero, it must be deleted from the...

  • How to write the insert, search, and remove functions for this hash table program? I'm stuck......

    How to write the insert, search, and remove functions for this hash table program? I'm stuck... This program is written in C++ Hash Tables Hash Table Header File Copy and paste the following code into a header file named HashTable.h Please do not alter this file in any way or you may not receive credit for this lab For this lab, you will implement each of the hash table functions whose prototypes are in HashTable.h. Write these functions in a...

  • please Code in c++ Create a new Library class. You will need both a header file...

    please Code in c++ Create a new Library class. You will need both a header file and a source file for this class. The class will contain two data members: an array of Book objects the current number of books in the array Since the book array is moving from the main.cc file, you will also move the constant array size definition (MAX_ARR_SIZE) into the Library header file. Write the following functions for the Library class: a constructor that initializes...

  • can someone please double check my code here are the requirements please help me fulfill the...

    can someone please double check my code here are the requirements please help me fulfill the requirements Using the material in the textbook (NumberList) as a sample, design your own dynamic linked list class (using pointers) to hold a series of capital letters. The class should have the following member functions: append, insert (at a specific position, return -1 if that position doesn't exist), delete (at a specific position, return -1 if that position doesn't exist), print, reverse (which rearranges...

  • Requirements: Finish all the functions which have been declared inside the hpp file. Details: st...

    Requirements: Finish all the functions which have been declared inside the hpp file. Details: string toString(void) const Return a visible list using '->' to show the linked relation which is a string like: 1->2->3->4->5->NULL void insert(int position, const int& data) Add an element at the given position: example0: 1->3->4->5->NULL instert(1, 2); 1->2->3->4->5->NULL example1: NULL insert(0, 1) 1->NULL void list::erase(int position) Erase the element at the given position 1->2->3->4->5->NULL erase(0) 2->3->4->5->NULL //main.cpp #include <iostream> #include <string> #include "SimpleList.hpp" using std::cin; using...

  • Hi, I hope I can get some help with the following exercise in C++( CPP): 1.Write...

    Hi, I hope I can get some help with the following exercise in C++( CPP): 1.Write an additional method called push_back(int) that will add an integer to the end of the list. You can modify the provided code. 2.Modify the Node class and LinkedList class so that you can access your parent node (double linked-list). /* definition of the list node class */ class Node { friend class LinkedList; private: int value; Node *pNext; public: /* Constructors with No Arguments...

  • I wrote this code but there’s an issue with it : #include <iostream> #include <vector&...

    I wrote this code but there’s an issue with it : #include <iostream> #include <vector> #include <string> #include <fstream> using namespace std; class Borrower { private: string ID, name; public: Borrower() :ID("0"), name("no name yet") {} void setID(string nID); void setName(string nID); string getID(); string getName(); }; void Borrower::setID(string nID) { ID = nID; } void Borrower::setName(string nname) { name = nname; } string Borrower::getID() { return ID; } string Borrower::getName() { return name; } class Book { private: string...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT