Hi everybody, am having problems with this program. Can anyone help me?
Code:#include <string>
#include <iostream>
using namespace std;
class GroceryItem
{
private:
string itemStockNumber;
float price;
int quantityInStock;
float totalValue;
public:
string setItemStockNumber();
float setPrice();
float setQuantityInStock();
float setTotalValue(float price, int quantity);
void displayGrocery();
};
void main()
{
GroceryItem Grocery;
Grocery.setItemStockNumber();
Grocery.setPrice();
Grocery.setQuantityInStock();
Grocery.displayGrocery();
system ("pause");
}
string GroceryItem::setItemStockNumber()
{
int x = 0;
cout << "Please enter the item's stock number. " << endl;
cout << "The item's stock number must be a four digit number: ";
cin >> itemStockNumber;
while(x < 1)
{
if(itemStockNumber == itemStockNumber.size(4))
++x;
else
cout << "The item's stock number must be a four digit number: ";
}
return itemStockNumber;
}
float GroceryItem::setPrice()
{
cout << "Please enter the price of item # ";
cout << ": ";
cin >> price;
return price;
}
float GroceryItem::setQuantityInStock()
{
cout << "Please enter the quantity of item #";
cout << ": ";
cin >> quantityInStock;
return quantityInStock;
setTotalValue(price, quantityInStock);
}
float GroceryItem::setTotalValue(float price, int quantity)
{
totalValue = price * quantity;
return totalValue;
}
void GroceryItem::displayGrocery()
{
cout << "The item #" << itemStockNumber << "'s price is $" << price;
cout << " and has " << quantityInStock << " items in stock." << endl;
cout << "The total value of the items is $" << totalValue;
}
Thanks!