101k views
0 votes
You are tasked with writing a program to process sales of a certain commodity. Its price is volatile and changes throughout the day. The input will come from the keyboard and will be in the form of number of items and unit price:36 9.50which means there was a sale of 36 units at 9.50. Your program should read in the transactions (Enter at least 10 of them). Indicate the end of the list by entering -99 0. After the data is read, display number of transactions, total units sold, average units per order, largest transaction amount, smallest transaction amount, total revenue and average revenue per order.

1 Answer

3 votes

Answer:

Here the code is given as,

Step-by-step explanation:

Code:

#include <math.h>

#include <cmath>

#include <iostream>

using namespace std;

int main() {

int v_stop = 0,count = 0 ;

int x;

double y;

int t_count [100];

double p_item [100];

double Total_rev = 0.0;

double cost_trx[100];

double Largest_element , Smallest_element;

double unit_sold = 0.0;

for( int a = 1; a < 100 && v_stop != -99 ; a = a + 1 )

{

cout << "Transaction # " << a << " : " ;

cin >> x >> y;

t_count[a] = x;

p_item [a] = y;

cost_trx[a] = x*y;

v_stop = x;

count = count + 1;

}

for( int a = 1; a < count; a = a + 1 )

{

Total_rev = Total_rev + cost_trx[a];

unit_sold = unit_sold + t_count[a];

}

Largest_element = cost_trx[1];

for(int i = 2;i < count - 1; ++i)

{

// Change < to > if you want to find the smallest element

if(Largest_element < cost_trx[i])

Largest_element = cost_trx[i];

}

Smallest_element = cost_trx[1];

for(int i = 2;i < count - 1; ++i)

{

// Change < to > if you want to find the smallest element

if(Smallest_element > cost_trx[i])

Smallest_element = cost_trx[i];

}

cout << "TRANSACTION PROCESSING REPORT " << endl;

cout << "Transaction Processed : " << count-1 << endl;

cout << "Uints Sold: " << unit_sold << endl;

cout << "Average Units per order: " << unit_sold/(count - 1) << endl;

cout << "Largest Transaction: " << Largest_element << endl;

cout << "Smallest Transaction: " << Smallest_element << endl;

cout << "Total Revenue: $ " << Total_rev << endl;

cout << "Average Revenue : $ " << Total_rev/(count - 1) << endl;

return 0;

}

Output:

You are tasked with writing a program to process sales of a certain commodity. Its-example-1
User Vlad Morzhanov
by
6.1k points