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

Create the following program using C++ Problem 2: Textbook #7, Inventory Class,

ID: 3859020 • Letter: C

Question

Create the following program using C++

Problem 2: Textbook #7, Inventory Class, page 501 (50 points) HINT: to test Inventory class follow the instruction from the attached file, InventoryTester Output.txt IMPORTANT: totalCost should NOT BE A DATA MEMBER of the class Inventory InventoryTester Output.txt (click to download) Hint for Inventory class: Follow the example in the textbook for Account class declaration, implementation, and usage. Your main) should be much simpler (pages 470 - 474) Submit the "cpp" and "h" files with the following names: proj3_2.cpp, Inventory.h, and Inventory.cpp (unless you use just one file for both the Inventory class and main function). Upload all your files in one compressed file. ABSOLUTELY NO GLOBAL VARIABLES ALLOWED (constants are fine as global)

Explanation / Answer

Below is your program: -

Inventory.h

#ifndef H_Inventory
#define H_Inventory

#include <iostream>
#include <cassert>
using namespace std;

class Inventory
{
public:
void print() const;
void setItemNumber(int num);
void setQuantity(int qty);
void setCost(double cst);
int getItemNumber() const;
int getQuantity() const;
double getCost() const;

Inventory();
Inventory(int num, int qty, double cost);


private:
int itemNumber;
int quantity;
double cost;

};

#endif

Inventory.cpp

#include <iostream>
#include "Inventory.h"

using namespace std;


void Inventory::print() const
{
cout<<" Inventory Summary";
cout<<" Item: "<<itemNumber;
cout<<" Price per unit: $"<<cost;
cout<<" Quantity: "<<quantity;
double totCost = cost * quantity;
cout<<" Total cost: $"<<totCost;
}

void Inventory::setCost(double cst)
{
cost = cst;
}

void Inventory::setItemNumber(int num)
{
itemNumber = num;
}

void Inventory::setQuantity(int qty)
{
quantity = qty;
}


double Inventory::getCost() const
{
return cost;
}

int Inventory::getItemNumber() const
{
return itemNumber;
}

int Inventory::getQuantity() const
{
return quantity;
}

Inventory::Inventory()
{
cost = 0;
quantity = 0;
itemNumber = 0;
}
Inventory::Inventory(int num, int qty, double cst)
{
cost = cst;
quantity = qty;
itemNumber = num;
}

proj3_2.cpp

#include<iostream>

#include "Inventory.h"

using namespace std;

int main() {

Inventory inv;

cout<<"Inventory tester output with input validation: ";

int invNum;

cout<<" Enter item number: ";

cin >> invNum;

while(invNum < 0) {

cout<<"ERROR. Please enter a positive value for item number.";

cout<<" Enter item number: ";

cin >> invNum;

}

inv.setItemNumber(invNum);

double cst;

cout<<" Enter item cost (per unit): $";

cin >> cst;

while(cst < 0) {

cout<<"ERROR. Please enter a positive value for cost per unit.";

cout<<" Enter item cost (per unit): $";

cin >> cst;

}

inv.setCost(cst);

int qty;

cout<<" Enter the quantity: ";

cin >> qty;

while(qty < 0) {

cout<<"ERROR. Please enter a positive value for quantity.";

cout<<" Enter the quantity: ";

cin >> qty;

}

inv.setQuantity(qty);

cout<<endl;

inv.print();

}

Sample Output

Inventory tester output with input validation:

Enter item number: -2341
ERROR. Please enter a positive value for item number.
Enter item number: 2341


Enter item cost (per unit): $14.75


Enter the quantity: -5
ERROR. Please enter a positive value for quantity.
Enter the quantity: 5


Inventory Summary
Item: 2341
Price per unit: $14.75
Quantity: 5
Total cost: $73.75

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote