Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C++, create a breakpoint on line 41 and step through the code until you have displayed two rows of products on the screen. Here

In C++, create a breakpoint on line 41 and step through the code until you have displayed two rows of products on the screen.

Here is the program:

// This program produces a sales report for DLC, Inc.

#include

#include

using namespace std;

// Function prototypes

void calcSales(const int [], const double [], double [], int);

void showOrder(const double [], const int [], int);

void dualSort(int [], double [], int);

void showTotals(const double [], const int [], int);

// NUM_PRODS is the number of products produced.

const int NUM_PRODS = 9;

int main()

{

// Array with product ID numbers

int id[NUM_PRODS] = {914, 915, 916, 917, 918, 919, 920,

921, 922};

// Array with number of units sold for each product

int units[NUM_PRODS] = {842, 416, 127, 514, 437, 269, 97,

492, 212};

// Array with product prices

double prices[NUM_PRODS] = {12.95, 14.95, 18.95, 16.95, 21.95,

31.95, 14.95, 14.95, 16.95};

// Array to hold the computed sales amounts

double sales[NUM_PRODS];

// Calculate each product's sales.

calcSales(units, prices, sales, NUM_PRODS);

// Sort the elements in the sales array in descending

// order and shuffle the ID numbers in the id array to

// keep them in parallel.

dualSort(id, sales, NUM_PRODS);

// Create the Breakpoint for the next line of code

// Set the numeric output formatting.

cout << setprecision(2) << fixed << showpoint;

// Display the products and sales amounts.

showOrder(sales, id, NUM_PRODS);

// Display total units sold and total sales.

showTotals(sales, units, NUM_PRODS);

return 0;

}

void calcSales(const int units[], const double prices[], double sales[], int num)

{

for (int index = 0; index < num; index++)

sales[index] = units[index] * prices[index];

}

void dualSort(int id[], double sales[], int size)

{

int startScan, maxIndex, tempid;

double maxValue;

for (startScan = 0; startScan < (size - 1); startScan++)

{

maxIndex = startScan;

maxValue = sales[startScan];

tempid = id[startScan];

for(int index = startScan + 1; index < size; index++)

{

if (sales[index] > maxValue)

{

maxValue = sales[index];

tempid = id[index];

maxIndex = index;

}

}

sales[maxIndex] = sales[startScan];

id[maxIndex] = id[startScan];

sales[startScan] = maxValue;

id[startScan] = tempid;

}

}

void showOrder(const double sales[], const int id[], int num)

{

cout << "Product Number\tSales ";

cout << "---------------------------------- ";

for (int index = 0; index < num; index++)

{

cout << id[index] << "\t\t$";

cout << setw(8) << sales[index] << endl;

}

cout << endl;

}

void showTotals(const double sales[], const int units[], int num)

{

int totalUnits = 0;

double totalSales = 0.0;

for (int index = 0; index < num; index++)

{

totalUnits += units[index];

totalSales += sales[index];

}

cout << "Total units Sold: " << totalUnits << endl;

cout << "Total sales: $" << totalSales << endl;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Learning MySQL Get A Handle On Your Data

Authors: Seyed M M Tahaghoghi

1st Edition

0596529465, 9780596529468

More Books

Students also viewed these Databases questions

Question

Describe a typical interpersonal skills training program

Answered: 1 week ago

Question

What is a verb?

Answered: 1 week ago