Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask DOT NET Expert

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

DOT NET, Programming

  • Category:- DOT NET
  • Reference No.:- M93083569

Have any Question?


Related Questions in DOT NET

Scenariouser modelling inc would like to organize a series

Scenario User Modelling Inc. would like to organize a series of conferences focusing on research topics in the area of user adaptive systems and personalization. They need to organize annual conferences for researchers a ...

Casewe sell pdfs from our site and pdfs can be ordered from

Case We sell pdf''s from our site and pdfs can be ordered from the site by selecting a book, putting it in a shopping cart, then signing in with a password or as a guest, and then checking out. For some reason, when a pu ...

Assignment specificationthis assignment is split into two

ASSIGNMENT SPECIFICATION This assignment is split into two documents. 1. Assignment Specification. This document contains the specification for what you will be required to do. 2. Assignment Addendum. This document conta ...

Summarythis assessment requires you to develop a simple

Summary This assessment requires you to develop a simple text editor with a basic offline user login. It is a windows application that will allow new uses to be added, existing users to login, and to create/save/edit tex ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As