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

This C++ program should be 150 lines minimum of non-trivial coherent code that u

ID: 3770661 • Letter: T

Question

This C++ program should be 150 lines minimum of non-trivial coherent code that utilizes all of the following: control structures, functions, arrays, and OOP (i.e. object, class, inheritance, etc.):

This C++ program should organize all the contents of a warehouse as entered by the user using the required elements as outlined above:

Input:

type of product, product name, inventory amount, price (for five products)

Output:

organizes the products based on type, alphabetical order, total value, respectively

Basic Data Structure:

the program will utilize control structure, functions, arrays, OOP, etc.

every task will be sorted by specific function processes (for example: an array of product names could be used to alphabetically sort the products within a specific function)

Algorithm:

once the data is inputted by the user it will be passed to the functions to carry out each specific task to organize the data in to a clear and concise output

Note:

the overall purpose of this program is to organize data so that it would be much easier to access in an otherwise large category of warehouse inventory

Explanation / Answer

Complete Program:

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

class Product
{
public:
Product();
Product(string ptype, string pname, double inventory, double price);
string getType();
string getName();
double getInventory();
double getPrice();
void printProduct();

private:
string type;
string name;
double inventory;
double price;
};

Product::Product()
{
type = "";
name = "";
inventory = 0.0;
price = 0.0;
}

Product::Product(string ptype, string pname, double pinventory, double pprice)
{
type = ptype;
name = pname;
inventory = pinventory;
price = pprice;
}

string Product::getType()
{
return type;
}

string Product::getName()
{
return name;
}

double Product::getInventory()
{
return inventory;
}

double Product::getPrice()
{
return price;
}

void Product::printProduct()
{
cout << left << setw(15) << type << setw(15) << name << right << setw(10) << setprecision(2) << fixed << inventory << setw(10) << setprecision(2) << fixed << price << endl;
}

void readData(Product products[], int n);
void printData(Product products[], int n);
void sortDataByType(Product products[], int n);
void sortDataByName(Product products[], int n);
void sortDataByInventory(Product products[], int n);
void sortDataByPrice(Product products[], int n);

int main()
{
const int SIZE = 5;
int choice;

Product products[SIZE];

readData(products, SIZE);
printData(products, SIZE);

do
{
  cout << " -----MENU----" << endl;
  cout << "1. Sort by type" << endl;
  cout << "2. Sort by name" << endl;
  cout << "3. Sort by inventory" << endl;
  cout << "4. Sort by price" << endl;
  cout << "5. Exit" << endl;
  cout << "Enter your choice: ";
  cin >> choice;

  switch(choice)
  {
  case 1:
   sortDataByType(products, SIZE);
   cout << " Details of the products sorted by type:";
   printData(products, SIZE);
   break;

  case 2:
   sortDataByName(products, SIZE);
   cout << " Details of the products sorted by name:";
   printData(products, SIZE);
   break;

  case 3:
   sortDataByInventory(products, SIZE);
   cout << " Details of the products sorted by inventory:";
   printData(products, SIZE);
   break;

  case 4:
   sortDataByPrice(products, SIZE);
   cout << " Details of the products sorted by price:";
   printData(products, SIZE);
   break;

  case 5:
   cout << "Thank you" << endl;
   break;

  default:
   cout << "Invalid choice!" << endl;
  }
}while(choice != 5);

system("pause");
return 0;
}

void readData(Product products[], int n)
{
string ptype;
string pname;
double pinventory;
double pprice;

for(int i = 0; i < n; i++)
{
  cout << " Enter the type of product: ";
  cin >> ptype;

  cout << "Enter the name of product: ";
  cin >> pname;

  cout << "Enter the inventory amount: ";
  cin >> pinventory;

  cout << "Enter the price: ";
  cin >> pprice;

  Product prod(ptype, pname, pinventory, pprice);

  products[i] = prod;
}
}

void printData(Product products[], int n)
{
cout << endl << left << setw(15) << "TYPE" << setw(15) << "NAME" << right << setw(10) << "INVENTORY" << setw(10) << "PRICE" << endl;
for(int i = 0; i < n; i++)
{
  products[i].printProduct();
}
}

void sortDataByType(Product products[], int n)
{
for(int i = 0; i < n - 1; i++)
{
  int minPos = i;

  for (int j = i + 1; j < n; j++)
  {
   if(strcmp(products[j].getType().c_str(), products[minPos].getType().c_str()) < 0)
    minPos = j;
  }

  if(minPos != i)
  {
   Product temp = products[i];
   products[i] = products[minPos];
   products[minPos] = temp;
  }
}
}

void sortDataByName(Product products[], int n)
{
for(int i = 0; i < n - 1; i++)
{
  int minPos = i;

  for (int j = i + 1; j < n; j++)
  {
   if(strcmp(products[j].getName().c_str(), products[minPos].getName().c_str()) < 0)
    minPos = j;
  }

  if(minPos != i)
  {
   Product temp = products[i];
   products[i] = products[minPos];
   products[minPos] = temp;
  }
}
}

void sortDataByInventory(Product products[], int n)
{
for(int i = 0; i < n - 1; i++)
{
  int minPos = i;

  for (int j = i + 1; j < n; j++)
  {
   if(products[j].getInventory() < products[minPos].getInventory())
    minPos = j;
  }

  if(minPos != i)
  {
   Product temp = products[i];
   products[i] = products[minPos];
   products[minPos] = temp;
  }
}
}

void sortDataByPrice(Product products[], int n)
{
for(int i = 0; i < n - 1; i++)
{
  int minPos = i;

  for (int j = i + 1; j < n; j++)
  {
   if(products[j].getPrice() < products[minPos].getPrice())
    minPos = j;
  }

  if(minPos != i)
  {
   Product temp = products[i];
   products[i] = products[minPos];
   products[minPos] = temp;
  }
}
}

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