I am really programming illiterate I have no idea how to cre
I am really programming illiterate. I have no idea how to create the Form for this question. Therefore I am lost on where to even start with coding. Here is the problem.
RetailItem Class
Write a class named RetailItem that holds data about an item in a retail store. The
class should have the following properties:
• Description —The Description property should hold a brief description of the
item.
• UnitsOnHand —The UnitsOnHand property should hold the number of units
currently in inventory.
• Price —The Price property should hold the item’s retail price.
Write a constructor that accepts arguments for each property.
The application should create an array of three RetailItem objects containing the
following data:
Description Units on Hand Price
Item 1 Jacket 12 59.95
Item 2 Jeans 40 34.95
Item 3 Shirt 20 24.95
The application should have a loop that steps through the array, displaying each
element’s properties.
Solution
Answer:
/*
Write a class named RetailItem that holds data about an item in a retail store. The class should have the following member variables:
• description. A string that holds a brief description of the item.
• unitsOnHand. An int that holds the number of units currently in inventory.
• price. A double that holds the item’s retail price.
Write a constructor that accepts arguments for each member variable, appropriate mutator functions (setters) that store values in these member variables, and accessor functions (getters) that return the values in these members variables. Once you have written the class, write a separate program that creates three RetailItem objects and stores the following data in them.
Description Units On Hand Price
Item #1 Jacket 12 59.95
Item #2 Designer Jeans 40 34.95
Item #3 Shirt 20 24.95
**/
// Includes
#include <iostream>
#include <string>
// Define the RetailItem class
class RetailItem
{
// Private Members
private:
std::string description; // Stores the description of the item
int unitsOnHand;
double price;
// Public Members
public:
// Constructors
RetailItem() // A constrcutor is a function that is called when an object is created
{
description = \"<Empty>\";
unitsOnHand = 0;
price = 0;
}
RetailItem(std::string desc, int qty, double cost) {
description = desc;
unitsOnHand = qty;
price = cost;
}
// Getters
std::string getDescription() // getDesciption Member Function - returns the value stored in the private member description
{ return description; }
int getUnits() { return unitsOnHand; }
double getPrice() { return price; }
// Setters
void SetDescription(std::string desc) // setDesrciption Member Function - assigns a value to the private member \"description\"
{ description = desc; }
void SetUnits(int qty) { unitsOnHand = qty; }
void SetPrice(double cost) { price = cost; }
};
// Main Function
int main()
{
// creating this way creates three objects with
// default data, you then need to use the setters
// to set the data.
RetailItem Items[3];
Items[0].SetDescription(\"Jacket\");
Items[0].SetUnits(12);
Items[0].SetPrice(59.95);
// items[1].. items[2] etc.
// use the constructor to assign data.
RetailItem Item1(\"Jacket\", 12, 59.95);
// read the data we assigned using setters
for (int i = 0; i <= 2; i++)
std::cout << \"Item: \" << Items[i].getDescription() << \", Qty: \" <<
Items[i].getUnits() << \", Price: \" << Items[i].getPrice() << std::endl;
// display data we entered from the constructor
std::cout << std::endl << \"Item: \" << Item1.getDescription() << \", Qty: \" <<
Item1.getUnits() << \", Price: \" << Item1.getPrice() << std::endl;
return 0;
}

