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

Write a windows console application that holds data about an item in a retail st

ID: 3867225 • Letter: W

Question

Write a windows console application that holds data about an item in a retail store.

Your class should be named RetailItem and should hold data about an item in a retail store. The class will have the following member variables.

Description - string holding the description of the item,

unitsOnHand - int that holds the number of units in inventory

Price - double that holds the price of the item

You will need two constructors, one that will accept arguments for each member variable and one that will assign default values. You will also need to write mutator functions and accessor functions. Once you write the class, write a separate program that creates three RetailItem objects. The first one should use the default values, and the other two should have values assigned upon creation. The user should input the variables (testing for the units on hand and price greater than 0).

Then, the program should display all three RetailItems. Finally, the program should tally the inventory for all three items and display it.

Welcome to the Retail store!

Price must be greater than 0.

Please enter the price for item 1: 33

Inventory must be greater than 0.

Please enter the units on hand for item 1: 10

Please enter the description for item 1: shirt

Display all items

Description: shirt

Units on hand: 10

Price: $33.00

Description: Jeans

Units on hand: 40

Price: $34.95

Description: Long sleeve shirt

Units on hand: 20

Price: $24.95

Display the total inventory.

The total inventory is 70.

Press any key to continue.

Be sure to think about the logic and design first, then code the C++ program.

Explanation / Answer

#include<iostream>
#include<string>

using namespace std;

class RetailItem {

    private:
        string description;
        int unitsOnHand;
        double price;
    public:
        RetailItem(){
            description = "";
            unitsOnHand = 0;
            price = 0.0;
        }
        RetailItem(string desc, int un, double pr){
            description = desc;
            unitsOnHand = un;
            price = pr;
        }
        void setDescription(string desc){
               description = desc;
        }
        void setUnitsOnHand(int a){
               unitsOnHand = a;
        }
        void setPrice(double a){
               price = a;
        }
        string getDescription(){
               return description;
        }
        int getUnitsOnHand(){
               return unitsOnHand;
        }
        double getPrice(){
               return price;
        }

};

int main(){
   RetailItem rt1;
   RetailItem *data[200];
   char ch;
   int itemcount;
   int total_inventory;
   int choice;
   int valid;
   double price;
   string desc;
   int inventory_count;

   itemcount = 0;
   total_inventory = 0;
   do {
        cout << "Welcome to the Retail store!" << endl<<endl;
        cout << "1.Enter an item ";
        cout << "2.Display all items ";
        cout << "3.Display Inventory ";
        cout << "4.Quit ";
        cout << "Enter your choice: ";
        cin >> choice;       
     
        switch(choice) {
            case 1:
                  valid = 0;
                  do {
                     cout << "Price must be greater than 0 ";
                     cout << "Please enter the price of item " <<itemcount+1 << endl;
                     cin >> price;
                     if (price > 0)
                         valid = 1;
                  } while (valid == 0);
                  do {
                     cout << "Inventory must be greater than 0 ";
                     cout << "Please enter units on hand for item " <<itemcount+1 << endl;
                     cin >> inventory_count;
                     if (inventory_count > 0)
                         valid = 1;
                  } while (valid == 0);
                  cout << "Please enter the description for item " << itemcount+1 << endl;
                  cin.ignore();
                  getline(cin,desc);
                 
                  data[itemcount] = new RetailItem(desc, inventory_count, price);               
                  itemcount++;
                  total_inventory = total_inventory + inventory_count;
                  break;
           case 2:
                  for (int i = 0; i<itemcount; i++){
                       cout << "Description:" << data[i]->getDescription() << endl;
                       cout << "Units on hand:" << data[i]->getUnitsOnHand() << endl;
                       cout << "Price:" << "$" << data[i]->getPrice() << endl;
                  }
                  break;
          case 3:
                  cout << "Total Inventory : " << total_inventory << endl;
                  break;
        }
   }while (choice != 4);
  

   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote