// This program display the title of the product, the unit cost and the total sales in 6 months
// And sort in the order of the highest dollar sales product first to the least.
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;
void getnumSold(vector<int>&); //To input the number of unit sold in 6 months, you can choose to input the number or use default.
void displayProd(vector<int>&, vector<float>);//displace the list of product and their cost.
void DollarSales(vector<int>&, vector<float>&);//Calculate the total dollar sold for each item.
void sortSales(vector <float>, vector<int>&);// Sort with highest dollar sold first.
void displaySales(vector<int>, vector<float>, vector<int>);// Display in order of the highest dollar sold first.const int Row = 9, ProdCol = 31;
char Prod[Row][ProdCol] = { {"(0)Six Steps to Leadership"}, {"(1)Six Steps to Leadership"}, {"(2)Road to Exellence"},
{"(3)Seven Lessons of Quality"},{"(4)Seven Lessons of Quality"},{"(5)Seven Lessons of Quality"},
{"(6)Teams Are Made, Not Born"}, {"(7)Leadership for the Future"}, {"(8)Leadership for the Future"} };
char Desc[Row][ProdCol] = { {"Book"}, {"Audio CD"}, {"DVD"},
{"Book"}, {"Audio CD"}, {"DVD"},
{"Book"}, {"Book"}, {"Audio CD"} };
float Price[] = { 12.95, 14.95, 18.95, 16.95,
21.95, 31.95, 14.95, 14.95, 16.95 };
int pnAr[] = { 914, 915, 916, 915, 918,// 0, 1, 2, 3, 4
919, 920, 921, 922 };// 5, 6, 7, 8
vector<int>DefaultNSold = { 842, 416, 127, 514, 437, 269, 97, 492, 212 };
int main()
{
vector<int>itemNum = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };//Item number from 0 to 8
vector<int>Sold(DefaultNSold.size());//recieve number sold for each item.
vector<float>totalValue(DefaultNSold.size());
getnumSold(Sold);//passing vector Sold to function getnumSold(). Return of #sold of each item
DollarSales(Sold, totalValue); // pass #sold in vector Sold, and return total sold value of each item.
displayProd(Sold, totalValue);//Show all the tittles of the items
sortSales(totalValue, itemNum);// pass total sold value of each item to sort highest to lowest total $ of items.
// also return the order of the items from highest to lowest for sorting.
displaySales(Sold, totalValue, itemNum);// Display from highest to lowest the total sales of items.
return 0;
}
void getnumSold(vector<int>& numSold)// get and return vector numSold to vector Sold
{
char select;
cout << " Enter y to use default numbers, any other character";
cout << "for entering 6 new numbers: "; cin >> select;
if ((select == 'y') || (select == 'Y'))
{
int row=1;
cout << " In getnumSold, You chose to use default = {";
for (row = 1; row < DefaultNSold.size(); row++)
{
numSold[row - 1] = DefaultNSold[row - 1];
cout << numSold[row - 1] << " ";
}
numSold[row - 1] = DefaultNSold[row - 1];
cout << numSold[row - 1] << "}\n\n";
}
else
{
cout << " You chose to enter 9 new sales number.\n\n";
cout << "Enter number sold for the following\n\n";
for (int row = 1; row <= DefaultNSold.size(); row++)
{
cout << " " << left << setw(35) << Prod[Row-1] << left <<
setw(15) << Desc[row-1] << "$" << Price[row-1] << " is: ";
cin >> numSold[row-1];
}
}
}
void displayProd(vector<int>& Sold, vector<float>totVal)// display the table of selections and price.
{
cout << " In displayProd\n\n";
cout << left << setw(35) << " Product" << setw(15) << "Decription" << setw(10) << "Part num" <<
setw(15) << " Price" << setw(10) << "sold" << setw(17) << "total" << "\n\n";
for (int line = 0; line < Row; line++)
{
cout << " " << left << setw(35) << Prod[line] << left << setw(15) <<
Desc[line] << setw(10) << pnAr[line] << "$" << Price[line] <<
right << setw(10) << Sold[line] << setw(7) <<"$" << left << totVal[line] << "\n\n";
}
}
void DollarSales(vector<int>&Sold, vector<float>&totalValue)// receive vector Sold and vector itemNum.
{ // return to vector Sold.
int size = Sold.size();
for (int element = 0; element < size; element++)
{
totalValue[element] = Price[element] * Sold[element];
//cout << totalValue[element] << "\n\n";
}
}
void sortSales(vector <float>Ar, vector<int>& itemN)// receive vector Sold and vector itemNum.
//function return vector itemN that contain the order of the items sorted from lowest
// total sales to highest.
{
int size = Ar.size();// find the size of the vector.
int startScan = 0, index, temp2;
float temp1;
do
{
index = startScan + 1; // startScan is the first element number, index is the following number.
while (index < size)
{
if (Ar[startScan] < Ar[index])//comparing the lowest number element starting with AR[0] to the rest
{ // one by oneswitch with them if it is higher than the other elements.
temp1 = Ar[startScan]; temp2 = itemN[startScan];
Ar[startScan] = Ar[index]; itemN[startScan] = itemN[index];
Ar[index] = temp1; itemN[index] = temp2;
}
index = index + 1;// to the next lower element to compare, AR[1]->AR[2]-> AR[3]...
}
startScan = startScan + 1;
} while (startScan < (size - 1));
}
void displaySales(vector<int>Sold, vector<float>totalValue, vector<int> itemN)
{
cout << "\n\n\n\n After sorting with the highest dollar amount first \n\n";
cout << left << setw(35) << " Product" << setw(15) << "Decription" << setw(10) << "Part num" <<
setw(15) << " Price" << setw(10) << "sold" << setw(17) << "total" << "\n\n";
int Row = Sold.size();
for (int line = 0; line < Row; line++)
{
cout << " " << left << setw(35) << Prod[itemN[line]] << left << setw(15) <<
Desc[itemN[line]] << setw(10) << pnAr[itemN[line]] << "$" << Price[itemN[line]] <<
right << setw(10) << Sold[itemN[line]] << setw(7) << "$" << left << totalValue[itemN[line]] << "\n\n";
}
}