Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help C++ Exercise 5-Update the displayo member function to display invent

ID: 3804628 • Letter: P

Question


Please help C++ Exercise 5-Update the displayo member function to display inventory item price, in addition to the other data members. ONote: make sure to change its name to display if you haven't done so already). Exercise 6. Update the read member function to read price, in addition to description and quantity on hand from an input stream. Note: Make sure to change its name to read (ifstream &). You may assume a simplified CSV (Comma Separated Values) format for the input: every line has the data values of onc inventory item separated by commas. Example: Iphone 6, 33, 599.000 Samsung Galaxy s6, 21,439.50 You may use the following function to read data for one inventory item: void InventoryItem: read( nFile) ifstream string line; getline(inFile, line, setDescription(line): int q; double p; char comma; inFile q; set QuantityonHand(q); infile comma; inFile p; set Price(p); inFile ignore(10e Below is a UML class diagram of class InventoryItem: Inventory Item description string qantityon Hand: int price double Inventory Item Inventory Item (string, int double) getDescription const string get QuantityOnhand const int get Price const double setDescription (string) void setQuantityOnhand (int) void set Price (double) void display const void read (ifstream 6) void.

Explanation / Answer

//Book.h

#include<iostream>
#include<string>
#include<fstream>
#include"Inventory.h"
using namespace std;
class Book : public InventoryItem
{
   string Title;
   string authorName;
   string publisher;
public:
   Book();
   Book(const Book &obj);
   virtual void display();
   void setTitle(string s);
   string getTitle() const;
   void setAuthorName(string au);
   string getAuthorName() const;
   void setPublisher(string pu);
   string getPublisher() const;
   virtual void Book::read(ifstream &inFile);
};

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

//Book.cpp

#include"Book.h"

Book::Book() :InventoryItem("",0,0)
{
   Title = "" ;
   authorName = "";
   publisher = "";
  
}
Book::Book(const Book &obj)
{
   Title = obj.getTitle();
   authorName = obj.getAuthorName();
   publisher = obj.getPublisher();
}


void Book::setTitle(string t)
{
   Title = t;
}

void Book::setAuthorName(string au)
{
   authorName = au;

}

void Book::setPublisher(string p)
{
   publisher = p;
}

void Book::display()
{
   cout << "Title: " << Title << " Athor Name:" << authorName << " Publisher: " << publisher << endl;
}

string Book::getTitle() const
{
   return Title;
}

string Book::getAuthorName() const
{
   return authorName;
}

string Book::getPublisher() const
{
   return publisher;
}

void Book::read(ifstream &inFile)
{
   string line;
   getline(inFile, line, ',');
   setTitle(line);
   getline(inFile, line, ',');
   setAuthorName(line);
   getline(inFile, line,',');
   setPublisher(line);
   getline(inFile, line, ',');
   setDescrition(line);
   int q; double p; char comma;
   inFile >> q;
   setQuantityOnhand(q);
   inFile >> comma;
   inFile >> p;
   setPrice(p);
   inFile.ignore(100, ' ');

}

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

//Inventory.h

#include<string>
#include<fstream>
#include<iostream>
using namespace std;

class InventoryItem
{
   string description;
   int quantityOnHand;
   double price;
public:
   InventoryItem();
   InventoryItem(const InventoryItem &obj) ;
   InventoryItem(string d, int q, double p);
   string getDescrition() const;
   void setDescrition(string s) ;
   int getQuantityOnhand() const;
   void setQuantityOnhand(int q) ;
   void setPrice(double price);
   double getPrice() const;
   void display();
   void read(ifstream &inFile);
};

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

//Inventory.cpp

#include"Inventory.h"
#include<string>
InventoryItem::InventoryItem()
{
   price = 0;
   description ="";
   quantityOnHand = 0;
}

InventoryItem::InventoryItem(string s, int q, double p)
{
   price = p;
   description = s;
   quantityOnHand = q;
}
InventoryItem::InventoryItem(const InventoryItem &obj)
{
   price = obj.price;
   description = obj.description;
   quantityOnHand =obj.quantityOnHand;
}


string InventoryItem::getDescrition() const
{
   return description;
}

void InventoryItem::setDescrition(string s)
{
   description = s;
}

void InventoryItem::setPrice(double p)
{
   price = p;
}

double InventoryItem::getPrice() const
{
   return price;
}

void InventoryItem::setQuantityOnhand(int q)
{
   quantityOnHand = q;
}


int InventoryItem::getQuantityOnhand() const
{
   return quantityOnHand;
}

void InventoryItem::display()
{
   cout << "Description : " << description << " quantityOnHand: " << quantityOnHand << " price: " << price << endl;
}

void InventoryItem::read(ifstream &inFile)
{
   string line;
   getline(inFile, line, ',');
   setDescrition(line);
   int q; double p; char comma;
   inFile >> q;
   setQuantityOnhand(q);
   inFile >> comma;
   inFile >> p;
   setPrice(p);
   inFile.ignore(100, ' ');

}

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

//output

Title: Progrmming in C Athor Name: Bal guru Swami Publisher: Swapna