Needs to be in C++ Retail Item Class Write a class named Retailltem that holds d
ID: 3740988 • Letter: N
Question
Needs to be in C++
Retail Item Class Write a class named Retailltem 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 that store values in these member variables, and accessor functions that return the values in these member variables. Once you have written the class, write a separate program that creates three Retailltem objectives and stores the following data in them Item #1 Item #2 Item #3 Description Jacket Designer Jeans Shirt Units On Hand 12 40 20 Price 59.95 34.95 24.95Explanation / Answer
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
// Define the RetailItem class
class RetailItem
{
// Private Members
private:
string description; // Stores the description of the item
int unitsOnHand;
double price;
// Public Members
public:
// Constructors
RetailItem(string d) // A constrcutor is a function that is called when an object is created.
{
description = d;
}
RetailItem(int u)
{
unitsOnHand = u;
}
RetailItem(double p)
{
price = p;
}
// Mutators
void setDesrciption(string d) // setDesrciption Member Function - assigns a value to the private member "description"
{
if (d != "") // Input Validatation: Verfiy that the description passed in was not blank.
{
description = d;
}
}
void setUnitsOnHand(int u)
{
if (u != "")
{
unitsOnHand = u;
}
}
void setPrice(double p)
{
if (p != "")
{
price = p;
}
}
// Accessors
string getDesrciption() // getDesciption Member Function - returns the value stored in the private member description
{
return description;
}
int getUnitsOnHand()
{
return unitsOnHand;
}
double getPrice()
{
return price;
}
};
// Main Function
int main()
{
// Create a new object of type RetailItem, called item1. Pass "Jacket" to the constructor's parameter to set the description to "Jacket".
RetailItem item1("Jacket");
// Call item1's accessor function getDesciption
cout << item1.getDesrciption() << endl;
// Call item1's mutator function setDesciption. Set the description to "Shoes".
item1.setDesrciption("Designer Jeans");
// Call item1's accessor function getDesciption again. This time "Shoes" will print to the screen since we changed the value of the description to "Shoes".
cout << item1.getDesrciption() << endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.