Hi! I am EXTREMELY new to C++ and I wish to ask for some help on my latest assignment. I do not really know where to begin. Any help is greatly appreciated!!
This is the assignment:
Using the variables created for the application, create a class object called Inventory. Our variables should be private within that class. In addition, set up public member functions for setting and getting the values for those private variables. There should be two constructors: a default constructor to set all values to zero or empty (for string variables), and a parameter constructor for setting the values when declared.
The class will also include functions for calculating the total value of the inventory and for generating the random number for the SKU.
We will still be using a loop to ask the user for the category, the item, the price, and the number in stock, so all that is required is the modifications in variables. Validation for the input should be within the class.
The output will remain as we have previously done it, so, again, modifications are needed for the variables only.
This is the code I have so far, I do not know where to begin:
Code:#include <iostream> #include <string> #include <stdlib.h> #include <time.h> #include <iomanip> using namespace std; class Inventory { private: int itemNumber; int quantity; double cost; double totalCost; public: Inventory() { itemNumber = 0; quantity = 0; cost = 0; totalCost = 0; } Inventory(int newItemNumber, int newQuantity, double newCost) { itemNumber = newItemNumber; quantity = newQuantity; cost = newCost; setTotalCost(quantity, cost); // this can be called as quantity and cost have now been initialized. } void setItemNumber(int) { itemNumber = itemNumber; } void setQuantity(int) { quantity = quantity; } void setCost(double) { cost = cost; } void setTotalCost(int, double) { totalCost = quantity * cost; } int getItemNumber() { return itemNumber; } int getQuantity() { return quantity; } double getCost() { return cost; } double getTotalCost() { return totalCost; } }; int main() { int itemNumber; int quantity; double cost; double totalCost; cout << "Enter the Item Number: "; cin >> itemNumber; while (itemNumber < 0) { cout << "Please enter a positive value for the Item Number: "; cin >> itemNumber; } cout << "Enter the Quantity of the item: "; cin >> quantity; while (quantity < 0) { cout << "Please enter a positive value for the Quantity of the item: "; cin >> quantity; } cout << "Enter the Cost of the item: "; cin >> cost; while (cost < 0) { cout << "Please enter a positive value for the Cost of the item: "; cin >> cost; } Inventory information(itemNumber, quantity, cost); totalCost = information.getTotalCost(); itemNumber = information.getItemNumber(); cost = information.getCost(); quantity = information.getQuantity(); cout << "The Item Number is: " << itemNumber << endl; cout << "The Quantity is: " << quantity << endl; cout << "The Cost is: " << cost << endl; cout << "The Total Cost is: " << totalCost << endl; return 0; }