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

This is a substantial project and could be a candidate for your e-portfolio. For

ID: 3738178 • Letter: T

Question

This is a substantial project and could be a candidate for your e-portfolio. For week 4’s assessment we will be creating a "real-world" solution that could be used by a company for inventory control.

You can either have 4 separate projects (each with its own main(), or you can have one project and have the 4 parts done in that main() function.

The requirements of this project are the development of a program that includes an inventory class with data members for stock number, quantity, price, also overloaded data entry and output operators. The data entry operator function should throw an error message if:

An error message, if the stock number is negative or higher than 999

An error message if the quantity is less than 0

An error message if the price is over $100.00

Your programs need to perform the following tasks:

1) Write a main() function that instantiates an array of five Inventory objects, and accepts data for each. Display an appropriate error message for each exception situation. When an exception is detected, replace all data fields with zeroes. At the end of the program, display data fields for all five objects. You should have ONE C++ source file for the main(), and separate Inventory.h and Inventory.cpp files for the Inventory class.



2) Write a main() function that instantiates an array of five Inventory objects and accepts data for each. If an exception is thrown because of an invalid stock number, force the user to reenter the stock number for the Inventory object. If the quantity is invalid, do nothing. If the price is in error, then set the price to 99.99. (Add a setPrice() function to the Inventory class to accomplish this.) At the end of the program, display data fields for all five objects.



3) Write a main() function that instantiates an array of five Inventory objects and accepts data for each. If an exception is thrown because of an invalid stock number, force the stock number to 999; otherwise, do nothing. (Add any needed functions to the Inventory class.) At the end of the program, display data fields for all five objects. .



4) Write a main() function that instantiates an array of five Inventory objects and accepts data for each. If any exception is thrown, stop accepting data. Display as many objects as were entered correctly.



Because this is a portfolio quality project, please fully comment all of your code, including a descriptive header for each code file, and provide design documentation in the form or a MS-Word document or a PowerPoint presentation.

Compile this application using Visual Studio and run it to make sure it is error free.

This is for C++

Explanation / Answer

Ineventory1.cpp

#include<bits/stdc++.h>
using namespace std;

class Inventory{
public:
int stockNumber;
int quantity;
float price;
};

int main()
{
Inventory arr[5] = {0};
bool flag = false;
for(int i = 0;i < 5;i++){
cin >> arr[i].stockNumber;
if (arr[i].stockNumber < 0 || arr[i].stockNumber > 999){
cout<< "Error: Stock Number must be in range (0,999)"<<endl;
arr[i].stockNumber = 0;
flag = true;
break;
}
cin >> arr[i].quantity;
if (arr[i].quantity < 0){
cout<< "Error: Quantity must be positive"<<endl;
arr[i].quantity = 0;
flag = true;
break;
}
cin >> arr[i].price;
if (arr[i].price > 100 || arr[i].price < 0){
cout<<"Error: Price must be in range (0,100)"<<endl;
arr[i].price = 0;
flag = true;
break;
}
}
for(int i = 0;i < 5;i++){
if (flag){
arr[i].stockNumber = arr[i].quantity = arr[i].price = 0;
}
}
cout<<"All inventory data: ";
for(int i = 0;i < 5;i++){
cout << arr[i].stockNumber<<" "<<arr[i].quantity<<" "<<arr[i].price<<endl;
}
return 0;
}

//Inventory2.cpp

#include<bits/stdc++.h>
using namespace std;

class Inventory{
public:
int stockNumber;
int quantity;
float price;
void setPrice(float val){
price = val;
}

};

int main()
{
Inventory arr[5] = {0};

for(int i = 0;i < 5;i++){
here:
cin >> arr[i].stockNumber;
if (arr[i].stockNumber < 0 || arr[i].stockNumber > 999){
cout<< "Info:Please re-enter stock number in range (0,999)"<<endl;
arr[i].stockNumber = 0;
goto here;
}
cin >> arr[i].quantity;
if (arr[i].quantity < 0){
arr[i].quantity = 0;
}
cin >> arr[i].price;
if (arr[i].price > 100 || arr[i].price < 0){
arr[i].setPrice(99.9);
}
}
cout<<"All inventory data: ";
for(int i = 0;i < 5;i++){
cout << arr[i].stockNumber<<" "<<arr[i].quantity<<" "<<arr[i].price<<endl;
}
return 0;
}

//Inventory3.cpp

#include<bits/stdc++.h>
using namespace std;

class Inventory{
public:
int stockNumber;
int quantity;
float price;
void setPrice(float val){
price = val;
}
void setStocknumber(int num){
stockNumber = num;
}

};

int main()
{
Inventory arr[5] = {0};

for(int i = 0;i < 5;i++){
cin >> arr[i].stockNumber;
if (arr[i].stockNumber < 0 || arr[i].stockNumber > 999){
arr[i].setStocknumber(999);
}
cin >> arr[i].quantity;
if (arr[i].quantity < 0){
arr[i].quantity = 0;
}
cin >> arr[i].price;
if (arr[i].price > 100 || arr[i].price < 0){
arr[i].setPrice(99.9);
}
}
cout<<"All inventory data: ";
for(int i = 0;i < 5;i++){
cout << arr[i].stockNumber<<" "<<arr[i].quantity<<" "<<arr[i].price<<endl;
}
return 0;
}

// Inventory4.cpp

#include<bits/stdc++.h>
using namespace std;

class Inventory{
public:
int stockNumber;
int quantity;
float price;
};

int main()
{
Inventory arr[5] = {0};
int corrected = 0;
for(int i = 0;i < 5;i++){
cin >> arr[i].stockNumber;
if (arr[i].stockNumber < 0 || arr[i].stockNumber > 999){
cout<< "Error: Stock Number must be in range (0,999)"<<endl;
arr[i].stockNumber = 0;
break;
}
cin >> arr[i].quantity;
if (arr[i].quantity < 0){
cout<< "Error: Quantity must be positive"<<endl;
arr[i].quantity = 0;
break;
}
cin >> arr[i].price;
if (arr[i].price > 100 || arr[i].price < 0){
cout<<"Error: Price must be in range (0,100)"<<endl;
arr[i].price = 0;
break;
}
corrected = i;
}
cout<<"All inventory data: ";
for(int i = 0;i < corrected;i++){
cout << arr[i].stockNumber<<" "<<arr[i].quantity<<" "<<arr[i].price<<endl;
}
return 0;
}

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