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

Write the statements (which would be in a client program, TestProduct) to create

ID: 3776236 • Letter: W

Question

Write the statements (which would be in a client program, TestProduct) to create two Product objects with the information below:
a. Product name: Milk Gallon Price: 3.50 Amount in Stock: 100
b. Product name: Broccoli Price: 1.99 Amount in Stock: 100
Write the statements (which would be in a client program, TestProduct) to create two Product objects with the information below:
a. Product name: Milk Gallon Price: 3.50 Amount in Stock: 100
b. Product name: Broccoli Price: 1.99 Amount in Stock: 100
Write the statements (which would be in a client program, TestProduct) to create two Product objects with the information below:
a. Product name: Milk Gallon Price: 3.50 Amount in Stock: 100
b. Product name: Broccoli Price: 1.99 Amount in Stock: 100

Explanation / Answer

#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

class Product
{
string productName;
float productPrice;
int amountInStock;

public:
void setProduct(string name, float price, int amount){
    this->productName = name;
    this->productPrice = price;
    this->amountInStock = amount;
}

string getProductName()
{
    return productName;
}

int getProductAmount()
{
    return amountInStock;
}

float getProductPrice()
{
    return productPrice;
}
};

int main ()
{
Product product1;
Product product2;

// create first product
product1.setProduct("Milk Gallon",3.50,100);

// create Second product
product2.setProduct("Brocoli",1.99,100);

//View both Product

//First Product
cout << "a. Product name: " << product1.getProductName() << " ";
cout << "Price: ";
cout << std::setprecision(2) << std::fixed << product1.getProductPrice() << endl;
cout << "Amount in Stock: " << product1.getProductAmount() << endl;

cout << endl;

// Second Product
cout << "b. Product name: " << product2.getProductName() << " ";
cout << "Price: ";
cout << std::setprecision(2) << std::fixed << product2.getProductPrice() << endl;
cout << "Amount in Stock: " << product2.getProductAmount() << endl;
}