Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

implement read, write, load, save and a billPrint function in item.cpp I need some help please. the main.cpp handles all the names, sku prices, taxes

 implement read, write, load, save and a billPrint function in item.cpp I need some help please. the main.cpp handles all the names, sku prices, taxes and qty of the products. I just need to input these functions to work with the main.cpp to get the correct outputs.

IO

Implement the four pure virtual methods of the base class as follows:

virtual std::ostream& write(std::ostream& os) const = 0;

virtual std::istream& read(std::istream& is) = 0;

virtual std::ofstream& save(std::ofstream& ofs) const = 0;

virtual std::ifstream& load(std::ifstream& ifs) = 0;

MAX_SKU_LEN: 7

MAX_NAME_LEN: 40

 

 POS_LIST: 1

 POS_FORM: 2

 

 ERROR_POS_SKU: "SKU too long"

 ERROR_POS_NAME: "Item name too long"

 ERROR_POS_PRICE: "Invalid price value"

 ERROR_POS_TAX: "Invalid tax status"

 ERROR_POS_QTY: "Invalid quantity value"

 ERROR_POS_STOCK: "Item out of stock"

 ERROR_POS_EMPTY: "Invalid Empty Item"

#### write

1. If in POS_LIST mode, it will print the object as follows:

```text

1234   |Screw Driver        |  12.32| X |  90|  1252.94|

4567   |Tape Measure - Level| 112.30|   |  10|  1123.00|

```

- Name: if longer than 20 characters, only the first 20 will be printed

- Taxed: if true `X` is printed or else space

- After the line is printed, no newlines are printed.

 

2. If in POS_FORM mode, it will print as follows:

```text

=============v

Name:        Screw Driver

Sku:         1234

Price:       12.32

Price + tax: 13.92

Stock Qty:   90

=============v

Name:        Tape Measure - Level - Laser - Combo

Sku:         4567

Price:       112.30

Price + tax: N/A

Stock Qty:   10

```

- At the end, a newline is printed.

3. If the Item is erroneous only the error object is printed (with no newline after).

 

In the end, the ostream reference is returned.

 

#### save

Save the data in a comma-separated format as follows:

First, the [itemType](#itemtype-query) is printed and then all the attributes are saved separated by commas. No newline is saved at the end.

In the following example, we assume the derived class's [itemType](#itemtype-query) function is returning 'T'.

```text

T,1234,Screw Driver,12.32,1,89

T,4567,Tape Measure - Level - Laser - Combo,112.30,0,9

```

If the Item is erroneous the error object is inserted into `cerr` and not the ofstream  (with a newline after).

 

In the end, the ofstream reference is returned.

 

#### read

Performs fool-proof data entry.

 

The attributes are read in the following order:

SKU, Name, Price, Taxed or not and Quantity.

 

After each data entry, the value is validated, if invalid the [proper error message](#additional-constant-values) is printed and in the next line at the prompt (`>`) the value is re-entered. This repeats until a valid value is entered. See [Execution Sample](#execution-sample).

 

In the end, the reference of istream is returned.

 

```text

Sku

> 12345

Name

> Hammer

Price

> 23.99

Taxed?

(Y)es/(N)o: y

Quantity

> 35

```

 

 

#### load

First, the error status will be [clear](#clear-1)ed

 

Then reads all the values from the ifstream object in a comma-separated format (assuming the data begins with the SKU) in local variables (not directly into the attributes of the item). 

 

If after the reading the ifstream is not in a failure state, it will validate the values one by one and if any of the validation fails, the error message is set to the proper message and validation stops.

 

At the end of the validation process, if there is no error, the attributes are set to the validated values.

 

The reference of the ifstream object is returned at the end.

 

#### billPrint

This function will receive and return the ostream object.

The bill print function will only print the Name, taxed price, and if the item is taxed or not:

```text

| Screw Driver        |     13.92 |  T  |

| Tape Measure - Level|    112.30 |     |

```

- Name: only the first 20 characters are printed

- Taxed: if the item is taxed, `T` and otherwise, a space is printed.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Entrepreneurship Theory Process Practice

Authors: Donald F. Kuratko

11th Edition

0357033892, 978-0357033890

More Books

Students also viewed these Databases questions

Question

Why should a business plan be updated?

Answered: 1 week ago