Write a class named RetailItem that holds data about an item in a retail store.
ID: 672360 • Letter: W
Question
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.
- Create a RetailItem class with the following methods
Default construtor, overloaded constructor, setDescription, setUnitsOnHand, setPrice, getDescription, getUnitsOnHand, getPrice.
Has To Be In JAVA
item description units on hand price 1 Jacket 12 59.95 2 Designer Jeans 40 99.95 3 Shirt 20 24.95Explanation / Answer
// Includes #include #include #include 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 coutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.