Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

this program is suppose to run a store everything works fine until void sellProd

ID: 3626094 • Letter: T

Question

this program is suppose to run a store everything works fine until void sellProduct function which allows the user to sell a product from the inventory and void restockProduct function which allows the user to restock products from inventory no clue on how to do these? also i half attempted sellProduct with no luck.

#include <iostream>

#include <iomanip>

#include <vector>

#include <string>

using namespace std;

class Product

{

public:

/**

A default constructor that sets all the private variables to

default values.

*/

Product();

/**

A three-parameter constructor that initializes

all three member variables to the values passed to the parameter.

*/

Product(string name, double price, int quantity);

/**

One "get" function for each private variable that returns the

current value. The name of the function must follow the naming

standards for "get" functions, which is the name of the variable

with the prefix word "get".

*/

string getName() const;

double getPrice() const;

int getQuantity() const;

/**

One "set" function for each private variable that sets a new value.

The name of the function must follow the naming standards for "set"

functions, which is the name of the variable with the prefix word "set".

Remember that you must define the "set" functions outside the class

declaration (curly braces of the class).

*/

void setName(string name);

void setPrice(double price);

void setQuantity(int quantity);

/**

Accessor function getValue() that has no parameters and returns

the price times the quantity.

*/

double getValue() const;

/**

Accessor function print() that has no parameters and returns no

values, but displays the data of the class all on one line like this:

*/

void print();

void read();

private:

string name;

double price;

int quantity;

};

void reportInventory (vector<Product>& store);

void addProduct(vector<Product>& store);

void deleteProduct(vector<Product>& store);

void sellProduct(vector<Product>& store);

void restockProduct(vector<Product>& store);

int main()

{

Product product1;

Product product2("Crackers", 2.43, 12);

Product product3("BBQ Sauce", 2.95, 1);

product1.setName("Cereal");

product1.setPrice(3.95);

product1.setQuantity(5);

vector<Product> store;

store.push_back(product1);

store.push_back(product2);

store.push_back(product3);

int choice = 1;

while (choice != 0) {

cout << " Welcome To The corner bodega Please enter one of the following: "

<< "0. Exit Program "

<< "1. Reort Inventory "

<< "2. Add a new Product "

<< "3. Delete a product "

<< "4. Sell a product "

<< "5. Restock a product "

<< " Make a Choice(0-5): ";

cin >> choice;

cout << endl;

if (choice==0){

cout << " Thank you for Shopping";

return 0;

} else if (choice ==1){

reportInventory(store);

} else if (choice ==2) {

addProduct(store);

} else if (choice == 3) {

deleteProduct(store);

} else if (choice == 4) {

sellProduct(store);

} else if (choice == 5) {

restockProduct(store);

}else {

cout << " Invalid choice,choose a number between 1 and 5 ";

}

}

cout << "My Products : ";

cout << "Name" << setw(14) << "Price" << setw(6) << "Qty"

<< right << setw(9) << "Value ";

//product1.print();

//product2.print();

//product3.print();

return 0;

}

Product::Product()

{

name = "";

price = 0.0;

quantity = 0;

}

Product :: Product(string newName, double newPrice, int newQuantity)

{

name = newName;

price = newPrice;

quantity = newQuantity;

}

string Product :: getName() const

{

return name;

}

double Product :: getPrice() const

{

return price;

}

int Product :: getQuantity() const

{

return quantity;

}

void Product :: setName(string newName)

{

name = newName;

}

void Product :: setPrice(double newPrice)

{

price = newPrice;

}

void Product :: setQuantity(int newQuantity)

{

quantity = newQuantity;

}

double Product :: getValue() const

{

return price * quantity;

}

void Product :: print()

{

cout

<< left << setw(14) << name << right << setw(4) << fixed

<< setprecision(2) << price << right << setw(6) << quantity

<< right << setw(8) << price * quantity << endl;

}

void Product:: read() {

cout<< "Enter the name of new product: ";

cin >> ws;

getline(cin, name);

cout<< "Enter the price of a " << name << ": ";

cin >>price;

cout << " Enter the intial inventory: ";

cin>> quantity;

}

void reportInventory (vector<Product>& store) {

cout << "# My products: "

<< setw(10) <<" Price"

<< setw(6) <<" Qty"

<< setw(9) <<"Value ";

for (unsigned i= 0; i < store.size(); i++) {

cout << i+ 1 << " ";

store[i].print();

}

}

void addProduct(vector<Product>&store) {

Product newProduct;

newProduct.read();

store.push_back(newProduct);

}

void deleteProduct(vector<Product>& store) {

reportInventory(store);

int num;

cout << "Enter the number of product you wish to delete.";

cin >> num;

for (unsigned i = num - 1; i< store.size() - 1; i++) {

store[i] = store [i+1];

}store.pop_back();

}

void sellProduct(vector<Product>& store) {

reportInventory(store);

int numProd;

cout << "Please enter the number of the product you wish to sell.";

cin >> numProd;

}

void restockProduct(vector<Product>& store) {

;

}

Explanation / Answer

Here are a good example of what you should do in those functions: void sellProduct(vector& store) { reportInventory(store); int numProd, prodQt; cout > numProd; cout > prodQt; if( store.at(numProd-1).getQuantity()