Please edit the code with linked lists in C++ Please provide your BookData.txt file as well BookRecord.cpp...

70.2K

Verified Solution

Question

Programming

Please edit the code with linked lists in C++

Please provide your BookData.txt file as well

BookRecord.cpp file


#include \"BookRecord.h\"
#include
#include
#include
#include
using namespace std;

BookRecord::BookRecord() {

   strcpy_s(m_sName, \"\");
   m_lStockNum = 0;
   m_iClassification = 0;
   m_dCost = 0.0;
   m_iCount = 0;
}
BookRecord::BookRecord(const char* name, long sn, int cl, doublecost) {

   strcpy_s(m_sName, name);
   m_lStockNum = sn;
   m_iClassification = cl;
   m_dCost = cost;
   m_iCount = 1;
}
BookRecord::~BookRecord() {
  
}
void BookRecord::getName(char* name) {
   for (int i = 0; i < 128; ++i)
       *name++ = m_sName[i];
}
void BookRecord::setName(const char* name) {
   strcpy_s(m_sName, name);
}
long BookRecord::getStockNum() {
   return m_lStockNum;
}
void BookRecord::setStockNum(long sn) {
   m_lStockNum = sn;
}
void BookRecord::getClassification(int& cl) {
   cl = m_iClassification;
}
void BookRecord::setClassification(int cl) {
   m_iClassification = cl;
};
void BookRecord::getCost(double* c) {
   *c = m_dCost;
};
void BookRecord::setCost(double c) {
   m_dCost = c;
};
int BookRecord::getNumberInStock() {
   return m_iCount;
}
void BookRecord::setNumberInStock(int count) {
   m_iCount = count;
}
void BookRecord::printRecord(char FileOut[128]) {
   ofstream outFile;
   outFile.open(FileOut, std::ios_base::app);
   getName(m_sName);
   getClassification(m_iClassification);
   getCost(&m_dCost);
   cout << endl << \"Name: \" << m_sName<< \" \" << \"Stock Num: \" << getStockNum() <<\" \" << \"Classification: \" << m_iClassification <<\" \" << \"Cost: \" << m_dCost << \" \" <<\"Count: \" << getNumberInStock() << \" \";
   outFile << endl << \"Name: \" <}

BookRecord.h file

#pragma once

class BookRecord {
private:
   char m_sName[128]; // stores the name of the book orperiodical
   long m_lStockNum; // stores a unique stock number forthe book or periodical
   int m_iClassification; //codes spefic informationabout the book or periodical
   double m_dCost; //stores the cost of the book orperiodical
   int m_iCount; //stores the number of copies of theitem currently in the inventory

public:
   BookRecord(); //constructor
   BookRecord(const char* name, long sn, int cl, doublecost);
   ~BookRecord(); //destructor

   void getName(char* name);
   void setName(const char* name);
   long getStockNum();
   void setStockNum(long sn);
   void getClassification(int& cl);
   void setClassification(int cl);
   void getCost(double* c);
   void setCost(double c);
   int getNumberInStock();
   void setNumberInStock(int count);
   void printRecord(char outFile[128]);
};

All requirements stated and illustrated in the excerpt from theSoftware Requirements Specification (see below) shall befollowed.

You will be required to meet ALL of the requirementsstated below.

2.1 System Organization

2.1.1

This program shall be implemented in C++ as a sorted (ordered)linked list. With nodes ordered by stock number.

2.1.2

The class used to store information on each book shall shall bethe BookRecord class developed in ProgrammingAssignment 1 with appropriate modifications so that it can be usedin a linked list.

2.1.3

All list functions shall be defined in a C++ class calledBook_Inventory. The class shall be defined asfollows:

//-----------------------------------------------------------------------------// File: Book_Inventory.h// Header file for a book inventory program implemented as a sorted linked list//// Note: All functions which print data on a book must print an appropriate//    message if it fails to find any book(s) meeting the search criteria//-----------------------------------------------------------------------------#pragma once;#include // This header lets you use cout and cin#include  // This header gives you all the file I/O functions#include#include#include \"BookRecord.h\"using namespace std; // This command lets you use all the I/O function and include headers w/o the \".h\"class Book_Inventory{  private:    BookRecord   *m_pHead;                // Pointer to the head of the list    ifstream    m_InFile;                // File containing the inventory  public:    Book_Inventory();                    // Class constructor    ~Book_Inventory();                   // Class destructor. Must free all list memory    void ClearList();                    // Remove all items from the list    bool readInventory(const char *filename);        // Read inventory file and build the list    bool addBook(BookRecord *br);              // Add the given book to the list     BookRecord *removeBook(long stockNum);         // Remove a book from the list or print message if not found    BookRecord *searchByStockNumber(long stockNum);     // Search by stock number return pointer to node or NULL if not found    void searchByClassification(int cl);          // Search for all books given classification, print all data    void searchByCost(double min, double max);       // Search for all books within the given cost range    int getNumberInStock(long sn);             // Get number of books in stock for the given stock number     void printAll();                    // Print all information on all books in the inventory.  private:    bool getNextLine(char *line, int lineLen);       // read next line from a file};

2.1.4

The BookRecord class shall have the private variableBookRecord *m_pNext, and the public functionsvoid setNext(BookRecord *next) andBookRecord *getNext() added to it

2.1.5

When data on a book is printed on the screen it shall be all ona single line in the following format:

   Title   Stock_Num   Classification   Cost   In Stock

   For example:
   Introduction toC++   12345   613   49.95   5

2.1.6

Format of the data file to be read shall be as follows:

   # Any line beginning with a pound sign shallbe ignored as a comment line
   # First non-comment line will give the number ofbooks in the file
   # Remaining lines will give the stock number,Title, classification,
   # cost and number in stock. Each shall be on aseparate line.
   # Example:
   25
   12345
   CS221 A Programming Challenge
   613
   23.95
   15
   # etc. for the remaining books in this list.

Note: Do not assume that the data file that will be usedto test your program will be the same as the exampleprovided.

2.1.7

Source code which can be adapted for use in the readInventory()function will be provided from the company Code Reuse Library.

2.1.8

The getClassification function in BookRecord shall be modifiedso that it functions as a \"normal\" get function, that isit shall return the classification value. Prototype the function asfollows:

     intgetClassification();

2.1.9

The getCost function in BookRecord shall be modified so that itfunctions as a \"normal\" get function, that is it shallreturn the cost value. Prototype the function as follows:

     doublegetCost();

Source Code Reuse Library

The following function fragment shows how to open a file andstart to read lines from the file
using the getNextLine() function. Either the Book_Inventory.h fileor the Book_Inventory.cpp
file will have to #include ,, and and include
the line using namespace std for this to work.

//--------------------------------------------// Function: readInventory()// Purpose: Read the inventory data file and//       build the list.// Returns: True if successful read//--------------------------------------------bool Book_Inventory::readInventory(const char *filename){   char   line[128];   int   numBooks;   // define other variables here as needed  m_InFile.open(filename, ifstream::in);   if(!m_InFile.is_open())  {    // m_InFile.is_open() returns false if the file could not be found or    //  if for some other reason the open failed.    cout << \"Unable to open file\" << filename << \"\nProgram terminating...\n\";    return false;  }  // Read number of books  getNextLine(line, 128);  numBooks = atoi(line);  for(int i=0; i

The atoi() (Ascii TO Integer) function is foundin stdlib.h. It takes a string
(character array) as an argument. The string must be a stringrepresentation of an
integer value. For example: \"25\". The function then parses thestring and returns
the int value represented by the string. There are also two otherfunctions in stdlib.h
which may be useful. These are atof() (Ascii TOFloat) which returns a double
value and atol() (Ascii TO Long) which returns along value.

The following function can be added to your Book_Inventory class asa private function.
It uses a class variable called m_InFile that is a reference to anopen text file (opened by
the readInventory() function) and will read the next line from thefile storing it in the
character array pointed to by line which should be a minimum of 128characters in length.
The lineLen argument gives the length of the array.getNextLine() will skip any comment lines
(those starting with #) and blank lines. It returns an empty stringafter the last line in
the file has been read.

//--------------------------------------------// Function: getNextLine() // Purpose: Read a line from a data file.//  The next non-comment line read from file//  is stored in line char array.//  An empty string is stored if the end of//  file is reached.// Returns: bool - true if a valid line was//  read, false if end of file is reached. //--------------------------------------------bool Book_Inventory::getNextLine(char *line, int lineLen){  int  done = false;  while(!done)  {    m_InFile.getline(line, lineLen);        if(m_InFile.good())  // If a line was successfully read    {      if(strlen(line) == 0) // Skip any blank lines        continue;      else if(line[0] == '#') // Skip any comment lines        continue;      else return true;  // Got a valid data line so return with this line    }    else // No valid line read, meaning we reached the end of file    {      strcpy(line, \"\"); // Copy empty string into line as sentinal value      return false;    }  } // end while  return false; // Cannot reach this point but include a return to avoid compiler warning         //  that not all paths return a value.}

Answer & Explanation Solved by verified expert
4.3 Ratings (544 Votes)
Here I am attaching code for these filesmaincppBookRecordcppBookRecordhBookInventorycppBookInventoryhmaincppinclude BookInventoryhusing namespace stdint main BookInventory Store new BookInventory BookRecord Book1 new BookRecordHello World2345 343 5645 BookRecord Book2 new BookRecordText 4561 2342345 BookRecord Book3 new BookRecordThe virtues ofstuff 2345 443 399 BookRecord Book4 new BookRecord BookRecord book new BookRecord StorereadInventoryBookDatatxt StoreaddBookBook1 StoreaddBookBook3 StoreaddBookBook2 StoreprintAll coutprintRecord return 0BookRecordcppinclude BookRecordhinclude using namespace    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students