I am a newbie when it comes to classes in C++, and I have to create a program that uses a class involved with retail items at a store. I have to create three items under this class with class members containing the item description, units, and price.
#include "stdafx.h"
#include <iostream>
#include <string>
#include "RetailItem.h"
usingnamespace std;
int main()
{
RetailItem item1, item2, item3;
string name;
int units;
double price;
cout << "Welcome to the Retail store!" << endl;
//Item 1
//Price
cout << "Please enter the price for item 1: ";
cin >> price;
while (price <= 0)
{
cout << "Price must be greater than 0." << endl;
cout << "Please enter the price for item 1: ";
cin >> price;
}
item1.setPrice(price); //Mutator Method
//Inventory
cout << "Please enter the units on hand for item 1: ";
cin >> units;
while (units <= 0)
{
cout << "Inventory must be greater than 0." << endl;
cout << "Please enter the units on hand for item 1: ";
cin >> units;
}
item1.setUnits(units); //Mutator Method
//Description
cout << "Please enter the description for item 1: ";
cin >> name;
item1.setName(name); //Mutator Method
//Item 2
//Price
cout << "Please enter the price for item 2: ";
cin >> price;
while (price <= 0)
{
cout << "Price must be greater than 0." << endl;
cout << "Please enter the price for item 2: ";
cin >> price;
}
item2.setPrice(price); //Mutator Method
//Inventory
cout << "Please enter the units on hand for item 2: ";
cin >> units;
while (units <= 0)
{
cout << "Inventory must be greater than 0." << endl;
cout << "Please enter the units on hand for item 2: ";
cin >> units;
}
item2.setUnits(units); //Mutator Method
//Description
cout << "Please enter the description for item 2: ";
cin >> name;
item2.setName(name); //Mutator Method
//Item 3 has Default Values.
//Display Items
cout << endl << endl;
cout << "Display all items" << endl;
//Item 1
cout << "Description: " << item1.getName << endl;
cout << "Units on hand: " << item1.getUnits << endl;
cout << "Price: $" << item1.getPrice << endl << endl;
//Item 2
cout << "Description: " << item2.getName << endl;
cout << "Units on hand: " << item2.getUnits << endl;
cout << "Price: $" << item2.getPrice << endl << endl;
//Item 3
cout << "Description: " << item3.getName << endl;
cout << "Units on hand: " << item3.getUnits << endl;
cout << "Price: $" << item3.getPrice << endl;
return 0;
}
I keep getting the error 'RetailItem::getName': non-standard syntax; use & to create a pointer to member from lines 82 to 92 for all of my getName, getUnits, and getPrice methods. I am not sure what to do. Thank you for your time.