Using C++ to write a class named ClothingItem that holds data about an item in a
ID: 3710610 • Letter: U
Question
Using C++ to write a class named ClothingItem 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. Write an appropriate input function that asks the user to enter three member variables and store the values entered. Write an appropriate output function
Explanation / Answer
#include <iostream>
#include <string>
using namespace std;
class ClothingItem
{
string description;
int unitsOnHands;
double retailPrice;
public:
//constructor
ClothingItem(string desc, int units, double rPrice)
{
description = desc;
unitsOnHands = units;
retailPrice = rPrice;
}
//input function
void getClothingItemData(){
cout<<" Enter brief description of item";
getline(cin, description);
cout<<" Enter number of units currently in inventory";
cin>>unitsOnHands;
cout<<" Enter item's retail price";
cin>>retailPrice;
}
//output function
void dsplayClothingData(){
cout<<" Description :"<<description;
cout<<" Units On Hands :"<<unitsOnHands;
cout<<" Retail price :"<<retailPrice;
}
};
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.