I need help with this C++ pseudocode

Write a windows console application that holds data about an item in a retail store. Your class should be named RetailItem and should hold data about an item in a retail store. The class will have the following member variables:
description - string holding the description of the item,
unitsOnHand – int that holds the number of units in inventory
price – double that holds the price of the item

You will need two constructors, one that will accept arguments for each member variable and one that will assign default values. You will also need to write mutator functions and accessor functions. Once you write the class, write a separate program that creates three RetailItem objects. The first one should use the default values and the other two should have values assigned upon creation. The user should input the variables (testing for the units on hand and price greater than 0). Then the program should display all three RetailItems. Finally the program should tally the inventory for all three items and display it.

You will create a RetailItem class, a main program and a RetailItem.h for a total of three files as a demonstration of understanding, creating, and using classes.

Create a Main program
Create three RetailItem objects
Ask user for price for item1 looping until value is greater than 0
Ask user for unitsOnHand for item2 looping until value is greater than 0
Ask user for description for item 1
Display all items
Add up total inventory and display total inventory

Create a RetailItem Class
Implement all member functions
Create a RetailItem.h
Private member variables should be description, unitsOnHand, and price
Public member functions include both constructors, and mutator and accessor functions for all three variables
I have already coded the following:

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
//Create a RetailItem Class
	class RetailItem {
	private:
		string description;
		int unitsOnHand;
		double price;

	public:
		//Constructor 
		RetailItem(string descriptionGiven, int unitsOnHandGiven, double priceGiven) {
			description = descriptionGiven;
			unitsOnHand = unitsOnHandGiven;
			price = priceGiven;
		}

		//Mutators
		void setDescription(string userDescription) {
			description = userDescription;
		}
		void setUnitsOnHand(int userUnitsOnHand) {
			unitsOnHand = userUnitsOnHand;
		}
		void setPrice(double userPrice) {
			price = userPrice;
		}
		//Accessors
		string getDescription() {
			return description;
		}
		int getUnitsOnHand() {
			return unitsOnHand;
		}
		double getPrice() {
			return price;
		}
	};


My question is in the main program should I be using a while loop when asking the user for prices of the items?
-- Ask user for price for item1 looping until value is greater than 0
Ask user for unitsOnHand for item2 looping until value is greater than 0
Last edited on
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
#include <iostream>
#include "stdafx.h"
#include <string>

using namespace std;

int main()
{
	string description = "";
	int unitsOnHand;
	double price;

	//Create three RetailItem objects
	RetailItem item1 = new RetailItem("Jacket", 120, 59.99);
	RetailItem item2 = new RetailItem("Jeans", 120, 49.99);
	RetailItem item3 = new RetailItem("Shirts", 100, 29.99);

	cout << "Welcome to the Retail Store ";
	
	//Ask user for price for item1 looping until value is greater than 0
	cout << "Price must be greater than 0 ";
	cout << "Please enter the price of item 1 ";
	cin >> price;

	while (price < 1)
	{
		cout << "Please enter a number greater than 0! ";
		cin >> price;
	}

	//Ask user for unitsOnHand for item2 looping until value is greater than 0
	cout << "Inventory must be greater than 0 ";
	cout << "Please enter inventory on hand ";
	cin >> unitsOnHand;

	while (unitsOnHand < 1)
	{
		cout << "Please enter a number greater than 0 ";
		cin >> unitsOnHand;
	}

        //Ask user for description for item 1
	cout << "Please enter the description of item 1 ";
	cin >> description;

	//Display all items
	cout << description;
	cout << unitsOnHand;
	cout << price;

	//Add up total inventory and display total inventory
	cout << "The total inventory is " << item1 + item2 + item3 << endl;

	system("pause");
}

Last edited on
Topic archived. No new replies allowed.