ONLY NEED HELP ON PART 2! Part 1 is on the bottom for reference. Using visual st
ID: 3733188 • Letter: O
Question
ONLY NEED HELP ON PART 2! Part 1 is on the bottom for reference. Using visual studio community 2017 for c++ data structures
CH 13 PART 2
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.
--------------------------
Submit to us:
1. all the files
Chapter 13 Programming Assignment Part 1:
************ADVISORY***************
Before you even start on this program, you need to know that C++ programs that use both cin and getline have problems because cin ignores the in the input stream and then if you use a getline after it to input a string it will pick up that . And you will be left scratching your head.
So, if you are using them together (as you will in this program) use a cin.ignore(); after your cin and it will clear out the input buffer. Easy peasy. There's lots of information about this on the web - check it out if you want a more detailed explanation.
************END OF ADVISORY*****
Functional Requirements:
Design an inventory class that can hold data for fine art prints created sold by Duncan Gallery.
Programming Requirements:
Design an inventory class that can hold information and calculate data for fine art prints created sold by Duncan Gallery. All the member variables will be private and all the member functions will be public.
Member Variables: Description (all are private)
inventoryNumber a positive int that holds the item's inventory number (must be positive)
imageName a string that holds the image name (< 25 characters)
photogLastName a string that holds last name of the photographer (<25 chars)
pricePaid a float >=0 that holds the price that the gallery paid for the print
priceSell a float >=0 that holds the retail price of the print
numberSold an int>=0 that holds the number of prints sold to date
Member Functions Description (all are public)
Default Constructor sets all the member variables to 0 or to ""
Constructor #2 accepts a print's inventoryNumber, imageName, photogLastName, etc... The function should copy these values to the appropriate variables.
-----------------
setInventoryNumber accepts an integer argument that is copied to the inventoryNumber member - (if <0 then EXIT_FAILURE)
setImageName accepts a string argument that is copied to the imageName member (if len>25 then EXIT_FAILURE)
setPhotogLastName accepts a string argument that is copied to the photogLastName member (if len>25 then EXIT_FAILURE)
setPricePaid accepts a float argument that is copied to the pricePaid member (if <0 then EXIT_FAILURE)
setPriceSell accepts a float argument that is copied to the priceSell member (if <0 then EXIT_FAILURE)
setNumberSold accepts an int argument that is copied to the numberSold member (if<0 then EXIT_FAILURE)
------------------
getInventoryNumber returns the value in imageNumber variable
getImageName returns the value in imageName variable
getPhotogLastName etc....
getPricePaid
getPriceSell
----------------------
Make sure to review "Rectangle. cpp(Version 1)" for an example of exit_failure. Remember, your data is protected by it's member functions. You can't trust anybody!
------------------------------------
Demonstrate the class in main() as follows:
1. create an array of 3 print objects
2. use the default constructor that initializes everything to 0 or "".
3. use a for loop to move through each object in the array. for each object, input user data and use the mutator functions to set the data.
4. once step 3 is totally completed, create another for loop and display the data for each object by having main call it's associated accessor function.
5. make your output look professional - use the iomanip library to help you.
------------------------------------
Submit to me the following files and URL
1. main. cpp
2. inventory.h
3. inventory. cpp
4. a URL to a live jing that shows me that your code is working. Don't forget to show us validation - show us some exit_failures.
Explanation / Answer
ScreenShot
---------------------------------------------------------------------------------------------------------------------------------------
code
//Header file
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
//Inventory class
class inventory {
//member variables
private:
int inventoryNumber, numberSold;
string imageName, photogLastName;
float pricePaid, priceSell;
//member functions
public:
//Default constructor
inventory() {
inventoryNumber = 0;
imageName ="";
photogLastName ="";
pricePaid = 0.0;
priceSell = 0.0;
numberSold = 0;
}
//Mutators
void SetinventoryNumber(int iNumber) {
inventoryNumber = iNumber;
}
void SetimageName(string iName) {
imageName = iName;
}
void SetphotogLastName(string pLName) {
photogLastName = pLName;
}
void SetpricePaid(float pPaid) {
pricePaid = pPaid;
}
void SetpriceSell(float pSell) {
priceSell = pSell;
}
void SetnumberSold(int nSold) {
numberSold = nSold;
}
//Accessors
int GetinventoryNumber() {
return inventoryNumber;
}
string GetimageName() {
return imageName;
}
string GetphotogLastName() {
return photogLastName;
}
float GetpricePaid() {
return pricePaid;
}
float GetpriceSell() {
return priceSell;
}
int GetnumberSold() {
return numberSold;
}
//Print method
void print() {
cout << setfill(' ') << setw(25) << "Inventory Number = " << inventoryNumber << endl;
cout << setfill(' ') << setw(25) << "Image Name = " << imageName << endl;
cout << setfill(' ') << setw(25) << "Photog Last Name = " << photogLastName << endl;
cout << setfill(' ') << setw(25) << "Price Paid = " << pricePaid << endl;
cout << setfill(' ') << setw(25) << "Price Sell = " << priceSell << endl;
cout << setfill(' ') << setw(25) << "Number Sold = " << numberSold << endl;
}
};
//main method
int main()
{
//object creation
inventory myInventory;
//variable declaration
int iNumber, nSold;
string iName, pLastName;
float pPaid, pSell;
//User input and exit_crash
cout << "Please enter the Inventory Number : ";
cin >> iNumber;
while (iNumber < 0) {
cout << "Inventory number should be positive...Please enter again";
cout << "Please enter the Inventory Number : ";
cin >> iNumber;
}
cout << "Please enter the Image Name : ";
//getline(cin, iName);
//cin.ignore();
cin >> iName;
cin.ignore();
while (iName.size()>25) {
cout << "Image Name should be less than or equal to 25 characters...Please enter again";
cout << "Please enter the Image Name : ";
cin >> iName;
cin.ignore();
//getline(cin, iName);
//cin.ignore();
}
cout << "Please enter the Photog Last name : ";
//getline(cin,pLastname);
//cin.ignore();
cin >>pLastName;
cin.ignore();
while (pLastName.size()>25) {
cout << "Photog Last name should be less than or equal to 25 characters...Please enter again";
cout << "Please enter the Photog Last name : ";
cin >> pLastName;
cin.ignore();
//getline(cin,pLastname);
//cin.ignore();
}
cout << "Please enter the Price paid : ";
cin>>pPaid;
while (pPaid<0) {
cout << "Price paid should be greater than or equal to 0...Please enter again";
cout << "Please enter the Price paid : ";
cin >> pPaid;
}
cout << "Please enter the Price sell : ";
cin >> pSell;
while (pSell<0) {
cout << "Price sell should be greater than or equal to 0...Please enter again";
cout << "Please enter the Price sell : ";
cin >> pSell;
}
cout << "Please enter the Number of sold : ";
cin >> nSold;
while (nSold<0) {
cout << "Number of sold should be greater than or equal to 0...Please enter again";
cout << "Please enter the Number of sold : ";
cin >> nSold;
}
//Set new values
myInventory.SetimageName(iName);
myInventory.SetinventoryNumber(iNumber);
myInventory.SetpricePaid(pPaid);
myInventory.SetpriceSell(pSell);
myInventory.SetphotogLastName(pLastName);
myInventory.SetnumberSold(nSold);
//call print method
myInventory.print();
return 0;
}
----------------------------------------------------------------------------------------------
Note:-
* i am using visual studio 2017.
*As per my understanding, you need a validation check for the user input.
* Go through the program,need extra requrements,let me know
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.