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

The requirements of this project are the development of a program that includes

ID: 3561221 • Letter: T

Question


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:

Your program needs 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. Save the file as Inventory.cpp.

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. Save the file as Inventory2.cpp.

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. Save the file as Inventory3.cpp.

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. Save the file as Inventory4.cpp.

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 Express 2013 for Desktop (It has to be done in the program I listed) and run it to make sure it is error free.

Explanation / Answer

Ineventory.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;
}