Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#ifndef INVENTORY_H_ #define INVENTORY_H_ #include // std::numeric_limits #include #include #include #include # include #include /* exit, EXIT_FAILURE */ using namespace std; // class defining the

#ifndef INVENTORY_H_ #define INVENTORY_H_ #include // std::numeric_limits #include #include #include #include # include #include /* exit, EXIT_FAILURE */ using namespace std;

// class defining the inventory

class Inventory{

private: // member variables int inventoryNumber ; string imageName ; string photogLastName ; float pricePaid ; float priceSell ; int numberSold ;

public:

Inventory();

Inventory(int inventoryNumber,string imageName,string photogLastName,float pricePaid ,float priceSell,int numberSold);

void setInventoryNumber(int inventoryNumber); void setImageName(string imageName); void setPhotogLastName(string photogLastName); void setPricePaid(float pricePaid); void setPriceSell(float priceSell); void setNumberSold(int numberSold); int getInventoryNumber(); string getImageName(); string getPhotogLastName(); float getPricePaid(); float getPriceSell(); int getNumberSold(); }; #endif /* INVENTORY_H_ */ Inventory::Inventory() { inventoryNumber =0; imageName=""; photogLastName=""; pricePaid=0; priceSell=0; numberSold=0; } // parameterized constructor

Inventory::Inventory(int inventoryNumber,string imageName,string photogLastName,float pricePaid ,float priceSell,int numberSold) { Inventory::inventoryNumber = inventoryNumber; Inventory::imageName = imageName; Inventory::photogLastName = photogLastName; Inventory::pricePaid=pricePaid; Inventory::priceSell = priceSell; Inventory::numberSold= numberSold; } // setters

void Inventory::setImageName(string imageName)

{ if(imageName.length()>25) { cout<<" Length of image name cannot be greater than 25"; exit(EXIT_FAILURE); } Inventory::imageName = imageName; } void Inventory::setInventoryNumber(int inventoryNumber)

{ if(inventoryNumber < 0){ cout<<" Inventory number cannot be less than 0"; exit(EXIT_FAILURE); } Inventory::inventoryNumber = inventoryNumber; }

void Inventory::setNumberSold(int numberSold) {

if(numberSold < 0){ cout<<" Number of prints sold cannot be less than 0"; exit(EXIT_FAILURE); } Inventory::numberSold= numberSold; }

void Inventory::setPhotogLastName(string photogLastName) { if(photogLastName.length()>25) { cout<<" Length of last name of photographer cannot be greater than 25"; exit(EXIT_FAILURE); } Inventory::photogLastName = photogLastName; } void Inventory::setPricePaid(float pricePaid)

{

if(pricePaid < 0){ cout<<" Price that the gallery paid for the print cannot be less than 0";

exit(EXIT_FAILURE); } Inventory::pricePaid=pricePaid; } void Inventory::setPriceSell(float priceSell) { if(priceSell < 0) { cout<<" Retail Price of the print cannot be less than 0"; exit(EXIT_FAILURE); } Inventory::priceSell = priceSell;

}

int Inventory::getInventoryNumber() { return inventoryNumber; } string Inventory::getImageName() { return imageName; } string Inventory::getPhotogLastName() { return photogLastName; } float Inventory::getPricePaid() { return pricePaid; } float Inventory::getPriceSell() { return priceSell; } int Inventory::getNumberSold() {

return numberSold;

}

// end of inventory.cpp

// main.cpp implementing Inventory class

using namespace std;

int main()

{

// create an array of 3 print objects

Inventory inventory[3];

int inventoryNumber ;

string imageName ;

string photogLastName ;

float pricePaid ;

float priceSell ;

int numberSold ;

// inputs

for(int i=0;i<3;i++)

{

cout<<" Enter details for Print "<<(i+1)<<":"<

cout<<" Enter inventory number : ";

cin>>inventoryNumber;

std::cin.ignore(std::numeric_limits::max(),' ');

cout<<" Enter image name : ";

getline(cin,imageName);

cout<<" Enter last name of the photographer : ";

getline(cin,photogLastName);

cout<<" Enter the price that the gallery paid for the print : $";

cin>>pricePaid;

cout<<" Enter the the retail price of the print : $";

cin>>priceSell;

cout<<" Enter the number of prints sold to date: ";

cin>>numberSold;

inventory[i].setInventoryNumber(inventoryNumber);

inventory[i].setImageName(imageName);

inventory[i].setPhotogLastName(photogLastName);

inventory[i].setPricePaid(pricePaid);

inventory[i].setPriceSell(priceSell);

inventory[i].setNumberSold(numberSold);

std::cin.ignore(std::numeric_limits::max(),' ');

}

// outputs

for(int i=0;i<3;i++)

{

cout<<" Inventory number : "<

cout<<" Image name : "<

cout<<" Photographer last name : "<

cout<<" Price paid : $"<

cout<<" Retail price : $"<

cout<<" Number of prints sold : "<

}

return 0;

}

****************************************************************************************************************************************

1.Functional Requirements: The owner of Duncan Miller Gallery does not like these EXIT_FAILURE crashes that the program causes. He thinks that it is a rather inelegant way to fix a problem. I totally agree.

Programming Requirements: Modify your code in main.cpp as follows:

When the program prompts the user for input, the code will check at that time for correct bounds. For example,

Prompt user for retail price

input retail price

while (retailPrice <0)

display error message

input retail price

end while

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

Programming Notes

Don't change anything in the member functions - we are just creating an higher-level form of validation. And yes, we are validating twice. But this stops the program from crashing with an EXIT_FAILURE and allows the users to fix their input mistakes.

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

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

Next Generation Databases NoSQLand Big Data

Authors: Guy Harrison

1st Edition

1484213300, 978-1484213308

More Books

Students also viewed these Databases questions