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

Please use simple C++ commands and libraries. This is a beginning c++ class and

ID: 3546860 • Letter: P

Question

Please use simple C++ commands and libraries. This is a beginning c++ class and I can't be using obscure libraries/algorithms/commands in my code.


Write a program that displays the roman numeral equivalent of any decimal number between 1 and 20 that the user enters. The roman numerals should be stored in an array of strings and the decimal number that the user enters should be used to locate the array elements holding the roman numeral equivalent. The program should have a loop that allows the user to continue entering numbers until an end sentinel of 0 is entered.

Explanation / Answer

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

// Function prototypes
int getTotal(int [], int);
int posOfLargest(int [], int);
int posOfSmallest(int [], int);

int main()
{
const int NUM_TYPES = 5;
string name[NUM_TYPES] =
{"mild ", "medium", "sweet ", "hot ", "zesty "};
int sales[NUM_TYPES]; // Holds jars sold for each salsa type

int totalJarsSold,
hiSalesProduct,
loSalesProduct;

for (int type = 0; type < NUM_TYPES; type++)
{
cout << "Jar sold last month of " << name[type] << ": ";
cin >> sales[type];

while (sales[type] < 0)
{ cout << "Jars sold must be 0 or more. Please re-enter: ";
cin >> sales[type];
}
}

// Call functions to get total sales and high and low selling products
totalJarsSold = getTotal(sales, NUM_TYPES);
hiSalesProduct = posOfLargest(sales, NUM_TYPES);
loSalesProduct = posOfSmallest(sales, NUM_TYPES);

// Produce the sales report
cout << endl << endl;
cout << " Salsa Sales Report ";
cout << "Name Jars Sold ";
cout << "____________________________ ";

for (int salsaType = 0; salsaType < NUM_TYPES; salsaType++)
cout << name[salsaType] << setw(21) << sales[salsaType] << endl;

cout << " Total Sales:" << setw(15) << totalJarsSold << endl;
cout << "High Seller: " <<name[hiSalesProduct] << endl;
cout << "Low Seller : " << name[loSalesProduct] << endl;

return 0;
}

/************************************************************
* getTotal *
* Calculates and returns the total of the values stored in *
* the array passed to the function. *
************************************************************/
int getTotal(int array[], int numElts)
{
int total = 0;

for (int pos = 0; pos < numElts; pos++)
total += array[pos];

return total;
}


/************************************************************
* posOfLargest *
* Finds and returns the subscript of the array position *
* holding the largest value in the array passed to the *
* function. *
************************************************************/
int posOfLargest(int array[], int numElts)
{
int indexOfLargest = 0;

for (int pos = 1; pos < numElts; pos++)
{
if (array[pos] > array[indexOfLargest])
indexOfLargest = pos;
}
return indexOfLargest;
}


/************************************************************
* posOfSmallest *
* Finds and returns the subscript of the array position *
* holding the smallest value in the array passed to the *
* function. *
************************************************************/
int posOfSmallest(int array[], int numElts)
{
int indexOfSmallest = 0;

for (int pos = 1; pos < numElts; pos++)
{
if (array[pos] < array[indexOfSmallest])
indexOfSmallest = pos;
}
return indexOfSmallest;
}