Write a stub for each member function of class book you can


PLEASE HELP IN

This Program is C++ (Microsoft Visual Studio)

Consider the following scenario: Company allForSale.com is an online store that sells several types of products online including books, electronic items (cell phones, notebooks, laptops, cameras, etc), and small home appliances.

The company hires you to write a program to manage its inventory. Your first thought is to create a class to represent each type of inventory sold by the company.

However, you quickly realize that all inventory items have several common attributes such as product description, price, and quantity on hand. So you decide to use the InventoryItem class defined in Lab 4 as a based class (with necessary changes).

In this lab, you will (1) modify class InventoryItem to include a price data member and (2) defined a derived class of InventoryItem to represent books.

Task 1: Add a data member to class InventoryItem

Exercise 1.Add a data member to class InventoryItem to represent the item's price

Exercise 2.Update the class constructors to initialize the price data member

Exercise 3.Add an accessor (getPrice) that returns the value of price and a mutator to set it (setPrice).

Exercise 4.Use the new accessor function to test the class constructors and setPrice().

Exercise 5.Update the display() member function to display inventory item price, in addition to the other data members. (Note: 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 one inventory item separated by commas. Example: Iphone 6, 33, 599.00

Samsung Galaxy s6, 21, 439.50

You may use the following function to read data for one inventory item:

void InventoryItem::read(ifstream &inFile)

{ string line;

getline(inFile, line, ',');

setDescription(line);

int q; double p; char comma; inFile >> q;

setQuantityOnHand(q);

inFile >> comma;

inFile >> p;

setPrice(p);

inFile.ignore(100, '\n');

}

Below is a UML class diagram of class InventoryItem:

InventoryItem

- description: string

- qantityOnHand:

int - price: double

+ InventoryItem()

+ InventoryItem(string, int, double)

+ getDescription() const: string

+ getQuantityOnhand() const: int

+ getPrice() const : double

+ setDescription(string): void

+ setQuantityOnhand(int): void

+ setPrice(double): void

+ display() const: void

+ read(ifstream &): void

Task 2: Derived class Book

Exerise 1. Declare a class Book as a derived class of InventoryItem. You only need to do the class specification in this task. Write a specification in a header file called Book.h. Make sure to include InventoryItem.h file from Task 1. Exerise 2. class Book should have the following data members:

-Title

-Name of author (assume only one author for now)

-Publisher

Exerise 3. Write the prototypes of the following member functions in class Book

-A default constructor that initializes the above data members to default values of your choice and uses the default constructor of the base class

- Accessor and mutator functions for book title, author, and publisher

-A parametrized constructor that initializes all data members including description, price, and quantity on hand. Remember to use as much of the code from the base class and to use the set functions to set data members.

- A member function display to display all attributes of a book

- A member function read to read all attributes of a book from an input stream.

Exerise 4. Draw a UML class diagram of class Book

Task 3: Incremental implementation and testing

Exercise 1. Write a stub for each member function of class Book. You can this either in Book.h or in a separate implementation file (Book.cpp). A function stub consists of the function header and an empty body if the function is a void function. For valuereturning functions, have the function return a dummy value.

Exercise 2.Write a driver program to test your new class. In function main() of the driver program, declare one instance of class Book. Build your project and fix all syntax errors.

Exercise 3.Incrementally implement the member functions of class Book. Each time you implement a function test it. Start with the set functions, then implement the get functions. Use the get function to test the set functions. Then implement and test the constructors. Finally, implement and test the display and read member functions. When implementing your class, you need to adhere to the following practices:

1. Use code from the base class whenever possible

2. Any changes to the data members should be done using the class set functions.

Task 4: Final testing of Book class

Exercise 1. Use the driver program below to test your Book class. Make sure to include the header file with the Book class you defined in the previous tasks.

//*******************************************************

// Driver program to test class Book.

// Note that it uses the vector class from the Standard Template Library

// to create a dynamic list of Book instances

#include

#include

#include

#include

#include

#include "Book.h"

using namespace std;

int main()

{

ifstream file("data.csv"); //Assume the name of input file is "data.csv"

if (!file)

{

cerr <<"Can't open file "<<

"data.csv"<< endl;

return (EXIT_FAILURE);

}

vectorbookList; Book

temp; while (file)

{ temp.read(file);

bookList.push_back(temp);

}

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

bookList[i].display();

system("pause");

return 0;

}

Demo your lab using the driver program above

Request for Solution File

Ask an Expert for Answer!!
DOT NET Programming: Write a stub for each member function of class book you can
Reference No:- TGS02889555

Expected delivery within 24 Hours