Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Programming Assignment -part one Programming Assignment part one Before you even

ID: 3730636 • Letter: P

Question

Programming Assignment -part one

Programming Assignment part one

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.

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

program asingment 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 mistake

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

Explanation / Answer

#include<iostream>
#include<string>
#include<cstdlib>

using namespace std;

class Inventory{
   private:
     int inventoryNumber;
     string imageName;
     string photogLastName;
     float pricePaid;
     float priceSell;
     int numberSold;
   public:
     Inventory(){
        inventoryNumber = 0;
        imageName = "";
        photogLastName = "";
        pricePaid = 0;
        priceSell = 0;
        numberSold = 0;
       
     }
     Inventory(int in, string img, string p, float pp, float ps,int n){
        inventoryNumber = in;
        imageName = img;
        photogLastName = p;
        pricePaid = pp;
        priceSell = ps;
        numberSold = n;
     }
     void setInventoryNumber(int a){
        if (a >= 0)
           inventoryNumber = a;
        else
           EXIT_FAILURE;
     }
     void setImageName(string a){
        if (a.size() <= 25)
           imageName = a;
        else
           EXIT_FAILURE;
     }
     void setPhotogLastName(string a){
        if (a.size() <= 25)
           photogLastName = a;
        else
           EXIT_FAILURE;
     }
     void setPricePaid(float a){
        if (a >= 0)
           pricePaid = a;
        else
           EXIT_FAILURE;
     }
     void setPriceSell(float a){
        if (a >= 0)
           priceSell = a;
        else
           EXIT_FAILURE;
     }
     void setNumberSold(int a){
        if (a >= 0)
           numberSold = a;
        else
           EXIT_FAILURE;
     }

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

};

int main(){
   
    Inventory data[3];

    for(int i = 0; i < 3; i++){
       cout << data[i].getInventoryNumber() << endl;
       cout << data[i].getImageName() << endl;
       cout << data[i].getPhotogLastName() << endl;
       cout << data[i].getPricePaid() << endl;
       cout << data[i].getPriceSell() << endl;
       cout << data[i].getNumberSold() << endl;
       cout << "--------------------------------------- ";
    }


       data[0].setInventoryNumber(1);
       data[0].setImageName("inmae1");
       data[0].setPhotogLastName("plastname1");
       data[0].setPricePaid(100.0);
       data[0].setPriceSell(200.0);
       data[0].setNumberSold(100);

       data[1].setInventoryNumber(2);
       data[1].setImageName("inmae2");
       data[1].setPhotogLastName("plastname2");
       data[1].setPricePaid(100.0);
       data[1].setPriceSell(200.0);
       data[1].setNumberSold(100);

       data[2].setInventoryNumber(3);
       data[2].setImageName("inmae3");
       data[2].setPhotogLastName("plastname3");
       data[2].setPricePaid(100.0);
       data[2].setPriceSell(200.0);
       data[2].setNumberSold(100);
   
   
    for(int i = 0; i < 3; i++){
      
       cout << data[i].getInventoryNumber() << endl;
       cout << data[i].getImageName() << endl;
       cout << data[i].getPhotogLastName() << endl;
       cout << data[i].getPricePaid() << endl;
       cout << data[i].getPriceSell() << endl;
       cout << data[i].getNumberSold() << endl;
       cout << "--------------------------------------- ";
      
    }
   
    return 0;

}

/*


Part 2

EXIT_FAILURE is replaces with

cout << "Invalid data ";

*/