Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C++ Overload the operator < < for class InventoryItem. The overloaded operator will allow printing the content of an InventoryItem object following the example

In C++

Overload the operator << for class InventoryItem. The overloaded operator will allow printing the content of an InventoryItem object following the example format bellow:

Inventory Item: description=Mars chocolate bar, unit cost=1.09$, quantity is stock=5

InventoryItem.h

class InventoryItem

{

public:

static int number_articles;

// Constructor

InventoryItem(char *desc, double c, int u);

// Destructor

~InventoryItem();

const char *getDescription() const;

double getCost() const;

int getUnits() const;

static int getNumberArticles();

private:

char *description; // The item description

double cost; // The item cost

int units; // Number of units on hand

};

InventoryItem.cpp

#include "InventoryItem.h"

using namespace std;

InventoryItem::InventoryItem(char *desc, double c, int u)

{

description = desc;

cost = c;

units = u;

number_articles++;

}

InventoryItem::~InventoryItem()

{

}

const char *InventoryItem::getDescription() const

{

return description;

}

double InventoryItem::getCost() const

{

return cost;

}

int InventoryItem::getUnits() const

{

return units;

}

int InventoryItem::getNumberArticles(){

return number_articles;

}

test_main.cpp

#include "InventoryItem.h"

#include

using namespace std;

int InventoryItem::number_articles = 0;

int main()

{

char item[] = "Apples";

InventoryItem i1 = InventoryItem(item, 10.09, 5);

cout << "Item Details-";

cout << " Description: " << i1.getDescription();

cout << " Cost: " << i1.getCost();

cout << " Units: " << i1.getUnits();

cout<<" Number of articles: "<

cout<

return 0;

}

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

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

4th Edition

0805360476, 978-0805360479

More Books

Students also viewed these Databases questions

Question

In C++ Overload the operator Answered: 1 week ago

Answered: 1 week ago

Question

Have issues been prioritized?

Answered: 1 week ago

Question

Has the priority order been provided by someone else?

Answered: 1 week ago

Question

Compare the current team to the ideal team.

Answered: 1 week ago