Help Please!!!!

I am completely stuck on this problem.
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.
Description Units On Hand Price
Item #1 Jacket 12 59.95
Item #2 Designer Jeans 40 34.95
Item #3 Shirt 20 24.95

This is what i have so far


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
  // Includes
#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;
}


I have no idea what to do from there.
i just need to know what the operands are for lines 42 and 49 because it says that != does not work for int and double

You cant check a double or integer against a string.

Other thing I picked up on was it says "Write a constructor that accepts arguments for each member variable" - I would read that as creating a constructor to accept all three arguments and not separate ones.

I don't see anything in your description that requires validation testing. Furthermore, in the real world I wouldn't be checking inside the class and would be checking at the point of user input, and provided its valid I would then pass that data to my object.

Hope this helps.




A little example...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64

#include <iostream>
#include <string>

class RetailItem
{
private:
	std::string description;
	int unitsOnHand;
	double price;

public:
	// if we dont supply parameters
	RetailItem() {
		description = "<Empty>";
		unitsOnHand = 0;
		price = 0;
	}
	// when we do.
	RetailItem(std::string desc, int qty, double cost) {
		description = desc;
		unitsOnHand = qty;
		price = cost;
	}
	// Getters
	std::string getDescription() { return description; }
	int getUnits() { return unitsOnHand; }
	double getPrice() { return price;	}
	// Setters
	void SetDescription(std::string desc) { description = desc; }
	void SetUnits(int qty) { unitsOnHand = qty; }
	void SetPrice(double cost) { price = cost; }
};

int main()
{

	// creating this way creates three objects with
	// default data, you then need to use the setters
	// to set the data.
	RetailItem Items[3];

	// like this...
	Items[0].SetDescription("Jacket");
	Items[0].SetUnits(12);
	Items[0].SetPrice(59.95);

	// items[1].. items[2] etc.

	// or we can use the constructor to assign data.
	RetailItem Item1("Jacket", 12, 59.95);

	// ok so lets read the data we assigned using setters
	for (int i = 0; i <= 2; i++)
		std::cout << "Item: " << Items[i].getDescription() << ", Qty: " <<
		Items[i].getUnits() << ", Price: " << Items[i].getPrice() << std::endl;

	// display data we entered from the constructor
	std::cout << std::endl << "Item: " << Item1.getDescription() << ", Qty: " <<
		Item1.getUnits() << ", Price: " << Item1.getPrice() << std::endl;

	return 0;
}

Item: Jacket, Qty: 12, Price: 59.95
Item: <Empty>, Qty: 0, Price: 0
Item: <Empty>, Qty: 0, Price: 0

Item: Jacket, Qty: 12, Price: 59.95
Topic archived. No new replies allowed.